diff options
| author | Alan Mackenzie | 2018-05-31 11:32:15 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2018-05-31 11:32:15 +0000 |
| commit | e50634c3543facde0ab5891548ae54aa1cd30caf (patch) | |
| tree | 73a0b7b3ddb2e5a4ff792effbbce2992a663e385 | |
| parent | fb9c52bb7d29c85f3baee770355260830dacea50 (diff) | |
| download | emacs-e50634c3543facde0ab5891548ae54aa1cd30caf.tar.gz emacs-e50634c3543facde0ab5891548ae54aa1cd30caf.zip | |
Amend c-before-change-check-unbalanced-strings to handle a quote at EOB.
* lisp/progmodes/cc-mode.el (c-before-change-check-unbalanced-strings): Before
going back a sexp from the \n marked with a string-fence syntax-table text
property, check that it is indeed a \n. If not, simply delete that text
property from the isolated quote, not the quote and the \n which otherwise
delimit an unterminated string. Should we encounter a double quote marked
with a string-fence syntax-table text property at the end of the last line,
remove that property.
| -rw-r--r-- | lisp/progmodes/cc-mode.el | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 2427191eae0..49c917160c1 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el | |||
| @@ -1121,7 +1121,8 @@ Note that the style variables are always made local to the buffer." | |||
| 1121 | ;; If BEG or END is inside an unbalanced string, remove the syntax-table | 1121 | ;; If BEG or END is inside an unbalanced string, remove the syntax-table |
| 1122 | ;; text property from respectively the start or end of the string. Also | 1122 | ;; text property from respectively the start or end of the string. Also |
| 1123 | ;; extend the region (c-new-BEG c-new-END) as necessary to cope with the | 1123 | ;; extend the region (c-new-BEG c-new-END) as necessary to cope with the |
| 1124 | ;; change being the insertion of an odd number of quotes. | 1124 | ;; coming change involving the insertion or deletion of an odd number of |
| 1125 | ;; quotes. | ||
| 1125 | ;; | 1126 | ;; |
| 1126 | ;; POINT is undefined both at entry to and exit from this function, the | 1127 | ;; POINT is undefined both at entry to and exit from this function, the |
| 1127 | ;; buffer will have been widened, and match data will have been saved. | 1128 | ;; buffer will have been widened, and match data will have been saved. |
| @@ -1169,31 +1170,37 @@ Note that the style variables are always made local to the buffer." | |||
| 1169 | (c-clear-char-property (1- (point)) 'syntax-table) | 1170 | (c-clear-char-property (1- (point)) 'syntax-table) |
| 1170 | (not (eq (char-before) ?\"))))) | 1171 | (not (eq (char-before) ?\"))))) |
| 1171 | (eq (char-before) ?\")) | 1172 | (eq (char-before) ?\")) |
| 1172 | (if (eq (char-before (1- (point))) | 1173 | (progn |
| 1173 | c-multiline-string-start-char) | 1174 | (c-pps-to-string-delim (point-max)) |
| 1174 | (progn | 1175 | (< (point) (point-max)))))) |
| 1175 | (c-pps-to-string-delim (point-max)) | ||
| 1176 | (< (point) (point-max))) | ||
| 1177 | (c-pps-to-string-delim (c-point 'eoll)) | ||
| 1178 | (< (point) (c-point 'eoll)))))) | ||
| 1179 | (setq c-new-END (max (point) c-new-END))) | 1176 | (setq c-new-END (max (point) c-new-END))) |
| 1180 | 1177 | ||
| 1181 | ((< c-new-END (point-max)) | 1178 | ((< c-new-END (point-max)) |
| 1182 | (goto-char (1+ c-new-END)) ; might be a newline. | 1179 | (goto-char (1+ c-new-END)) ; might be a newline. |
| 1183 | ;; In the following regexp, the initial \n caters for a newline getting | 1180 | ;; In the following regexp, the initial \n caters for a newline getting |
| 1184 | ;; joined to a preceding \ by the removal of what comes between. | 1181 | ;; joined to a preceding \ by the removal of what comes between. |
| 1185 | (re-search-forward "\n?\\(\\\\\\(.\\|\n\\|\r\\)\\|[^\\\n\r]\\)*" nil t) | 1182 | (re-search-forward "[\n\r]?\\(\\\\\\(.\\|\n\\|\r\\)\\|[^\\\n\r]\\)*" |
| 1183 | nil t) | ||
| 1186 | ;; We're at an EOLL or point-max. | 1184 | ;; We're at an EOLL or point-max. |
| 1187 | (setq c-new-END (min (1+ (point)) (point-max))) | 1185 | (setq c-new-END (min (1+ (point)) (point-max))) |
| 1188 | ;; FIXME!!! Write a clever comment here. | 1186 | ;; FIXME!!! Write a clever comment here. |
| 1189 | (goto-char c-new-END) | 1187 | (goto-char c-new-END) |
| 1190 | (when (equal (c-get-char-property (1- (point)) 'syntax-table) '(15)) | 1188 | (if (equal (c-get-char-property (1- (point)) 'syntax-table) '(15)) |
| 1191 | (backward-sexp) | 1189 | (if (memq (char-before) '(?\n ?\r)) |
| 1192 | (c-clear-char-property (1- c-new-END) 'syntax-table) | 1190 | ;; Normally terminated invalid string. |
| 1193 | (c-clear-char-property (point) 'syntax-table))) | 1191 | (progn |
| 1194 | 1192 | (backward-sexp) | |
| 1195 | (t (if (memq (char-before c-new-END) c-string-delims) | 1193 | (c-clear-char-property (1- c-new-END) 'syntax-table) |
| 1196 | (c-clear-char-property (1- c-new-END) 'syntax-table)))) | 1194 | (c-clear-char-property (point) 'syntax-table)) |
| 1195 | ;; Opening " at EOB. | ||
| 1196 | (c-clear-char-property (1- (point)) 'syntax-table)) | ||
| 1197 | (if (c-search-backward-char-property 'syntax-table '(15) c-new-BEG) | ||
| 1198 | ;; Opening " on last line of text (without EOL). | ||
| 1199 | (c-clear-char-property (point) 'syntax-table)))) | ||
| 1200 | |||
| 1201 | (t (goto-char c-new-END) | ||
| 1202 | (if (c-search-backward-char-property 'syntax-table '(15) c-new-BEG) | ||
| 1203 | (c-clear-char-property (point) 'syntax-table)))) | ||
| 1197 | 1204 | ||
| 1198 | (when (eq end-literal-type 'string) | 1205 | (when (eq end-literal-type 'string) |
| 1199 | (c-clear-char-property (1- (cdr end-limits)) 'syntax-table)) | 1206 | (c-clear-char-property (1- (cdr end-limits)) 'syntax-table)) |