diff options
| author | Alan Mackenzie <acm@muc.de> | 2019-07-16 20:01:12 +0000 |
|---|---|---|
| committer | Alan Mackenzie <acm@muc.de> | 2019-07-16 20:01:12 +0000 |
| commit | 585fb957399f21a93cbfabd182b76262466797e3 (patch) | |
| tree | 3b3656706b56b771b316e5fb159f231688e4713b /lisp/progmodes/cc-engine.el | |
| parent | d2758820cd45733570c704431da3f3e91dbb8605 (diff) | |
| download | emacs-585fb957399f21a93cbfabd182b76262466797e3.tar.gz | |
CC Mode: allow bogusly "adjacent" double quote marks to pair up syntactically
For this introduce the text property c-fl-syn-tab to "mirror" syntax-table.
* lisp/progmodes/cc-defs.el (c-is-escaped, c-will-be-escaped, c-put-syn-tab)
(c-clear-syn-tab, c-clear-syn-tab-properties, c-with-extended-string-fences):
new macros.
(c-point): Use c-is-escaped
(c-search-forward-char-property, c-search-backward-char-property)
(c-search-forward-char-property-with-value-on-char)
(c-search-forward-char-property-without-value-on-char): Fix regexp error
involving \n.
* lisp/progmodes/cc-engine.el (c-semi-pp-to-literal): User
c-with-extended-string-fences around a parse-partial-sexp.
(c-full-get-near-cache-entry): Fix an off-by-one error.
(c-full-pp-to-literal): Avoid writing duplicate entries into a cache.
(c-after-change-unmark-raw-strings): Use c-clear-syn-tab-properties.
* lisp/progmodes/cc-mode.el (c-leave-cc-mode-mode): Clear the c-fl-syn-tab
properties, too.
(c-basic-common-init): Mark c-fl-syn-tab as a non-sticky text property.
(c-depropertize-new-text): Also handle c-fl-syn-tab.
(c-multiline-string-check-final-quote, c-parse-quotes-after-change): Use
c-is-escaped.
(c-fl-syn-tab-region): New variable.
(c-clear-string-fences, c-restore-string-fences, c-remove-string-fences): New
functions.
(c-before-change-check-unbalanced-strings)
(c-after-change-mark-abnormal-strings, c-after-change-escape-NL-in-string):
Use the new functions and macros.
(c-before-change, c-after-change, c-font-lock-fontify-region): Restore the
syntax-table text properties from c-fl-syn-tab text properties for these
functions.
(c-electric-pair-inhibit-predicate): Test the c-fl-syn-tab property rather
than syntax-table.
Diffstat (limited to 'lisp/progmodes/cc-engine.el')
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 40a3b72f6a2..cb88fc3e58d 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -93,6 +93,14 @@ ;; `text-property-default-nonsticky' if that variable exists (Emacs ;; >= 21). ;; +;; 'c-fl-syn-tab +;; Saves the value of syntax-table properties which have been +;; temporarily removed from certain buffer positions. The syntax-table +;; properties are restored during c-before-change, c-after-change, and +;; font locking. The purpose of the temporary removal is to enable +;; C-M-* key sequences to operate over bogus pairs of string delimiters +;; which are "adjacent", yet do not delimit a string. +;; ;; 'c-is-sws and 'c-in-sws ;; Used by `c-forward-syntactic-ws' and `c-backward-syntactic-ws' to ;; speed them up. See the comment blurb before `c-put-is-sws' @@ -155,6 +163,9 @@ (defvar c-doc-line-join-re) (defvar c-doc-bright-comment-start-re) (defvar c-doc-line-join-end-ch) +(defvar c-fl-syn-tab-region) +(cc-bytecomp-defun c-clear-string-fences) +(cc-bytecomp-defun c-restore-string-fences) ;; Make declarations for all the `c-lang-defvar' variables in cc-langs. @@ -2816,7 +2827,9 @@ comment at the start of cc-engine.el for more info." c-block-comment-awkward-chars))) (and (nth 4 s) (nth 7 s) ; Line comment (not (memq (char-before here) '(?\\ ?\n))))))) - (setq s (parse-partial-sexp pos here nil nil s))) + (c-with-extended-string-fences + pos here + (setq s (parse-partial-sexp pos here nil nil s)))) (when (not (eq near-pos here)) (c-semi-put-near-cache-entry here s)) (cond @@ -2883,7 +2896,7 @@ comment at the start of cc-engine.el for more info." (setq elt (car nc-list)) (when (and (car (cddr elt)) - (>= here (nth 8 (cadr elt))) + (> here (nth 8 (cadr elt))) (< here (car (cddr elt)))) (throw 'found elt)) (when @@ -2902,7 +2915,7 @@ comment at the start of cc-engine.el for more info." (copy-tree nc-pos-state))) (defun c-full-put-near-cache-entry (here state end) - ;; Put a new near chace entry into the near cache. + ;; Put a new near cache entry into the near cache. (while (>= (length c-full-lit-near-cache) 6) (setq c-full-lit-near-cache (delq (car (last c-full-lit-near-cache)) @@ -3001,7 +3014,8 @@ comment at the start of cc-engine.el for more info." (list s ty (cons start (point)))) (t - (c-full-put-near-cache-entry here s nil) + (unless (eq near-base here) + (c-full-put-near-cache-entry here s nil)) (list s)))))))) (defsubst c-truncate-lit-pos-cache (pos) @@ -7379,7 +7393,7 @@ comment at the start of cc-engine.el for more info." (when found (setq c-new-BEG (min (point) c-new-BEG) c-new-END (point-max)) - (c-clear-char-properties (point) c-new-END 'syntax-table) + (c-clear-syn-tab-properties (point) c-new-END) (c-truncate-lit-pos-cache (point))))) ;; Are there any raw strings in a newly created macro? |
