summaryrefslogtreecommitdiff
path: root/lisp/progmodes
diff options
context:
space:
mode:
authorK. Handa <handa@gnu.org>2016-06-01 08:07:18 +0900
committerK. Handa <handa@gnu.org>2016-06-01 08:07:18 +0900
commit4efef3db2fb1c3a20b83a67948e614d9b0c258dd (patch)
treec0c08fc308869f7ba3d988594e4a51b69a70325b /lisp/progmodes
parent694d5e5b56a9d55023ffc292188bd88f6f6cbca6 (diff)
parent01030eed9395f5004e7d0721394697d1ca90cc2f (diff)
downloademacs-4efef3db2fb1c3a20b83a67948e614d9b0c258dd.tar.gz
emacs-4efef3db2fb1c3a20b83a67948e614d9b0c258dd.tar.bz2
emacs-4efef3db2fb1c3a20b83a67948e614d9b0c258dd.zip
Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/cc-engine.el64
-rw-r--r--lisp/progmodes/cc-langs.el13
-rw-r--r--lisp/progmodes/cc-mode.el103
3 files changed, 105 insertions, 75 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 2450a5db8b9..4d6a1203c25 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -229,8 +229,12 @@
;; The starting position from where we determined `c-macro-cache'.
(defvar c-macro-cache-syntactic nil)
(make-variable-buffer-local 'c-macro-cache-syntactic)
-;; non-nil iff `c-macro-cache' has both elements set AND the cdr is at a
-;; syntactic end of macro, not merely an apparent one.
+;; Either nil, or the syntactic end of the macro currently represented by
+;; `c-macro-cache'.
+(defvar c-macro-cache-no-comment nil)
+(make-variable-buffer-local 'c-macro-cache-no-comment)
+;; Either nil, or the last character of the macro currently represented by
+;; `c-macro-cache' which isn't in a comment. */
(defun c-invalidate-macro-cache (beg end)
;; Called from a before-change function. If the change region is before or
@@ -242,12 +246,14 @@
((< beg (car c-macro-cache))
(setq c-macro-cache nil
c-macro-cache-start-pos nil
- c-macro-cache-syntactic nil))
+ c-macro-cache-syntactic nil
+ c-macro-cache-no-comment nil))
((and (cdr c-macro-cache)
(< beg (cdr c-macro-cache)))
(setcdr c-macro-cache nil)
(setq c-macro-cache-start-pos beg
- c-macro-cache-syntactic nil))))
+ c-macro-cache-syntactic nil
+ c-macro-cache-no-comment nil))))
(defun c-macro-is-genuine-p ()
;; Check that the ostensible CPP construct at point is a real one. In
@@ -288,7 +294,8 @@ comment at the start of cc-engine.el for more info."
t))
(setq c-macro-cache nil
c-macro-cache-start-pos nil
- c-macro-cache-syntactic nil)
+ c-macro-cache-syntactic nil
+ c-macro-cache-no-comment nil)
(save-restriction
(if lim (narrow-to-region lim (point-max)))
@@ -323,7 +330,8 @@ comment at the start of cc-engine.el for more info."
(>= (point) (car c-macro-cache)))
(setq c-macro-cache nil
c-macro-cache-start-pos nil
- c-macro-cache-syntactic nil))
+ c-macro-cache-syntactic nil
+ c-macro-cache-no-comment nil))
(while (progn
(end-of-line)
(when (and (eq (char-before) ?\\)
@@ -347,14 +355,38 @@ comment at the start of cc-engine.el for more info."
(let* ((here (point))
(there (progn (c-end-of-macro) (point)))
s)
- (unless c-macro-cache-syntactic
+ (if c-macro-cache-syntactic
+ (goto-char c-macro-cache-syntactic)
(setq s (parse-partial-sexp here there))
(while (and (or (nth 3 s) ; in a string
(nth 4 s)) ; in a comment (maybe at end of line comment)
(> there here)) ; No infinite loops, please.
(setq there (1- (nth 8 s)))
(setq s (parse-partial-sexp here there)))
- (setq c-macro-cache-syntactic (car c-macro-cache)))
+ (setq c-macro-cache-syntactic (point)))
+ (point)))
+
+(defun c-no-comment-end-of-macro ()
+ ;; Go to the end of a CPP directive, or a pos just before which isn't in a
+ ;; comment. For this purpose, open strings are ignored.
+ ;;
+ ;; This function must only be called from the beginning of a CPP construct.
+ ;;
+ ;; Note that this function might do hidden buffer changes. See the comment
+ ;; at the start of cc-engine.el for more info.
+ (let* ((here (point))
+ (there (progn (c-end-of-macro) (point)))
+ s)
+ (if c-macro-cache-no-comment
+ (goto-char c-macro-cache-no-comment)
+ (setq s (parse-partial-sexp here there))
+ (while (and (nth 3 s) ; in a string
+ (> there here)) ; No infinite loops, please.
+ (setq here (1+ (nth 8 s)))
+ (setq s (parse-partial-sexp here there)))
+ (when (nth 4 s)
+ (goto-char (1- (nth 8 s))))
+ (setq c-macro-cache-no-comment (point)))
(point)))
(defun c-forward-over-cpp-define-id ()
@@ -8899,6 +8931,22 @@ comment at the start of cc-engine.el for more info."
(c-syntactic-skip-backward c-block-prefix-charset limit t)
(eq (char-before) ?>))))))
+ ;; Skip back over noise clauses.
+ (while (and
+ c-opt-cpp-prefix
+ (eq (char-before) ?\))
+ (let ((after-paren (point)))
+ (if (and (c-go-list-backward)
+ (progn (c-backward-syntactic-ws)
+ (c-simple-skip-symbol-backward))
+ (or (looking-at c-paren-nontype-key)
+ (looking-at c-noise-macro-with-parens-name-re)))
+ (progn
+ (c-syntactic-skip-backward c-block-prefix-charset limit t)
+ t)
+ (goto-char after-paren)
+ nil))))
+
;; Note: Can't get bogus hits inside template arglists below since they
;; have gotten paren syntax above.
(when (and
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 705f723d55d..6f4d1f16857 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -476,7 +476,8 @@ so that all identifiers are recognized as words.")
c++ '(c-extend-region-for-CPP
c-before-change-check-<>-operators
c-invalidate-macro-cache)
- (c objc) '(c-extend-region-for-CPP c-invalidate-macro-cache)
+ (c objc) '(c-extend-region-for-CPP
+ c-invalidate-macro-cache)
;; java 'c-before-change-check-<>-operators
awk 'c-awk-record-region-clear-NL)
(c-lang-defvar c-get-state-before-change-functions
@@ -505,9 +506,11 @@ parameters \(point-min) and \(point-max).")
;; For documentation see the following c-lang-defvar of the same name.
;; The value here may be a list of functions or a single function.
t 'c-change-expand-fl-region
- (c objc) '(c-neutralize-syntax-in-and-mark-CPP
+ (c objc) '(c-extend-font-lock-region-for-macros
+ c-neutralize-syntax-in-and-mark-CPP
c-change-expand-fl-region)
- c++ '(c-neutralize-syntax-in-and-mark-CPP
+ c++ '(c-extend-font-lock-region-for-macros
+ c-neutralize-syntax-in-and-mark-CPP
c-restore-<>-properties
c-change-expand-fl-region)
java '(c-restore-<>-properties
@@ -2264,6 +2267,10 @@ contain type identifiers."
;; MSVC extension.
"__declspec"))
+(c-lang-defconst c-paren-nontype-key
+ t (c-make-keywords-re t (c-lang-const c-paren-nontype-kwds)))
+(c-lang-defvar c-paren-nontype-key (c-lang-const c-paren-nontype-key))
+
(c-lang-defconst c-paren-type-kwds
"Keywords that may be followed by a parenthesis expression containing
type identifiers separated by arbitrary tokens."
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index de903b80ade..9ab04808af6 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -865,14 +865,6 @@ Note that the style variables are always made local to the buffer."
;;; Change hooks, linking with Font Lock and electric-indent-mode.
-;; Buffer local variables recording Beginning/End-of-Macro position before a
-;; change, when a macro straddles, respectively, the BEG or END (or both) of
-;; the change region. Otherwise these have the values BEG/END.
-(defvar c-old-BOM 0)
-(make-variable-buffer-local 'c-old-BOM)
-(defvar c-old-EOM 0)
-(make-variable-buffer-local 'c-old-EOM)
-
(defun c-called-from-text-property-change-p ()
;; Is the primitive which invoked `before-change-functions' or
;; `after-change-functions' one which merely changes text properties? This
@@ -886,8 +878,8 @@ Note that the style variables are always made local to the buffer."
'(put-text-property remove-list-of-text-properties)))
(defun c-extend-region-for-CPP (beg end)
- ;; Set c-old-BOM or c-old-EOM respectively to BEG, END, each extended to the
- ;; beginning/end of any preprocessor construct they may be in.
+ ;; Adjust `c-new-BEG', `c-new-END' respectively to the beginning and end of
+ ;; any preprocessor construct they may be in.
;;
;; Point is undefined both before and after this function call; the buffer
;; has already been widened, and match-data saved. The return value is
@@ -896,45 +888,33 @@ Note that the style variables are always made local to the buffer."
;; This function is in the C/C++/ObjC values of
;; `c-get-state-before-change-functions' and is called exclusively as a
;; before change function.
- (goto-char beg)
+ (goto-char c-new-BEG)
(c-beginning-of-macro)
- (setq c-old-BOM (point))
+ (setq c-new-BEG (point))
- (goto-char end)
+ (goto-char c-new-END)
(when (c-beginning-of-macro)
(c-end-of-macro)
(or (eobp) (forward-char))) ; Over the terminating NL which may be marked
; with a c-cpp-delimiter category property
- (setq c-old-EOM (point)))
-
-(defun c-extend-font-lock-region-for-macros (begg endd &optional old-len)
- ;; Extend the region (BEGG ENDD) to cover all (possibly changed)
- ;; preprocessor macros; return the cons (new-BEG . new-END). OLD-LEN should
- ;; be either the old length parameter when called from an
- ;; after-change-function, or nil otherwise. This defun uses the variables
- ;; c-old-BOM, c-new-BOM.
+ (setq c-new-END (point)))
+
+(defun c-extend-font-lock-region-for-macros (begg endd old-len)
+ ;; Extend the region (c-new-BEG c-new-END) to cover all (possibly changed)
+ ;; preprocessor macros; The return value has no significance.
;;
;; Point is undefined on both entry and exit to this function. The buffer
;; will have been widened on entry.
- (let (limits new-beg new-end)
- (goto-char c-old-BOM) ; already set to old start of macro or begg.
- (setq new-beg
- (min begg
- (if (setq limits (c-state-literal-at (point)))
- (cdr limits) ; go forward out of any string or comment.
- (point))))
-
- (goto-char endd)
- (if (setq limits (c-state-literal-at (point)))
- (goto-char (car limits))) ; go backward out of any string or comment.
- (if (c-beginning-of-macro)
- (c-end-of-macro))
- (setq new-end (max endd
- (if old-len
- (+ (- c-old-EOM old-len) (- endd begg))
- c-old-EOM)
- (point)))
- (cons new-beg new-end)))
+ ;;
+ ;; This function is in the C/C++/ObjC value of `c-before-font-lock-functions'.
+ (goto-char endd)
+ (if (c-beginning-of-macro)
+ (c-end-of-macro))
+ (setq c-new-END (max endd c-new-END (point)))
+ ;; Determine the region, (c-new-BEG c-new-END), which will get font
+ ;; locked. This restricts the region should there be long macros.
+ (setq c-new-BEG (max c-new-BEG (c-determine-limit 500 begg))
+ c-new-END (min c-new-END (c-determine-+ve-limit 500 endd))))
(defun c-neutralize-CPP-line (beg end)
;; BEG and END bound a region, typically a preprocessor line. Put a
@@ -963,19 +943,14 @@ Note that the style variables are always made local to the buffer."
(t nil)))))))
(defun c-neutralize-syntax-in-and-mark-CPP (begg endd old-len)
- ;; (i) Extend the font lock region to cover all changed preprocessor
- ;; regions; it does this by setting the variables `c-new-BEG' and
- ;; `c-new-END' to the new boundaries.
- ;;
- ;; (ii) "Neutralize" every preprocessor line wholly or partially in the
- ;; extended changed region. "Restore" lines which were CPP lines before the
- ;; change and are no longer so; these can be located from the Buffer local
- ;; variables `c-old-BOM' and `c-old-EOM'.
+ ;; (i) "Neutralize" every preprocessor line wholly or partially in the
+ ;; changed region. "Restore" lines which were CPP lines before the change
+ ;; and are no longer so.
;;
- ;; (iii) Mark every CPP construct by placing a `category' property value
+ ;; (ii) Mark each CPP construct by placing a `category' property value
;; `c-cpp-delimiter' at its start and end. The marked characters are the
;; opening # and usually the terminating EOL, but sometimes the character
- ;; before a comment/string delimiter.
+ ;; before a comment delimiter.
;;
;; That is, set syntax-table properties on characters that would otherwise
;; interact syntactically with those outside the CPP line(s).
@@ -992,15 +967,8 @@ Note that the style variables are always made local to the buffer."
;; Note: SPEED _MATTERS_ IN THIS FUNCTION!!!
;;
;; This function might make hidden buffer changes.
- (c-save-buffer-state (new-bounds)
- ;; First determine the region, (c-new-BEG c-new-END), which will get font
- ;; locked. It might need "neutralizing". This region may not start
- ;; inside a string, comment, or macro.
- (setq new-bounds (c-extend-font-lock-region-for-macros
- c-new-BEG c-new-END old-len))
- (setq c-new-BEG (max (car new-bounds) (c-determine-limit 500 begg))
- c-new-END (min (cdr new-bounds) (c-determine-+ve-limit 500 endd)))
- ;; Clear all old relevant properties.
+ (c-save-buffer-state (limits )
+ ;; Clear 'syntax-table properties "punctuation":
(c-clear-char-property-with-value c-new-BEG c-new-END 'syntax-table '(1))
;; CPP "comment" markers:
@@ -1011,6 +979,8 @@ Note that the style variables are always made local to the buffer."
;; Add needed properties to each CPP construct in the region.
(goto-char c-new-BEG)
+ (if (setq limits (c-literal-limits)) ; Go past any literal.
+ (goto-char (cdr limits)))
(skip-chars-backward " \t")
(let ((pps-position (point)) pps-state mbeg)
(while (and (< (point) c-new-END)
@@ -1030,7 +1000,7 @@ Note that the style variables are always made local to the buffer."
(nth 4 pps-state)))) ; in a comment?
(goto-char (match-beginning 1))
(setq mbeg (point))
- (if (> (c-syntactic-end-of-macro) mbeg)
+ (if (> (c-no-comment-end-of-macro) mbeg)
(progn
(c-neutralize-CPP-line mbeg (point)) ; "punctuation" properties
(if (eval-when-compile
@@ -1256,10 +1226,15 @@ Note that the style variables are always made local to the buffer."
;;
;; This is called from an after-change-function, but the parameters BEG END
;; and OLD-LEN are not used.
- (if font-lock-mode
- (setq c-new-BEG
- (or (c-fl-decl-start c-new-BEG) (c-point 'bol c-new-BEG))
- c-new-END (c-point 'bonl c-new-END))))
+ (if font-lock-mode
+ (setq c-new-BEG
+ (or (c-fl-decl-start c-new-BEG) (c-point 'bol c-new-BEG))
+ c-new-END
+ (save-excursion
+ (goto-char c-new-END)
+ (if (bolp)
+ (point)
+ (c-point 'bonl c-new-END))))))
(defun c-context-expand-fl-region (beg end)
;; Return a cons (NEW-BEG . NEW-END), where NEW-BEG is the beginning of a