GNU bug report logs - #33840
electric-pair-mode breaks self-insert-command

Previous Next

Package: emacs;

Reported by: Alan Mackenzie <acm <at> muc.de>

Date: Sun, 23 Dec 2018 02:46:01 UTC

Severity: normal

Tags: wontfix

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

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 33840 in the body.
You can then email your comments to 33840 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#33840; Package emacs. (Sun, 23 Dec 2018 02:46:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Alan Mackenzie <acm <at> muc.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 23 Dec 2018 02:46:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: bug-gnu-emacs <at> gnu.org
Subject: electric-pair-mode breaks self-insert-command
Date: Sun, 23 Dec 2018 02:38:41 +0000
Hello, Emacs.

In the master branch, put the following into *scratch* and evaluate it:

    (defun s-i-c ()
      (interactive)
      (self-insert-command 1))
    (local-set-key "(" 's-i-c))

On typing "(", it will be seen that the self-insert-command does its
job, correctly entering "(" into *scratch*.

Now do M-x electric-pair-mode.

If you now type "(", self-insert-command wrongly enters "()" into the
buffer.  This is a bug, and is the root cause of bug #33794.

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33840; Package emacs. (Tue, 09 Jul 2019 22:40:01 GMT) Full text and rfc822 format available.

Message #8 received at 33840 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 33840 <at> debbugs.gnu.org
Subject: Re: bug#33840: electric-pair-mode breaks self-insert-command
Date: Wed, 10 Jul 2019 00:39:00 +0200
Alan Mackenzie <acm <at> muc.de> writes:

> In the master branch, put the following into *scratch* and evaluate it:
>
>     (defun s-i-c ()
>       (interactive)
>       (self-insert-command 1))
>     (local-set-key "(" 's-i-c))
>
> On typing "(", it will be seen that the self-insert-command does its
> job, correctly entering "(" into *scratch*.
>
> Now do M-x electric-pair-mode.
>
> If you now type "(", self-insert-command wrongly enters "()" into the
> buffer.  This is a bug, and is the root cause of bug #33794.

I must be misunderstanding something -- isn't the entire point of
electric-pair-mode that it inserts the corresponding parenthesis when
self-insert-command is called on one of the magical characters?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33840; Package emacs. (Wed, 10 Jul 2019 09:41:01 GMT) Full text and rfc822 format available.

Message #11 received at 33840 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 33840 <at> debbugs.gnu.org
Subject: Re: bug#33840: electric-pair-mode breaks self-insert-command
Date: Wed, 10 Jul 2019 09:39:56 +0000
Hello, Lars.

On Wed, Jul 10, 2019 at 00:39:00 +0200, Lars Ingebrigtsen wrote:
> Alan Mackenzie <acm <at> muc.de> writes:

> > In the master branch, put the following into *scratch* and evaluate it:

> >     (defun s-i-c ()
> >       (interactive)
> >       (self-insert-command 1))
> >     (local-set-key "(" 's-i-c))

> > On typing "(", it will be seen that the self-insert-command does its
> > job, correctly entering "(" into *scratch*.

> > Now do M-x electric-pair-mode.

> > If you now type "(", self-insert-command wrongly enters "()" into the
> > buffer.  This is a bug, and is the root cause of bug #33794.

> I must be misunderstanding something -- isn't the entire point of
> electric-pair-mode that it inserts the corresponding parenthesis when
> self-insert-command is called on one of the magical characters?

But the entire point of (self-insert-command 1) is to insert exactly one
copy of what was just typed.  With electric-pair-mode enabled, it no
longer does this; it does something else instead.

self-insert-command is a primitive, and it shouldn't be modified to do
other things.  Instead these other things should be done alongside the
primitive, or after it.

Similarly, you would not modify + such that (+ 2 3) => 6, even if you had
a use case where you wanted this strange arithmetic.

Because of this change to self-insert-command, other uses of it (other
than when bound directly to a key) fail.  This happened in bug #33794
where this change to self-insert-command broke c-electric-brace.  This
has since been worked around by other means.

Being realistic, I now don't really expect this bug to be fixed.  It
would cost too much.  But if you are going to close it, please mark it as
"won't fix" and _not_ "not a bug".

Thanks!

> -- 
> (domestic pets only, the antidote for overdose, milk.)
>    bloggy blog: http://lars.ingebrigtsen.no

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33840; Package emacs. (Wed, 10 Jul 2019 11:35:02 GMT) Full text and rfc822 format available.

Message #14 received at 33840 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 33840 <at> debbugs.gnu.org
Subject: Re: bug#33840: electric-pair-mode breaks self-insert-command
Date: Wed, 10 Jul 2019 13:34:26 +0200
Alan Mackenzie <acm <at> muc.de> writes:

> self-insert-command is a primitive, and it shouldn't be modified to do
> other things.  Instead these other things should be done alongside the
> primitive, or after it.
>
> Similarly, you would not modify + such that (+ 2 3) => 6, even if you had
> a use case where you wanted this strange arithmetic.

I agree that modifying primitives is really confusing and should be
avoided, but I don't think self-insert-command is ... very primitive.
:-)  I mean, look at the doc string:

---

(self-insert-command N &optional C)

  Probably introduced at or before Emacs version 22.1.

Insert the character you type.
Whichever character C you type to run this command is inserted.
The numeric prefix argument N says how many times to repeat the insertion.
Before insertion, ‘expand-abbrev’ is executed if the inserted character does
not have word syntax and the previous character in the buffer does.
After insertion, ‘internal-auto-fill’ is called if
‘auto-fill-function’ is non-nil and if the ‘auto-fill-chars’ table has
a non-nil value for the inserted character.  At the end, it runs
‘post-self-insert-hook’.

---

There's a lot of stuff going on there!  It sounds more like a "don't use
this function from code unless you want unpredictable things to happen"
thing to me...

> Being realistic, I now don't really expect this bug to be fixed.  It
> would cost too much.  But if you are going to close it, please mark it as
> "won't fix" and _not_ "not a bug".

Will do.  :-)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) wontfix. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Wed, 10 Jul 2019 11:35:03 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 33840 <at> debbugs.gnu.org and Alan Mackenzie <acm <at> muc.de> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Wed, 10 Jul 2019 11:35:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33840; Package emacs. (Wed, 10 Jul 2019 17:09:01 GMT) Full text and rfc822 format available.

