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.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 14000 in the body.
You can then email your comments to 14000 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#14000
; Package
emacs
.
(Tue, 19 Mar 2013 19:56:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Carsten Bormann <cabo <at> tzi.org>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Tue, 19 Mar 2013 19:56:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
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))))))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#14000
; Package
emacs
.
(Tue, 26 Mar 2013 02:44:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 14000 <at> debbugs.gnu.org (full text, mbox):
> In electric-pair-mode, I type "(("
> I get "(()"
> I should get "(())"
> Fix below.
Actually, it's not a bug but a feature. There's no way to know for sure
when pairing is desired and when it's not, and as an electric-pair user
I prefer electric-pair to err on the conservative side.
This said, it would be nice to also accommodate users with different
usage patterns. If you look at the many other pairing packages, they
show a whole bunch of slightly different behaviors, it would be nice to
try and see how we can "merge" them.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#14000
; Package
emacs
.
(Tue, 26 Mar 2013 07:30:03 GMT)
Full text and
rfc822 format available.
Message #11 received at 14000 <at> debbugs.gnu.org (full text, mbox):
On Mar 26, 2013, at 03:41, Stefan Monnier <monnier <at> iro.umontreal.ca> wrote:
>> In electric-pair-mode, I type "(("
>> I get "(()"
>> I should get "(())"
>> Fix below.
>
> Actually, it's not a bug but a feature. There's no way to know for sure
> when pairing is desired and when it's not, and as an electric-pair user
> I prefer electric-pair to err on the conservative side.
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.
> This said, it would be nice to also accommodate users with different
> usage patterns. If you look at the many other pairing packages, they
> show a whole bunch of slightly different behaviors, it would be nice to
> try and see how we can "merge" them.
I haven't done the work of surveying pairing packages.
I just happened to pick up electric-pair-mode from a specific package (I forget which), and since it is a global thing, it immediately started affecting all my buffers. It is nice enough, so I kept it on.
But the behavior I was fixing here is seriously jarring (as in *always* wrong) in my usage.
Grüße, Carsten
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#14000
; Package
emacs
.
(Tue, 26 Mar 2013 13:22:01 GMT)
Full text and
rfc822 format available.
Message #14 received at 14000 <at> debbugs.gnu.org (full text, mbox):
> But if you live in a world of paired parentheses (and I
> thought Emacs-Lispers were!)
Mostly, yes.
> you want to add them in pairs, always.
No, not at all. Some people do, but my guess would be that they are a minority.
Probably most if not all who live in a world of paired parens have tried
behavior such as electric pairing, but I'd guess that relatively few who tried
it have stayed with it.
Perhaps it's a bit like the use of the so-called "structured" editors that were
pushed by some in the 1980s: they pretty much forced you to only perform actions
that kept things well-formed, always - like filling out forms.
Real users hated them, for the most part. What they wanted was instead the
typical best-of-both-worlds behavior that Emacs offered: you can do anything at
all, but you can also easily ask the editor to check text for well-formedness
etc. IOW, check on-demand, not preformed or forced form.
Not that electric pairing prevents you from deleting parens, so they are no
longer necessarily paired (that would really be like those structured editors),
but the analogy is not too off-base.
Personally, I use `show-paren-mode' (and `blink-matching-paren'). But I don't
program in C etc., and I suppose that the language used might make some
difference wrt preference.
Wrt right parens, some Lisp dialects (e.g. Franz Lisp) have allowed you to use
`]' to act as a sufficient number of `)' to reach an even number (balance). For
quick interactive evaluation it could sometimes be handy.
E.g. (setq foo '((a) (((b (c d].
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#14000
; Package
emacs
.
(Tue, 26 Mar 2013 13:35:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 14000 <at> debbugs.gnu.org (full text, mbox):
On Mar 26, 2013, at 14:18, "Drew Adams" <drew.adams <at> oracle.com> wrote:
> Some people do, but my guess would be that they are a minority.
Well, the majority is then going to keep electric-pair-mode off, and will not be concerned by this bugfix?
My bug report was about the behavior when it's on.
Apparently then, someone already has made the decision that they want the parentheses in pairs.
Wanting them in pairs, but not when they happen to be nested touching on the left, is hard to follow for me.
But, as Stefan points out, there may indeed be people who actually want that, hence a preference setting within electric-pair-mode may be the right thing here.
Grüße, Carsten
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#14000
; Package
emacs
.
(Tue, 26 Mar 2013 14:24:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 14000 <at> debbugs.gnu.org (full text, mbox):
> > Some people do, but my guess would be that they are a minority.
>
> Well, the majority is then going to keep electric-pair-mode
> off, and will not be concerned by this bugfix?
Yes, my reply was only wrt the lines I quoted - nothing about the bug itself.
Mine was an OT comment on the notion that Lispers generally prefer electric
pairing (I doubt it). And it's only a guess on my part wrt the majority. And
it really doesn't matter whether something is majority or minority.
I just wanted to respond to the assumption that if you are an Emacs Lisper then
"you want to add them in pairs, always." That's too strong, IMO.
> My bug report was about the behavior when it's on.
> Apparently then, someone already has made the decision that
> they want the parentheses in pairs.
Yes.
> Wanting them in pairs, but not when they happen to be nested
> touching on the left, is hard to follow for me.
> But, as Stefan points out, there may indeed be people who
> actually want that, hence a preference setting within
> electric-pair-mode may be the right thing here.
A preference setting would be good, IMO. Emacs is (should be), above _all_
else, easily user-extensible and customizable. By all means, make it easy to
choose, and make users aware of the easy-to-make choices.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#14000
; Package
emacs
.
(Tue, 26 Mar 2013 16:52:01 GMT)
Full text and
rfc822 format available.
Message #23 received at 14000 <at> debbugs.gnu.org (full text, mbox):
> ... adding a preference.
Yes, that's the intention.
Stefan
Reply sent
to
Stefan Monnier <monnier <at> IRO.UMontreal.CA>
:
You have taken responsibility.
(Mon, 01 Apr 2013 13:33:04 GMT)
Full text and
rfc822 format available.
Notification sent
to
Carsten Bormann <cabo <at> tzi.org>
:
bug acknowledged by developer.
(Mon, 01 Apr 2013 13:33:07 GMT)
Full text and
rfc822 format available.
Message #28 received at 14000-done <at> debbugs.gnu.org (full text, mbox):
> 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 ()
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Tue, 30 Apr 2013 11:24:03 GMT)
Full text and
rfc822 format available.
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.