emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Re: Algorithm in electric-pair--unbalanced-strings-p unsuitable


From: Alan Mackenzie
Subject: [PATCH] Re: Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode
Date: Thu, 4 Jul 2019 16:58:46 +0000
User-agent: Mutt/1.10.1 (2018-07-13)

Hello, Joãa.

On Wed, Jul 03, 2019 at 14:31:58 +0100, João Távora wrote:
[ .... ]

> If [you] don't agree, find a small enough solution that fixes e-p-m,
> propose it here,  then find a consensus that overrides my opinion, it
> happens all the time, won't hold it against you or anyone else, good
> luck.

Here is the entire part of the fix needed for bug #36474, that should go
into elec-pair-mode.el:


diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el
index 5fb9d751e2..ba86b55167 100644
--- a/lisp/elec-pair.el
+++ b/lisp/elec-pair.el
@@ -484,6 +484,23 @@ electric-pair-default-inhibit
       (electric-pair-inhibit-if-helps-balance char)
     (electric-pair-conservative-inhibit char)))
 
+(defun electric-pair-cc-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
+`electric-pair-default-inhibit' 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)))
+    (electric-pair-default-inhibit char)))
+
 (defun electric-pair-post-self-insert-function ()
   (let* ((pos (and electric-pair-mode (electric--after-char-pos)))
          (skip-whitespace-info))


You will note that it is the mere addition of a function, not used
anywhere else in elec-pair.el, so cannot possibly damage its
functionality.  If I was being perverse, I could even put this function
in cc-mode.el instead, though this would not be good practice.

This new function has been tested, and it works.

Now, will you please just decide to install this patch.  If you like, I
can write a commit message for it.

> --
> João Távora

-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]