[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] emacs-26 88ddf53: Fontify a CPP construct correctly when a
From: |
Alan Mackenzie |
Subject: |
[Emacs-diffs] emacs-26 88ddf53: Fontify a CPP construct correctly when a comment follows without spaces |
Date: |
Thu, 21 Dec 2017 12:58:11 -0500 (EST) |
branch: emacs-26
commit 88ddf53ef086ee2f2e0ea729bc4afbf34d88d82b
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>
Fontify a CPP construct correctly when a comment follows without spaces
Do this by removing a broken optimization in the state cache which put
category text properties on a character between the end of the CPP construct
and the beginning of the comment. This can't work when there's no such
character.
* lisp/progmodes/cc-defs.el (c-cpp-delimiter, c-set-cpp-delimiters)
(c-clear-cpp-delimiters, c-comment-out-cpps, c-with-cpps-commented-out)
(c-with-all-but-one-cpps-commented-out): Remove.
* lisp/progmodes/cc-engine.el (c-no-comment-end-of-macro): Return the
comment
start position rather than one character before it.
(c-invalidate-state-cache, c-parse-state): Remove the invocations of
c-with-all-but-one-cpps-commented-out and c-with-cpps-commented-out.
* lisp/progmodes/cc-mode.el (c-neutralize-syntax-in-and-mark-CPP): Rename to
c-neutralize-syntax-in-CPP and remove the bits which applied category
properties.
* lisp/progmodes/cc-langs.el (c-before-font-lock-functions): Incorporate the
new name of the function c-neutralize-syntax-in-CPP.
---
lisp/progmodes/cc-defs.el | 53 ---------------------------------------------
lisp/progmodes/cc-engine.el | 27 +++++++----------------
lisp/progmodes/cc-langs.el | 4 ++--
lisp/progmodes/cc-mode.el | 26 +++++-----------------
4 files changed, 16 insertions(+), 94 deletions(-)
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el
index 973d97c..e837ce1 100644
--- a/lisp/progmodes/cc-defs.el
+++ b/lisp/progmodes/cc-defs.el
@@ -1414,59 +1414,6 @@ with value CHAR in the region [FROM to)."
;;;;;;;;;;;;;;;
-(defconst c-cpp-delimiter '(14)) ; generic comment syntax
-;; This is the value of the `category' text property placed on every #
-;; which introduces a CPP construct and every EOL (or EOB, or character
-;; preceding //, etc.) which terminates it. We can instantly "comment
-;; out" all CPP constructs by giving `c-cpp-delimiter' a syntax-table
-;; property '(14) (generic comment delimiter).
-(defmacro c-set-cpp-delimiters (beg end)
- ;; This macro does a hidden buffer change.
- `(progn
- (c-put-char-property ,beg 'category 'c-cpp-delimiter)
- (if (< ,end (point-max))
- (c-put-char-property ,end 'category 'c-cpp-delimiter))))
-(defmacro c-clear-cpp-delimiters (beg end)
- ;; This macro does a hidden buffer change.
- `(progn
- (c-clear-char-property ,beg 'category)
- (if (< ,end (point-max))
- (c-clear-char-property ,end 'category))))
-
-(defsubst c-comment-out-cpps ()
- ;; Render all preprocessor constructs syntactically commented out.
- (put 'c-cpp-delimiter 'syntax-table c-cpp-delimiter))
-(defsubst c-uncomment-out-cpps ()
- ;; Restore the syntactic visibility of preprocessor constructs.
- (put 'c-cpp-delimiter 'syntax-table nil))
-
-(defmacro c-with-cpps-commented-out (&rest forms)
- ;; Execute FORMS... whilst the syntactic effect of all characters in
- ;; all CPP regions is suppressed. In particular, this is to suppress
- ;; the syntactic significance of parens/braces/brackets to functions
- ;; such as `scan-lists' and `parse-partial-sexp'.
- `(unwind-protect
- (c-save-buffer-state ()
- (c-comment-out-cpps)
- ,@forms)
- (c-save-buffer-state ()
- (c-uncomment-out-cpps))))
-
-(defmacro c-with-all-but-one-cpps-commented-out (beg end &rest forms)
- ;; Execute FORMS... whilst the syntactic effect of all characters in
- ;; every CPP region APART FROM THE ONE BETWEEN BEG and END is
- ;; suppressed.
- `(unwind-protect
- (c-save-buffer-state ()
- (save-restriction
- (widen)
- (c-clear-cpp-delimiters ,beg ,end))
- ,`(c-with-cpps-commented-out ,@forms))
- (c-save-buffer-state ()
- (save-restriction
- (widen)
- (c-set-cpp-delimiters ,beg ,end)))))
-
(defmacro c-self-bind-state-cache (&rest forms)
;; Bind the state cache to itself and execute the FORMS. Return the result
;; of the last FORM executed. It is assumed that no buffer changes will
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 12ec8f7..7b9baee 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -238,8 +238,8 @@
;; `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. */
+;; Either nil, or the position of a comment which is open at the end of the
+;; macro represented by `c-macro-cache'.
(defun c-invalidate-macro-cache (beg _end)
;; Called from a before-change function. If the change region is before or
@@ -382,8 +382,9 @@ comment at the start of cc-engine.el for more info."
(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.
+ ;; Go to the start of the comment which is open at the end of the current
+ ;; CPP directive, or to the end of that directive. For this purpose, open
+ ;; strings are ignored.
;;
;; This function must only be called from the beginning of a CPP construct.
;;
@@ -401,7 +402,7 @@ comment at the start of cc-engine.el for more info."
(setq s (parse-partial-sexp here there)))
(when (and (nth 4 s)
(not (eq (nth 7 s) 'syntax-table))) ; no pseudo comments.
- (goto-char (1- (nth 8 s))))
+ (goto-char (nth 8 s)))
(setq c-macro-cache-no-comment (point)))
(point)))
@@ -3862,14 +3863,7 @@ comment at the start of cc-engine.el for more info."
(if (eval-when-compile (memq 'category-properties c-emacs-features))
;; Emacs
(c-with-<->-as-parens-suppressed
- (if (and c-state-old-cpp-beg
- (< c-state-old-cpp-beg here))
- (c-with-all-but-one-cpps-commented-out
- c-state-old-cpp-beg
- c-state-old-cpp-end
- (c-invalidate-state-cache-1 here))
- (c-with-cpps-commented-out
- (c-invalidate-state-cache-1 here))))
+ (c-invalidate-state-cache-1 here))
;; XEmacs
(c-invalidate-state-cache-1 here)))
@@ -3902,12 +3896,7 @@ comment at the start of cc-engine.el for more info."
(if (eval-when-compile (memq 'category-properties c-emacs-features))
;; Emacs
(c-with-<->-as-parens-suppressed
- (if (and here-cpp-beg (> here-cpp-end here-cpp-beg))
- (c-with-all-but-one-cpps-commented-out
- here-cpp-beg here-cpp-end
- (c-parse-state-1))
- (c-with-cpps-commented-out
- (c-parse-state-1))))
+ (c-parse-state-1))
;; XEmacs
(c-parse-state-1))
(setq c-state-old-cpp-beg
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 169b61c..12a1587 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -518,13 +518,13 @@ parameters \(point-min) and \(point-max).")
(c objc) '(c-depropertize-new-text
c-parse-quotes-after-change
c-extend-font-lock-region-for-macros
- c-neutralize-syntax-in-and-mark-CPP
+ c-neutralize-syntax-in-CPP
c-change-expand-fl-region)
c++ '(c-depropertize-new-text
c-parse-quotes-after-change
c-extend-font-lock-region-for-macros
c-after-change-re-mark-raw-strings
- c-neutralize-syntax-in-and-mark-CPP
+ c-neutralize-syntax-in-CPP
c-restore-<>-properties
c-change-expand-fl-region)
java '(c-depropertize-new-text
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 22dea03..4073a5a 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -1016,15 +1016,10 @@ Note that the style variables are always made local to
the buffer."
t)
(t nil)))))))
-(defun c-neutralize-syntax-in-and-mark-CPP (_begg _endd _old-len)
- ;; (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.
- ;;
- ;; (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 delimiter.
+(defun c-neutralize-syntax-in-CPP (_begg _endd _old-len)
+ ;; "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.
;;
;; That is, set syntax-table properties on characters that would otherwise
;; interact syntactically with those outside the CPP line(s).
@@ -1044,12 +1039,7 @@ Note that the style variables are always made local to
the buffer."
(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:
- (if (eval-when-compile (memq 'category-properties c-emacs-features));Emacs.
- (c-clear-char-property-with-value
- c-new-BEG c-new-END 'category 'c-cpp-delimiter))
- ;; FIXME!!! What about the "<" and ">" category properties? 2009-11-16
+ ;; The above is now done in `c-depropertize-CPP'.
;; Add needed properties to each CPP construct in the region.
(goto-char c-new-BEG)
@@ -1076,11 +1066,7 @@ Note that the style variables are always made local to
the buffer."
(goto-char (match-beginning 1))
(setq mbeg (point))
(if (> (c-no-comment-end-of-macro) mbeg)
- (progn
- (c-neutralize-CPP-line mbeg (point)) ; "punctuation" properties
- (if (eval-when-compile
- (memq 'category-properties c-emacs-features)) ;Emacs.
- (c-set-cpp-delimiters mbeg (point)))) ; "comment" markers
+ (c-neutralize-CPP-line mbeg (point)) ; "punctuation" properties
(forward-line)) ; no infinite loop with, e.g., "#//"
)))))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] emacs-26 88ddf53: Fontify a CPP construct correctly when a comment follows without spaces,
Alan Mackenzie <=