[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 8d5cdd6: Fix bug #36474, such that CC Mode quotes w
From: |
Alan Mackenzie |
Subject: |
[Emacs-diffs] master 8d5cdd6: Fix bug #36474, such that CC Mode quotes work properly in electric-pair-mode |
Date: |
Mon, 8 Jul 2019 05:26:18 -0400 (EDT) |
branch: master
commit 8d5cdd688f5dd39c8e667f9c6c2c4876c7fdc564
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>
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.
---
lisp/progmodes/cc-mode.el | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index b45c2e5..98b8385 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."
(if (boundp 'c-comment-continuation-stars)
(setq c-block-comment-prefix c-comment-continuation-stars))
(add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode)
+ ;; Connect up with Emacs's electric-pair-mode
+ (eval-after-load "elec-pair"
+ '(when (boundp 'electric-pair-inhibit-predicate)
+ (dolist (buf (buffer-list))
+ (with-current-buffer buf
+ (when c-buffer-is-cc-mode
+ (make-local-variable 'electric-pair-inhibit-predicate)
+ (setq electric-pair-inhibit-predicate
+ #'c-electric-pair-inhibit-predicate))))))
(setq c-initialization-ok t)
;; Connect up with Emacs's electric-indent-mode, for >= Emacs 24.4
(when (fboundp 'electric-indent-local-mode)
@@ -553,6 +562,17 @@ that requires a literal mode spec at compile time."
(make-local-variable 'adaptive-fill-regexp)
(make-local-variable 'fill-paragraph-handle-comment)
+ (setq c-buffer-is-cc-mode mode)
+
+ ;; Prepare for the use of `electric-pair-mode'. Note: if this mode is not
+ ;; yet loaded, `electric-pair-inhibit-predicate' will get set from an
+ ;; `eval-after-load' form in `c-initialize-cc-mode' when elec-pair.elc is
+ ;; loaded.
+ (when (boundp 'electric-pair-inhibit-predicate)
+ (make-local-variable 'electric-pair-inhibit-predicate)
+ (setq electric-pair-inhibit-predicate
+ #'c-electric-pair-inhibit-predicate))
+
;; now set their values
(set (make-local-variable 'parse-sexp-ignore-comments) t)
(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."
(c-update-modeline)))
+;; Connection with Emacs's electric-pair-mode
+(defun c-electric-pair-inhibit-predicate (char)
+ "Return t to inhibit the insertion of a second copy of CHAR.
+
+At the time of call, point is just after the newly inserted CHAR.
+
+When CHAR is \", t will be returned unless the \" is marked with
+a string fence syntax-table text property. For other characters,
+the default value of `electric-pair-inhibit-predicate' is called
+and its value returned.
+
+This function is the appropriate value of
+`electric-pair-inhibit-predicate' for CC Mode modes, which mark
+invalid strings with such a syntax table text property on the
+opening \" and the next unescaped end of line."
+ (if (eq char ?\")
+ (not (equal (get-text-property (1- (point)) 'syntax-table) '(15)))
+ (funcall (default-value 'electric-pair-inhibit-predicate) char)))
+
+
;; Support for C
(defvar c-mode-syntax-table
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 8d5cdd6: Fix bug #36474, such that CC Mode quotes work properly in electric-pair-mode,
Alan Mackenzie <=