GNU bug report logs - #14000
24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses

Previous Next

Package: emacs;

Reported by: Carsten Bormann <cabo <at> tzi.org>

Date: Tue, 19 Mar 2013 19:56:02 UTC

Severity: normal

Found in version 24.3.50

Done: Stefan Monnier <monnier <at> IRO.UMontreal.CA>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#14000: closed (24.3.50; electric-pair-post-self-insert-function
 does not handle nested parentheses)
Date: Mon, 01 Apr 2013 13:33:04 +0000
[Message part 1 (text/plain, inline)]
Your message dated Mon, 01 Apr 2013 09:28:56 -0400
with message-id <jwvvc86z8g6.fsf-monnier+emacs <at> gnu.org>
and subject line Re: bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses
has caused the debbugs.gnu.org bug report #14000,
regarding 24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
14000: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=14000
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Carsten Bormann <cabo <at> tzi.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3.50;
	electric-pair-post-self-insert-function does not handle nested
	parentheses
Date: Tue, 19 Mar 2013 18:59:53 +0100
In electric-pair-mode, I type "(("

I get "(()"

I should get "(())"

Fix below.

In GNU Emacs 24.3.50.1 (x86_64-apple-darwin, NS apple-appkit-1038.36)
 of 2013-03-19 on bob.porkrind.org
Bzr revision: 112090 dgutov <at> yandex.ru-20130319050649-jie5ixrjvsavih4i
Windowing system distributor `Apple', version 10.3.1187
Configured using:
 `configure --host=x86_64-apple-darwin --build=i686-apple-darwin
 --with-ns'

--- electric.el	2013-03-19 18:51:05.000000000 +0100
+++ electric-fixed.el	2013-03-19 18:55:59.000000000 +0100
@@ -354,7 +354,10 @@
                ;; I find it more often preferable not to pair when the
                ;; same char is next.
                (eq last-command-event (char-after))
-               (eq last-command-event (char-before (1- (point))))
+               (and
+                (eq last-command-event (char-before (1- (point))))
+                (not (eq syntax ?\())
+               )
                ;; I also find it often preferable not to pair next to a word.
                (eq (char-syntax (following-char)) ?w)))
       (save-excursion (insert closer))))))


[Message part 3 (message/rfc822, inline)]
From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Carsten Bormann <cabo <at> tzi.org>
Cc: 14000-done <at> debbugs.gnu.org
Subject: Re: bug#14000: 24.3.50;
	electric-pair-post-self-insert-function does not handle nested
	parentheses
Date: Mon, 01 Apr 2013 09:28:56 -0400
> OK, I maybe should have suggested adding a preference.
> But if you live in a world of paired parentheses (and I thought
> Emacs-Lispers were!) you want to add them in pairs, always.

I installed the patch below,


        Stefan


=== modified file 'lisp/electric.el'
--- lisp/electric.el	2013-01-01 09:11:05 +0000
+++ lisp/electric.el	2013-04-01 13:27:16 +0000
@@ -302,6 +302,26 @@
   :version "24.1"
   :type 'boolean)
 
+(defcustom electric-pair-inhibit-predicate
+  #'electric-pair-default-inhibit
+  "Predicate to prevent insertion of a matching pair.
+The function is called with a single char (the opening char just inserted).
+If it returns non-nil, then `electric-pair-mode' will not insert a matching
+closer."
+  :type '(choice
+          (const :tag "Default" electric-pair-default-inhibit)
+          (const :tag "Always pair" ignore)
+          function))
+
+(defun electric-pair-default-inhibit (char)
+  (or
+   ;; I find it more often preferable not to pair when the
+   ;; same char is next.
+   (eq char (char-after))
+   (eq char (char-before (1- (point))))
+   ;; I also find it often preferable not to pair next to a word.
+   (eq (char-syntax (following-char)) ?w)))
+
 (defun electric-pair-syntax (command-event)
   (and electric-pair-mode
        (let ((x (assq command-event electric-pair-pairs)))
@@ -351,12 +371,7 @@
      ;; Insert matching pair.
      ((not (or (not (memq syntax `(?\( ?\" ?\$)))
                overwrite-mode
-               ;; I find it more often preferable not to pair when the
-               ;; same char is next.
-               (eq last-command-event (char-after))
-               (eq last-command-event (char-before (1- (point))))
-               ;; I also find it often preferable not to pair next to a word.
-               (eq (char-syntax (following-char)) ?w)))
+               (funcall electric-pair-inhibit-predicate last-command-event)))
       (save-excursion (insert closer))))))
 
 (defun electric-pair-will-use-region ()



This bug report was last modified 12 years and 56 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.