Message #21 received at 33840 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Alan Mackenzie <acm <at> muc.de>, 33840 <at> debbugs.gnu.org
Subject: Re: bug#33840: electric-pair-mode breaks self-insert-command
Date: Wed, 10 Jul 2019 13:08:24 -0400
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> Alan Mackenzie <acm <at> muc.de> writes:
>
>> self-insert-command is a primitive, and it shouldn't be modified to do
>> other things.  Instead these other things should be done alongside the
>> primitive, or after it.
>>
>> Similarly, you would not modify + such that (+ 2 3) => 6, even if you had
>> a use case where you wanted this strange arithmetic.
>
> I agree that modifying primitives is really confusing and should be
> avoided, but I don't think self-insert-command is ... very primitive.
> :-)  I mean, look at the doc string:
[...]
> There's a lot of stuff going on there!  It sounds more like a "don't use
> this function from code unless you want unpredictable things to happen"
> thing to me...
>
>> Being realistic, I now don't really expect this bug to be fixed.  It
>> would cost too much.

FWIW, I don't think using a documented hook should be considered
"modifying" the primitive which calls it (unlike say, using advice).
But electric-pair-mode's current implementation seems to involve a
complicated dance of inserting and deleting and inserting characters
again, so I think there is some room for improvement.  Perhaps by using
something other than post-self-insert-hook.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 08 Aug 2019 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 234 days ago.

Previous Next


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