summaryrefslogtreecommitdiff
path: root/lisp/progmodes/cc-mode.el
diff options
context:
space:
mode:
authorJim Porter <jporterbugs@gmail.com>2021-11-06 01:21:35 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2021-11-06 01:21:35 +0100
commitb811ad15beeb4b96acb9d83b3a5770ef9f5fe172 (patch)
treebde4af0a51b414ddd5850289b8875aa07201aa6d /lisp/progmodes/cc-mode.el
parentcfd4d45f1164fb86bdad306ed0d532150a88f7e7 (diff)
downloademacs-b811ad15beeb4b96acb9d83b3a5770ef9f5fe172.tar.gz
emacs-b811ad15beeb4b96acb9d83b3a5770ef9f5fe172.tar.bz2
emacs-b811ad15beeb4b96acb9d83b3a5770ef9f5fe172.zip
Improve behavior of 'electric-pair-mode' in 'cc-mode'
* lisp/progmodes/cc-mode.el (c-electric-pair-inhibit-predicate): Inhibit insertion of paired quote in fewer cases. * test/lisp/electric-tests.el (define-electric-pair-test): Add 'c-mode' to list of modes to test by default (bug#50538). This ensures that quotes are paired correctly within comments, allows for insertion of quote pairs immediately before another quote, and allows inserting quote pairs within a string (thus splitting the string in two).
Diffstat (limited to 'lisp/progmodes/cc-mode.el')
-rw-r--r--lisp/progmodes/cc-mode.el19
1 files changed, 13 insertions, 6 deletions
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index ee5872d761a..f9435c9ceee 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -2636,17 +2636,24 @@ This function is called from `c-common-init', once per mode initialization."
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.
+When CHAR is \" and not within a comment, t will be returned if
+the quotes on the current line are already balanced (i.e. if the
+last \" is not marked with a string fence syntax-table text
+property). For other cases, 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)) 'c-fl-syn-tab) '(15)))
+ (if (and (eq char ?\")
+ (not (memq (cadr (c-semi-pp-to-literal (1- (point)))) '(c c++))))
+ (let ((last-quote (save-match-data
+ (save-excursion
+ (goto-char (c-point 'eoll))
+ (search-backward "\"")))))
+ (not (equal (c-get-char-property last-quote 'c-fl-syn-tab) '(15))))
(funcall (default-value 'electric-pair-inhibit-predicate) char)))