* bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses
@ 2013-03-19 17:59 Carsten Bormann
2013-03-26 2:41 ` Stefan Monnier
0 siblings, 1 reply; 8+ messages in thread
From: Carsten Bormann @ 2013-03-19 17:59 UTC (permalink / raw)
To: 14000
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@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))))))
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses
2013-03-19 17:59 bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses Carsten Bormann
@ 2013-03-26 2:41 ` Stefan Monnier
2013-03-26 7:27 ` Carsten Bormann
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2013-03-26 2:41 UTC (permalink / raw)
To: Carsten Bormann; +Cc: 14000
> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses
2013-03-26 2:41 ` Stefan Monnier
@ 2013-03-26 7:27 ` Carsten Bormann
2013-03-26 13:18 ` bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nestedparentheses Drew Adams
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Carsten Bormann @ 2013-03-26 7:27 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 14000
On Mar 26, 2013, at 03:41, Stefan Monnier <monnier@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
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nestedparentheses
2013-03-26 7:27 ` Carsten Bormann
@ 2013-03-26 13:18 ` Drew Adams
2013-03-26 13:32 ` Carsten Bormann
2013-03-26 16:48 ` bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses Stefan Monnier
2013-04-01 13:28 ` Stefan Monnier
2 siblings, 1 reply; 8+ messages in thread
From: Drew Adams @ 2013-03-26 13:18 UTC (permalink / raw)
To: 'Carsten Bormann', 'Stefan Monnier'; +Cc: 14000
> 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].
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nestedparentheses
2013-03-26 13:18 ` bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nestedparentheses Drew Adams
@ 2013-03-26 13:32 ` Carsten Bormann
2013-03-26 14:20 ` Drew Adams
0 siblings, 1 reply; 8+ messages in thread
From: Carsten Bormann @ 2013-03-26 13:32 UTC (permalink / raw)
To: Drew Adams; +Cc: 14000
On Mar 26, 2013, at 14:18, "Drew Adams" <drew.adams@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
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nestedparentheses
2013-03-26 13:32 ` Carsten Bormann
@ 2013-03-26 14:20 ` Drew Adams
0 siblings, 0 replies; 8+ messages in thread
From: Drew Adams @ 2013-03-26 14:20 UTC (permalink / raw)
To: 'Carsten Bormann'; +Cc: 14000
> > 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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses
2013-03-26 7:27 ` Carsten Bormann
2013-03-26 13:18 ` bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nestedparentheses Drew Adams
@ 2013-03-26 16:48 ` Stefan Monnier
2013-04-01 13:28 ` Stefan Monnier
2 siblings, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2013-03-26 16:48 UTC (permalink / raw)
To: Carsten Bormann; +Cc: 14000
> ... adding a preference.
Yes, that's the intention.
Stefan
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses
2013-03-26 7:27 ` Carsten Bormann
2013-03-26 13:18 ` bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nestedparentheses Drew Adams
2013-03-26 16:48 ` bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses Stefan Monnier
@ 2013-04-01 13:28 ` Stefan Monnier
2 siblings, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2013-04-01 13:28 UTC (permalink / raw)
To: Carsten Bormann; +Cc: 14000-done
> 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 ()
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-04-01 13:28 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-19 17:59 bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses Carsten Bormann
2013-03-26 2:41 ` Stefan Monnier
2013-03-26 7:27 ` Carsten Bormann
2013-03-26 13:18 ` bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nestedparentheses Drew Adams
2013-03-26 13:32 ` Carsten Bormann
2013-03-26 14:20 ` Drew Adams
2013-03-26 16:48 ` bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses Stefan Monnier
2013-04-01 13:28 ` Stefan Monnier
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).