summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorAlan Mackenzie <acm@muc.de>2016-08-04 21:07:52 +0000
committerAlan Mackenzie <acm@muc.de>2016-08-04 21:07:52 +0000
commit6a9d967048f489bea8c716eb7b5be2c582b480bb (patch)
tree620dcba7ec8c1e3f674b60f2d5f3f8458d568024 /lisp
parent847140163a38af9f429c807f28be023dea9166cf (diff)
downloademacs-6a9d967048f489bea8c716eb7b5be2c582b480bb.tar.gz
Widen in certain low level CC Mode functions. This fixes bug #24148.
* lisp/progmodes/cc-engine (c-state-semi-pp-to-literal) (c-state-full-pp-to-literal): Widen around the functionality. (c-parse-ps-state-below): Correct the order of save-excursion and save-restriction.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/cc-engine.el122
1 files changed, 63 insertions, 59 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index dbcd071da16..e22b98dbc4d 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -2313,30 +2313,32 @@ comment at the start of cc-engine.el for more info."
;; newer Emacsen only, the syntax of a position after a potential first char
;; of a two char construct) of STATE are valid.
(save-excursion
- (save-match-data
- (let* ((base-and-state (c-parse-ps-state-below here))
- (base (car base-and-state))
- (s (cdr base-and-state))
- (s (parse-partial-sexp base here nil nil s))
- ty)
- (cond
- ((or (nth 3 s) (nth 4 s)) ; in a string or comment
- (setq ty (cond
- ((nth 3 s) 'string)
- ((nth 7 s) 'c++)
- (t 'c)))
- (list s ty (nth 8 s)))
-
- ((and (not not-in-delimiter) ; inside a comment starter
- (not (bobp))
- (progn (backward-char)
- (and (not (and (memq 'category-properties c-emacs-features)
- (looking-at "\\s!")))
- (looking-at c-comment-start-regexp))))
- (setq ty (if (looking-at c-block-comment-start-regexp) 'c 'c++))
- (list s ty (point)))
-
- (t (list s)))))))
+ (save-restriction
+ (widen)
+ (save-match-data
+ (let* ((base-and-state (c-parse-ps-state-below here))
+ (base (car base-and-state))
+ (s (cdr base-and-state))
+ (s (parse-partial-sexp base here nil nil s))
+ ty)
+ (cond
+ ((or (nth 3 s) (nth 4 s)) ; in a string or comment
+ (setq ty (cond
+ ((nth 3 s) 'string)
+ ((nth 7 s) 'c++)
+ (t 'c)))
+ (list s ty (nth 8 s)))
+
+ ((and (not not-in-delimiter) ; inside a comment starter
+ (not (bobp))
+ (progn (backward-char)
+ (and (not (and (memq 'category-properties c-emacs-features)
+ (looking-at "\\s!")))
+ (looking-at c-comment-start-regexp))))
+ (setq ty (if (looking-at c-block-comment-start-regexp) 'c 'c++))
+ (list s ty (point)))
+
+ (t (list s))))))))
(defun c-state-full-pp-to-literal (here &optional not-in-delimiter)
;; This function will supersede c-state-pp-to-literal.
@@ -2357,38 +2359,40 @@ comment at the start of cc-engine.el for more info."
;; newer Emacsen only, the syntax of a position after a potential first char
;; of a two char construct) of STATE are valid.
(save-excursion
- (save-match-data
- (let* ((base-and-state (c-parse-ps-state-below here))
- (base (car base-and-state))
- (s (cdr base-and-state))
- (s (parse-partial-sexp base here nil nil s))
- ty start)
- (cond
- ((or (nth 3 s) (nth 4 s)) ; in a string or comment
- (setq ty (cond
- ((nth 3 s) 'string)
- ((nth 7 s) 'c++)
- (t 'c)))
- (setq start (nth 8 s))
- (parse-partial-sexp here (point-max)
- nil ; TARGETDEPTH
- nil ; STOPBEFORE
- s ; OLDSTATE
- 'syntax-table) ; stop at end of literal
- (list s ty (cons start (point))))
-
- ((and (not not-in-delimiter) ; inside a comment starter
- (not (bobp))
- (progn (backward-char)
- (and (not (and (memq 'category-properties c-emacs-features)
- (looking-at "\\s!")))
- (looking-at c-comment-start-regexp))))
- (setq ty (if (looking-at c-block-comment-start-regexp) 'c 'c++)
- start (point))
- (forward-comment 1)
- (list s ty (cons start (point))))
-
- (t (list s)))))))
+ (save-restriction
+ (widen)
+ (save-match-data
+ (let* ((base-and-state (c-parse-ps-state-below here))
+ (base (car base-and-state))
+ (s (cdr base-and-state))
+ (s (parse-partial-sexp base here nil nil s))
+ ty start)
+ (cond
+ ((or (nth 3 s) (nth 4 s)) ; in a string or comment
+ (setq ty (cond
+ ((nth 3 s) 'string)
+ ((nth 7 s) 'c++)
+ (t 'c)))
+ (setq start (nth 8 s))
+ (parse-partial-sexp here (point-max)
+ nil ; TARGETDEPTH
+ nil ; STOPBEFORE
+ s ; OLDSTATE
+ 'syntax-table) ; stop at end of literal
+ (list s ty (cons start (point))))
+
+ ((and (not not-in-delimiter) ; inside a comment starter
+ (not (bobp))
+ (progn (backward-char)
+ (and (not (and (memq 'category-properties c-emacs-features)
+ (looking-at "\\s!")))
+ (looking-at c-comment-start-regexp))))
+ (setq ty (if (looking-at c-block-comment-start-regexp) 'c 'c++)
+ start (point))
+ (forward-comment 1)
+ (list s ty (cons start (point))))
+
+ (t (list s))))))))
(defsubst c-state-pp-to-literal (from to &optional not-in-delimiter)
;; Do a parse-partial-sexp from FROM to TO, returning either
@@ -2492,9 +2496,9 @@ comment at the start of cc-engine.el for more info."
;; STATE are those concerning comments and strings; STATE is the state of a
;; null `parse-partial-sexp' scan when CACHE-POS is not in a comment or
;; string.
- (save-restriction
- (widen)
- (save-excursion
+ (save-excursion
+ (save-restriction
+ (widen)
(let ((c c-state-semi-nonlit-pos-cache)
elt state pos npos high-elt)
;; Trim the cache to take account of buffer changes.