diff options
| author | Alan Mackenzie | 2019-08-02 11:24:38 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2019-08-02 11:24:38 +0000 |
| commit | 2ca12bb3de7f76446c102bb1e133f6ac03f7d8be (patch) | |
| tree | 62f814ed7147a8f3276e521751724835f022707c | |
| parent | ccc52f1d97ad71f2af3f237168018180fa4f873f (diff) | |
| download | emacs-2ca12bb3de7f76446c102bb1e133f6ac03f7d8be.tar.gz emacs-2ca12bb3de7f76446c102bb1e133f6ac03f7d8be.zip | |
CC Mode: Fix the timing of application and removal of string fence properties
This fixes bug #36897.
* lisp/progmodes/cc-mode.el (c-before-change-check-unbalanced-strings): Check
string fence text properties are actually present on string delimiters before
trying to remove them.
(c-before-change): Amend the nesting of unwind-protect, widen,
c-restore-string-fences, and c-clear-string-fences. Move
invalidate-state-cache to outside of the widening.
(c-after-change): Amend the nesting of unwind-protect, widen,
c-restore-string-fences, and c-clear-string-fences.
| -rw-r--r-- | lisp/progmodes/cc-mode.el | 71 |
1 files changed, 35 insertions, 36 deletions
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 5e373b6e170..60a9de5ddb5 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el | |||
| @@ -1426,8 +1426,11 @@ Note that the style variables are always made local to the buffer." | |||
| 1426 | (and c-multiline-string-start-char | 1426 | (and c-multiline-string-start-char |
| 1427 | (not (c-characterp c-multiline-string-start-char)))) | 1427 | (not (c-characterp c-multiline-string-start-char)))) |
| 1428 | (when (and (eq end-literal-type 'string) | 1428 | (when (and (eq end-literal-type 'string) |
| 1429 | (not (eq (char-before (cdr end-limits)) ?\())) | 1429 | (not (eq (char-before (cdr end-limits)) ?\()) |
| 1430 | (c-remove-string-fences (1- (cdr end-limits))) | 1430 | (memq (char-after (car end-limits)) c-string-delims) |
| 1431 | (equal (c-get-char-property (car end-limits) 'syntax-table) | ||
| 1432 | '(15))) | ||
| 1433 | (c-remove-string-fences (car end-limits)) | ||
| 1431 | (setq c-new-END (max c-new-END (cdr end-limits)))) | 1434 | (setq c-new-END (max c-new-END (cdr end-limits)))) |
| 1432 | 1435 | ||
| 1433 | (when (and (eq beg-literal-type 'string) | 1436 | (when (and (eq beg-literal-type 'string) |
| @@ -1864,12 +1867,12 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") | |||
| 1864 | ;; property changes. | 1867 | ;; property changes. |
| 1865 | (when (fboundp 'syntax-ppss) | 1868 | (when (fboundp 'syntax-ppss) |
| 1866 | (setq c-syntax-table-hwm most-positive-fixnum)) | 1869 | (setq c-syntax-table-hwm most-positive-fixnum)) |
| 1867 | (unwind-protect | 1870 | (save-restriction |
| 1868 | (progn | 1871 | (save-match-data |
| 1869 | (c-restore-string-fences (point-min) (point-max)) | 1872 | (widen) |
| 1870 | (save-restriction | 1873 | (unwind-protect |
| 1871 | (save-match-data | 1874 | (progn |
| 1872 | (widen) | 1875 | (c-restore-string-fences (point-min) (point-max)) |
| 1873 | (save-excursion | 1876 | (save-excursion |
| 1874 | ;; Are we inserting/deleting stuff in the middle of an | 1877 | ;; Are we inserting/deleting stuff in the middle of an |
| 1875 | ;; identifier? | 1878 | ;; identifier? |
| @@ -1896,8 +1899,8 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") | |||
| 1896 | 'font-lock-comment-face) | 1899 | 'font-lock-comment-face) |
| 1897 | (previous-single-property-change end 'face)) | 1900 | (previous-single-property-change end 'face)) |
| 1898 | end))) | 1901 | end))) |
| 1899 | (when (>= end1 beg) ; Don't hassle about changes | 1902 | (when (>= end1 beg) ; Don't hassle about changes entirely in |
| 1900 | ; entirely in comments. | 1903 | ; comments. |
| 1901 | ;; Find a limit for the search for a `c-type' property | 1904 | ;; Find a limit for the search for a `c-type' property |
| 1902 | (while | 1905 | (while |
| 1903 | (and (/= (skip-chars-backward "^;{}") 0) | 1906 | (and (/= (skip-chars-backward "^;{}") 0) |
| @@ -1924,12 +1927,11 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") | |||
| 1924 | (buffer-substring-no-properties (point) type-pos))) | 1927 | (buffer-substring-no-properties (point) type-pos))) |
| 1925 | 1928 | ||
| 1926 | (goto-char end1) | 1929 | (goto-char end1) |
| 1927 | (skip-chars-forward "^;{}") ;FIXME!!! loop for | 1930 | (skip-chars-forward "^;{}") ; FIXME!!! loop for |
| 1928 | ;comment, maybe | 1931 | ; comment, maybe |
| 1929 | (setq lim (point)) | 1932 | (setq lim (point)) |
| 1930 | (setq term-pos | 1933 | (setq term-pos |
| 1931 | (or (c-next-single-property-change end 'c-type nil lim) | 1934 | (or (c-next-single-property-change end 'c-type nil lim) lim)) |
| 1932 | lim)) | ||
| 1933 | (setq c-maybe-stale-found-type | 1935 | (setq c-maybe-stale-found-type |
| 1934 | (list type marked-id | 1936 | (list type marked-id |
| 1935 | type-pos term-pos | 1937 | type-pos term-pos |
| @@ -1940,14 +1942,13 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") | |||
| 1940 | (if c-get-state-before-change-functions | 1942 | (if c-get-state-before-change-functions |
| 1941 | (mapc (lambda (fn) | 1943 | (mapc (lambda (fn) |
| 1942 | (funcall fn beg end)) | 1944 | (funcall fn beg end)) |
| 1943 | c-get-state-before-change-functions)) | 1945 | c-get-state-before-change-functions)))) |
| 1944 | ))) | 1946 | (c-clear-string-fences)))) |
| 1945 | ;; The following must be done here rather than in | 1947 | (c-truncate-lit-pos-cache beg) |
| 1946 | ;; `c-after-change' because newly inserted parens would foul | 1948 | ;; The following must be done here rather than in `c-after-change' |
| 1947 | ;; up the invalidation algorithm. | 1949 | ;; because newly inserted parens would foul up the invalidation |
| 1948 | (c-invalidate-state-cache beg) | 1950 | ;; algorithm. |
| 1949 | (c-truncate-lit-pos-cache beg)) | 1951 | (c-invalidate-state-cache beg))) |
| 1950 | (c-clear-string-fences)))) | ||
| 1951 | 1952 | ||
| 1952 | (defvar c-in-after-change-fontification nil) | 1953 | (defvar c-in-after-change-fontification nil) |
| 1953 | (make-variable-buffer-local 'c-in-after-change-fontification) | 1954 | (make-variable-buffer-local 'c-in-after-change-fontification) |
| @@ -1991,19 +1992,17 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") | |||
| 1991 | ;; When `combine-after-change-calls' is used we might get calls | 1992 | ;; When `combine-after-change-calls' is used we might get calls |
| 1992 | ;; with regions outside the current narrowing. This has been | 1993 | ;; with regions outside the current narrowing. This has been |
| 1993 | ;; observed in Emacs 20.7. | 1994 | ;; observed in Emacs 20.7. |
| 1994 | (unwind-protect | 1995 | (save-restriction |
| 1995 | (progn | 1996 | (save-match-data ; c-recognize-<>-arglists changes match-data |
| 1996 | (c-restore-string-fences (point-min) (point-max)) | 1997 | (widen) |
| 1997 | (save-restriction | 1998 | (unwind-protect |
| 1998 | (save-match-data ; c-recognize-<>-arglists changes match-data | 1999 | (progn |
| 1999 | (widen) | 2000 | (c-restore-string-fences (point-min) (point-max)) |
| 2000 | |||
| 2001 | (when (> end (point-max)) | 2001 | (when (> end (point-max)) |
| 2002 | ;; Some emacsen might return positions past the | 2002 | ;; Some emacsen might return positions past the end. This |
| 2003 | ;; end. This has been observed in Emacs 20.7 when | 2003 | ;; has been observed in Emacs 20.7 when rereading a buffer |
| 2004 | ;; rereading a buffer changed on disk (haven't been | 2004 | ;; changed on disk (haven't been able to minimize it, but |
| 2005 | ;; able to minimize it, but Emacs 21.3 appears to | 2005 | ;; Emacs 21.3 appears to work). |
| 2006 | ;; work). | ||
| 2007 | (setq end (point-max)) | 2006 | (setq end (point-max)) |
| 2008 | (when (> beg end) | 2007 | (when (> beg end) |
| 2009 | (setq beg end))) | 2008 | (setq beg end))) |
| @@ -2034,8 +2033,8 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") | |||
| 2034 | (save-excursion | 2033 | (save-excursion |
| 2035 | (mapc (lambda (fn) | 2034 | (mapc (lambda (fn) |
| 2036 | (funcall fn beg end old-len)) | 2035 | (funcall fn beg end old-len)) |
| 2037 | c-before-font-lock-functions))))) | 2036 | c-before-font-lock-functions))) |
| 2038 | (c-clear-string-fences)))) | 2037 | (c-clear-string-fences)))))) |
| 2039 | ;; A workaround for syntax-ppss's failure to notice syntax-table text | 2038 | ;; A workaround for syntax-ppss's failure to notice syntax-table text |
| 2040 | ;; property changes. | 2039 | ;; property changes. |
| 2041 | (when (fboundp 'syntax-ppss) | 2040 | (when (fboundp 'syntax-ppss) |