all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#33840: electric-pair-mode breaks self-insert-command
@ 2018-12-23  2:38 Alan Mackenzie
  2019-07-09 22:39 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Mackenzie @ 2018-12-23  2:38 UTC (permalink / raw)
  To: 33840

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).





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#33840: electric-pair-mode breaks self-insert-command
  2018-12-23  2:38 bug#33840: electric-pair-mode breaks self-insert-command Alan Mackenzie
@ 2019-07-09 22:39 ` Lars Ingebrigtsen
  2019-07-10  9:39   ` Alan Mackenzie
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-09 22:39 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 33840

Alan Mackenzie <acm@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





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#33840: electric-pair-mode breaks self-insert-command
  2019-07-09 22:39 ` Lars Ingebrigtsen
@ 2019-07-10  9:39   ` Alan Mackenzie
  2019-07-10 11:34     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Mackenzie @ 2019-07-10  9:39 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 33840

Hello, Lars.

On Wed, Jul 10, 2019 at 00:39:00 +0200, Lars Ingebrigtsen wrote:
> Alan Mackenzie <acm@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).





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#33840: electric-pair-mode breaks self-insert-command
  2019-07-10  9:39   ` Alan Mackenzie
@ 2019-07-10 11:34     ` Lars Ingebrigtsen
  2019-07-10 17:08       ` Noam Postavsky
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-10 11:34 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 33840

Alan Mackenzie <acm@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





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#33840: electric-pair-mode breaks self-insert-command
  2019-07-10 11:34     ` Lars Ingebrigtsen
@ 2019-07-10 17:08       ` Noam Postavsky
  0 siblings, 0 replies; 5+ messages in thread
From: Noam Postavsky @ 2019-07-10 17:08 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Alan Mackenzie, 33840

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Alan Mackenzie <acm@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.





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-07-10 17:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-23  2:38 bug#33840: electric-pair-mode breaks self-insert-command Alan Mackenzie
2019-07-09 22:39 ` Lars Ingebrigtsen
2019-07-10  9:39   ` Alan Mackenzie
2019-07-10 11:34     ` Lars Ingebrigtsen
2019-07-10 17:08       ` Noam Postavsky

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.