diff options
| author | Alan Mackenzie | 2019-12-07 18:55:19 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2019-12-07 18:55:19 +0000 |
| commit | 68d4a14fd46754c3951dd669c9821447bfbe844e (patch) | |
| tree | f080f2651bb3ff1257e27d26788d10ce38069af6 | |
| parent | 959bbf30032c365c9e6f08dc9211d6bab3123f35 (diff) | |
| download | emacs-68d4a14fd46754c3951dd669c9821447bfbe844e.tar.gz emacs-68d4a14fd46754c3951dd669c9821447bfbe844e.zip | |
CC Mode: Allow most functions on post-self-insert-hook to be called
This contrasts with the previous state where no such functions got called.
This fixes bug #38406.
* lisp/progmodes/cc-cmds.el (c--unsafe-post-self-insert-hook-functions): New
variable.
(c--call-post-self-insert-hook-more-safely-1): New function.
(c--call-post-self-insert-hook-more-safely): New macro.
(c-electric-pound, c-electric-brace, c-electric-slash, c-electric-star)
(c-electric-semi&comma, c-electric-colon, c-electric-lt-gt, c-electric-paren):
Invoke c--call-post-self-insert-hook-more-safely (which calls most of the hook
post-self-insert-hook) at the end of each of the commands.
| -rw-r--r-- | lisp/progmodes/cc-cmds.el | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index af2efb63fc3..0343f9df32b 100644 --- a/lisp/progmodes/cc-cmds.el +++ b/lisp/progmodes/cc-cmds.el | |||
| @@ -495,6 +495,36 @@ function to control that." | |||
| 495 | (c-hungry-delete-forward) | 495 | (c-hungry-delete-forward) |
| 496 | (c-hungry-delete-backwards))) | 496 | (c-hungry-delete-backwards))) |
| 497 | 497 | ||
| 498 | (defvar c--unsafe-post-self-insert-hook-functions | ||
| 499 | '(electric-pair-post-self-insert-function) | ||
| 500 | "Known unsafe functions when members of `post-self-insert-hook' in CC Mode") | ||
| 501 | |||
| 502 | (defun c--call-post-self-insert-hook-more-safely-1 () | ||
| 503 | ;; Call post-self-insert-hook, having removed from `post-self-insert-hook' | ||
| 504 | ;; functions known not to be safe to CC Mode. The result is of no | ||
| 505 | ;; significance. Note that the hook call is NOT absolutely safe. | ||
| 506 | (let ((src post-self-insert-hook) | ||
| 507 | dest) | ||
| 508 | (while src | ||
| 509 | (cond | ||
| 510 | ((memq (car src) c--unsafe-post-self-insert-hook-functions)) | ||
| 511 | ((eq (car src) t) | ||
| 512 | (let ((src (default-value 'post-self-insert-hook))) | ||
| 513 | (while src | ||
| 514 | (unless (memq (car src) c--unsafe-post-self-insert-hook-functions) | ||
| 515 | (add-hook 'dest (car src) t)) ; Preserve the order of the functions. | ||
| 516 | (setq src (cdr src))))) | ||
| 517 | (t (add-hook 'dest (car src) t))) ; Preserve the order of the functions. | ||
| 518 | (setq src (cdr src))) | ||
| 519 | (run-hooks 'dest))) | ||
| 520 | |||
| 521 | (defmacro c--call-post-self-insert-hook-more-safely () | ||
| 522 | ;; Call post-self-insert-hook, if such exists. See comment for | ||
| 523 | ;; `c--call-post-self-insert-hook-more-safely-1'. | ||
| 524 | (if (boundp 'post-self-insert-hook) | ||
| 525 | '(c--call-post-self-insert-hook-more-safely-1) | ||
| 526 | '(progn))) | ||
| 527 | |||
| 498 | (defun c-electric-pound (arg) | 528 | (defun c-electric-pound (arg) |
| 499 | "Insert a \"#\". | 529 | "Insert a \"#\". |
| 500 | If `c-electric-flag' is set, handle it specially according to the variable | 530 | If `c-electric-flag' is set, handle it specially according to the variable |
| @@ -524,7 +554,8 @@ inside a literal or a macro, nothing special happens." | |||
| 524 | (insert (c-last-command-char)) | 554 | (insert (c-last-command-char)) |
| 525 | (and (not bolp) | 555 | (and (not bolp) |
| 526 | (goto-char (- (point-max) pos))) | 556 | (goto-char (- (point-max) pos))) |
| 527 | ))) | 557 | )) |
| 558 | (c--call-post-self-insert-hook-more-safely)) | ||
| 528 | 559 | ||
| 529 | (defun c-point-syntax () | 560 | (defun c-point-syntax () |
| 530 | ;; Return the syntactic context of the construct at point. (This is NOT | 561 | ;; Return the syntactic context of the construct at point. (This is NOT |
| @@ -905,7 +936,8 @@ settings of `c-cleanup-list' are done." | |||
| 905 | (save-excursion | 936 | (save-excursion |
| 906 | (c-save-buffer-state nil | 937 | (c-save-buffer-state nil |
| 907 | (c-backward-syntactic-ws safepos)) | 938 | (c-backward-syntactic-ws safepos)) |
| 908 | (funcall old-blink-paren))))) | 939 | (funcall old-blink-paren))) |
| 940 | (c--call-post-self-insert-hook-more-safely))) | ||
| 909 | 941 | ||
| 910 | (defun c-electric-slash (arg) | 942 | (defun c-electric-slash (arg) |
| 911 | "Insert a slash character. | 943 | "Insert a slash character. |
| @@ -957,7 +989,8 @@ is inhibited." | |||
| 957 | (let (post-self-insert-hook) ; Disable random functionality. | 989 | (let (post-self-insert-hook) ; Disable random functionality. |
| 958 | (self-insert-command (prefix-numeric-value arg))) | 990 | (self-insert-command (prefix-numeric-value arg))) |
| 959 | (if indentp | 991 | (if indentp |
| 960 | (indent-according-to-mode)))) | 992 | (indent-according-to-mode)) |
| 993 | (c--call-post-self-insert-hook-more-safely))) | ||
| 961 | 994 | ||
| 962 | (defun c-electric-star (arg) | 995 | (defun c-electric-star (arg) |
| 963 | "Insert a star character. | 996 | "Insert a star character. |
| @@ -987,7 +1020,8 @@ this indentation is inhibited." | |||
| 987 | (bolp)))) | 1020 | (bolp)))) |
| 988 | (let (c-echo-syntactic-information-p) ; shut this up | 1021 | (let (c-echo-syntactic-information-p) ; shut this up |
| 989 | (indent-according-to-mode)) | 1022 | (indent-according-to-mode)) |
| 990 | )) | 1023 | ) |
| 1024 | (c--call-post-self-insert-hook-more-safely)) | ||
| 991 | 1025 | ||
| 992 | (defun c-electric-semi&comma (arg) | 1026 | (defun c-electric-semi&comma (arg) |
| 993 | "Insert a comma or semicolon. | 1027 | "Insert a comma or semicolon. |
| @@ -1059,8 +1093,8 @@ settings of `c-cleanup-list'." | |||
| 1059 | (setq add-newline-p (not (eq answer 'stop))) | 1093 | (setq add-newline-p (not (eq answer 'stop))) |
| 1060 | )) | 1094 | )) |
| 1061 | (if add-newline-p | 1095 | (if add-newline-p |
| 1062 | (c-newline-and-indent)) | 1096 | (c-newline-and-indent))))) |
| 1063 | ))))) | 1097 | (c--call-post-self-insert-hook-more-safely))) |
| 1064 | 1098 | ||
| 1065 | (defun c-electric-colon (arg) | 1099 | (defun c-electric-colon (arg) |
| 1066 | "Insert a colon. | 1100 | "Insert a colon. |
| @@ -1162,8 +1196,8 @@ reindented unless `c-syntactic-indentation' is nil. | |||
| 1162 | ;; does a newline go after the colon? | 1196 | ;; does a newline go after the colon? |
| 1163 | (if (and (memq 'after (cdr-safe newlines)) | 1197 | (if (and (memq 'after (cdr-safe newlines)) |
| 1164 | (not is-scope-op)) | 1198 | (not is-scope-op)) |
| 1165 | (c-newline-and-indent)) | 1199 | (c-newline-and-indent)))) |
| 1166 | )))) | 1200 | (c--call-post-self-insert-hook-more-safely))) |
| 1167 | 1201 | ||
| 1168 | (defun c-electric-lt-gt (arg) | 1202 | (defun c-electric-lt-gt (arg) |
| 1169 | "Insert a \"<\" or \">\" character. | 1203 | "Insert a \"<\" or \">\" character. |
| @@ -1253,7 +1287,8 @@ numeric argument is supplied, or the point is inside a literal." | |||
| 1253 | ;; From now (2016-01-01), the syntax-table text properties on < and > | 1287 | ;; From now (2016-01-01), the syntax-table text properties on < and > |
| 1254 | ;; are applied in an after-change function, not during redisplay. Hence | 1288 | ;; are applied in an after-change function, not during redisplay. Hence |
| 1255 | ;; we no longer need to call (sit-for 0) for blink paren to work. | 1289 | ;; we no longer need to call (sit-for 0) for blink paren to work. |
| 1256 | (funcall blink-paren-function))))) | 1290 | (funcall blink-paren-function)))) |
| 1291 | (c--call-post-self-insert-hook-more-safely)) | ||
| 1257 | 1292 | ||
| 1258 | (defun c-electric-paren (arg) | 1293 | (defun c-electric-paren (arg) |
| 1259 | "Insert a parenthesis. | 1294 | "Insert a parenthesis. |
| @@ -1372,7 +1407,8 @@ newline cleanups are done if appropriate; see the variable `c-cleanup-list'." | |||
| 1372 | ;; Apply `electric-pair-mode' stuff inside a string or comment. | 1407 | ;; Apply `electric-pair-mode' stuff inside a string or comment. |
| 1373 | (when (and (boundp 'electric-pair-mode) electric-pair-mode) | 1408 | (when (and (boundp 'electric-pair-mode) electric-pair-mode) |
| 1374 | (let (post-self-insert-hook) | 1409 | (let (post-self-insert-hook) |
| 1375 | (electric-pair-post-self-insert-function)))))) | 1410 | (electric-pair-post-self-insert-function)))) |
| 1411 | (c--call-post-self-insert-hook-more-safely))) | ||
| 1376 | 1412 | ||
| 1377 | (defun c-electric-continued-statement () | 1413 | (defun c-electric-continued-statement () |
| 1378 | "Reindent the current line if appropriate. | 1414 | "Reindent the current line if appropriate. |