GNU bug report logs -
#14000
24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses
Previous Next
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
[Message part 1 (text/plain, inline)]
Your bug report
#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses
which was filed against the emacs package, has been closed.
The explanation is attached below, along with your original report.
If you require more details, please reply to 14000 <at> debbugs.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)]
> 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 ()
[Message part 3 (message/rfc822, inline)]
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))))))
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.