diff options
| author | Alan Mackenzie | 2019-07-08 09:24:29 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2019-07-08 09:24:29 +0000 |
| commit | 8d5cdd688f5dd39c8e667f9c6c2c4876c7fdc564 (patch) | |
| tree | 1261035b3ff985122b75a1409161e136517d5b81 | |
| parent | ee883189d441b45dc343905074db5187ec900e26 (diff) | |
| download | emacs-8d5cdd688f5dd39c8e667f9c6c2c4876c7fdc564.tar.gz emacs-8d5cdd688f5dd39c8e667f9c6c2c4876c7fdc564.zip | |
Fix bug #36474, such that CC Mode quotes work properly in electric-pair-mode
Also finishes the fix for bug #36423.
* lisp/progmodes/cc-mode.el (c-initialize-cc-mode): Add an `eval-after-load'
to set electric-pair-inhibit-predicate for existing CC Mode buffers when
elec-pair.elc gets loaded.
(c-basic-common-init): Set electric-pair-inhibit-predicate when a CC Mode mode
gets initialized.
(c-electric-pair-inhibit-predicate): New function.
| -rw-r--r-- | lisp/progmodes/cc-mode.el | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index b45c2e5fd38..98b8385fccb 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el | |||
| @@ -226,6 +226,15 @@ control). See \"cc-mode.el\" for more info." | |||
| 226 | (if (boundp 'c-comment-continuation-stars) | 226 | (if (boundp 'c-comment-continuation-stars) |
| 227 | (setq c-block-comment-prefix c-comment-continuation-stars)) | 227 | (setq c-block-comment-prefix c-comment-continuation-stars)) |
| 228 | (add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode) | 228 | (add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode) |
| 229 | ;; Connect up with Emacs's electric-pair-mode | ||
| 230 | (eval-after-load "elec-pair" | ||
| 231 | '(when (boundp 'electric-pair-inhibit-predicate) | ||
| 232 | (dolist (buf (buffer-list)) | ||
| 233 | (with-current-buffer buf | ||
| 234 | (when c-buffer-is-cc-mode | ||
| 235 | (make-local-variable 'electric-pair-inhibit-predicate) | ||
| 236 | (setq electric-pair-inhibit-predicate | ||
| 237 | #'c-electric-pair-inhibit-predicate)))))) | ||
| 229 | (setq c-initialization-ok t) | 238 | (setq c-initialization-ok t) |
| 230 | ;; Connect up with Emacs's electric-indent-mode, for >= Emacs 24.4 | 239 | ;; Connect up with Emacs's electric-indent-mode, for >= Emacs 24.4 |
| 231 | (when (fboundp 'electric-indent-local-mode) | 240 | (when (fboundp 'electric-indent-local-mode) |
| @@ -553,6 +562,17 @@ that requires a literal mode spec at compile time." | |||
| 553 | (make-local-variable 'adaptive-fill-regexp) | 562 | (make-local-variable 'adaptive-fill-regexp) |
| 554 | (make-local-variable 'fill-paragraph-handle-comment) | 563 | (make-local-variable 'fill-paragraph-handle-comment) |
| 555 | 564 | ||
| 565 | (setq c-buffer-is-cc-mode mode) | ||
| 566 | |||
| 567 | ;; Prepare for the use of `electric-pair-mode'. Note: if this mode is not | ||
| 568 | ;; yet loaded, `electric-pair-inhibit-predicate' will get set from an | ||
| 569 | ;; `eval-after-load' form in `c-initialize-cc-mode' when elec-pair.elc is | ||
| 570 | ;; loaded. | ||
| 571 | (when (boundp 'electric-pair-inhibit-predicate) | ||
| 572 | (make-local-variable 'electric-pair-inhibit-predicate) | ||
| 573 | (setq electric-pair-inhibit-predicate | ||
| 574 | #'c-electric-pair-inhibit-predicate)) | ||
| 575 | |||
| 556 | ;; now set their values | 576 | ;; now set their values |
| 557 | (set (make-local-variable 'parse-sexp-ignore-comments) t) | 577 | (set (make-local-variable 'parse-sexp-ignore-comments) t) |
| 558 | (set (make-local-variable 'indent-line-function) 'c-indent-line) | 578 | (set (make-local-variable 'indent-line-function) 'c-indent-line) |
| @@ -2255,6 +2275,26 @@ This function is called from `c-common-init', once per mode initialization." | |||
| 2255 | (c-update-modeline))) | 2275 | (c-update-modeline))) |
| 2256 | 2276 | ||
| 2257 | 2277 | ||
| 2278 | ;; Connection with Emacs's electric-pair-mode | ||
| 2279 | (defun c-electric-pair-inhibit-predicate (char) | ||
| 2280 | "Return t to inhibit the insertion of a second copy of CHAR. | ||
| 2281 | |||
| 2282 | At the time of call, point is just after the newly inserted CHAR. | ||
| 2283 | |||
| 2284 | When CHAR is \", t will be returned unless the \" is marked with | ||
| 2285 | a string fence syntax-table text property. For other characters, | ||
| 2286 | the default value of `electric-pair-inhibit-predicate' is called | ||
| 2287 | and its value returned. | ||
| 2288 | |||
| 2289 | This function is the appropriate value of | ||
| 2290 | `electric-pair-inhibit-predicate' for CC Mode modes, which mark | ||
| 2291 | invalid strings with such a syntax table text property on the | ||
| 2292 | opening \" and the next unescaped end of line." | ||
| 2293 | (if (eq char ?\") | ||
| 2294 | (not (equal (get-text-property (1- (point)) 'syntax-table) '(15))) | ||
| 2295 | (funcall (default-value 'electric-pair-inhibit-predicate) char))) | ||
| 2296 | |||
| 2297 | |||
| 2258 | ;; Support for C | 2298 | ;; Support for C |
| 2259 | 2299 | ||
| 2260 | (defvar c-mode-syntax-table | 2300 | (defvar c-mode-syntax-table |