GNU bug report logs - #27470
26.0.50; this-command-keys and interactive input

Previous Next

Package: emacs;

Reported by: Michael Heerdegen <michael_heerdegen <at> web.de>

Date: Sat, 24 Jun 2017 06:00:02 UTC

Severity: minor

Tags: patch

Found in version 26.0.50

Done: Eli Zaretskii <eliz <at> gnu.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 27470 in the body.
You can then email your comments to 27470 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#27470; Package emacs. (Sat, 24 Jun 2017 06:00:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Michael Heerdegen <michael_heerdegen <at> web.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 24 Jun 2017 06:00:03 GMT) Full text and rfc822 format available.

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

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.0.50; this-command-keys and interactive input
Date: Sat, 24 Jun 2017 07:58:47 +0200
Hello,

Evaluate this:

(defun test (arg)
  (interactive (list (read-from-minibuffer "Input: ")))
  (message "%S" (cons this-command (this-command-keys)))
  arg)

(global-set-key [f12] #'test)

where f12 stands for some random key sequence.

Hit f12 and give any input.  I get the following message:

(test . "^M")

I would expect (test . f12).

Obviously, `this-command-keys' returns the key confirming the input
instead of the key that has invoked the command.  This contradicts the
descriptions in the documentation (docstring and manual).  The docs only
mention an exception when a command calls `read-key-sequence', but this
is not the case here.  FWIW, I would prefer fixing this over changing
the docs.


Thanks,

Michael.


In GNU Emacs 26.0.50 (build 3, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2017-06-19 built on drachen
Repository revision: 1b75af59b305867c89271905be72a05d06a4eff4
Windowing system distributor 'The X.Org Foundation', version 11.0.11903000
System Description:	Debian GNU/Linux 9.0 (stretch)





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27470; Package emacs. (Sat, 24 Jun 2017 07:02:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: 27470 <at> debbugs.gnu.org
Subject: Re: bug#27470: 26.0.50; this-command-keys and interactive input
Date: Sat, 24 Jun 2017 10:01:17 +0300
> From: Michael Heerdegen <michael_heerdegen <at> web.de>
> Date: Sat, 24 Jun 2017 07:58:47 +0200
> 
> (defun test (arg)
>   (interactive (list (read-from-minibuffer "Input: ")))
>   (message "%S" (cons this-command (this-command-keys)))
>   arg)
> 
> (global-set-key [f12] #'test)
> 
> where f12 stands for some random key sequence.
> 
> Hit f12 and give any input.  I get the following message:
> 
> (test . "^M")
> 
> I would expect (test . f12).

This happens because read-from-minibuffer enters recursive-edit, and
we don't preserve this-command-keys across recursive-edit invocations.

This has been Emacs behavior since forever.

The patch below seems to fix this, but I have no idea what it could
break, given how old this behavior is.  So if we are to accept this,
I'd like to have a few people step forward and run with the change for
a month or so, to see there are no adverse effects.  We've been burnt
several times lately by changes in keyboard-input stuff that broke
subtle but very useful features.

Thanks.

diff --git a/src/minibuf.c b/src/minibuf.c
index 1bbe276..5617941 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -497,6 +497,8 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
 				  Fcons (Vminibuffer_history_position,
 					 Fcons (Vminibuffer_history_variable,
 						minibuf_save_list))))));
+  minibuf_save_list
+    = Fcons (Fthis_command_keys_vector (), minibuf_save_list);
 
   record_unwind_protect_void (read_minibuf_unwind);
   minibuf_level++;
@@ -836,6 +838,11 @@ read_minibuf_unwind (void)
   Fset_buffer (XWINDOW (window)->contents);
 
   /* Restore prompt, etc, from outer minibuffer level.  */
+  Lisp_Object key_vec = Fcar (minibuf_save_list);
+  eassert (VECTORP (key_vec));
+  this_command_key_count = XFASTINT (Flength (key_vec));
+  this_command_keys = key_vec;
+  minibuf_save_list = Fcdr (minibuf_save_list);
   minibuf_prompt = Fcar (minibuf_save_list);
   minibuf_save_list = Fcdr (minibuf_save_list);
   minibuf_prompt_width = XFASTINT (Fcar (minibuf_save_list));




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27470; Package emacs. (Sat, 24 Jun 2017 13:16:01 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: 27470 <at> debbugs.gnu.org
Subject: Re: bug#27470: 26.0.50; this-command-keys and interactive input
Date: Sat, 24 Jun 2017 09:15:04 -0400
> (defun test (arg)
>   (interactive (list (read-from-minibuffer "Input: ")))
>   (message "%S" (cons this-command (this-command-keys)))
>   arg)

Whether it's a bug or not is hard to say (the quirk is described in the
doctring).  But you can get the behavior you want with:

    (defun sm-test (arg &optional keys)
      (interactive
        (let ((keys (this-command-keys-vector)))
          (list (read-from-minibuffer "Input: ") keys)))
      (message "%S" (cons this-command keys))
      arg)


-- Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27470; Package emacs. (Sun, 25 Jun 2017 05:54:01 GMT) Full text and rfc822 format available.

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

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 27470 <at> debbugs.gnu.org
Subject: Re: bug#27470: 26.0.50; this-command-keys and interactive input
Date: Sun, 25 Jun 2017 07:53:42 +0200
Eli Zaretskii <eliz <at> gnu.org> writes:

> The patch below seems to fix this, but I have no idea what it could
> break, given how old this behavior is.

Thanks.  Solves the issue for me.  I'll keep using your patch so I'm the
first tester.


Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27470; Package emacs. (Sat, 22 Jul 2017 08:17:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: michael_heerdegen <at> web.de
Cc: 27470 <at> debbugs.gnu.org
Subject: Re: bug#27470: 26.0.50; this-command-keys and interactive input
Date: Sat, 22 Jul 2017 11:16:32 +0300
> Date: Sat, 24 Jun 2017 10:01:17 +0300
> From: Eli Zaretskii <eliz <at> gnu.org>
> Cc: 27470 <at> debbugs.gnu.org
> 
> > From: Michael Heerdegen <michael_heerdegen <at> web.de>
> > Date: Sat, 24 Jun 2017 07:58:47 +0200
> > 
> > (defun test (arg)
> >   (interactive (list (read-from-minibuffer "Input: ")))
> >   (message "%S" (cons this-command (this-command-keys)))
> >   arg)
> > 
> > (global-set-key [f12] #'test)
> > 
> > where f12 stands for some random key sequence.
> > 
> > Hit f12 and give any input.  I get the following message:
> > 
> > (test . "^M")
> > 
> > I would expect (test . f12).
> 
> This happens because read-from-minibuffer enters recursive-edit, and
> we don't preserve this-command-keys across recursive-edit invocations.
> 
> This has been Emacs behavior since forever.
> 
> The patch below seems to fix this, but I have no idea what it could
> break, given how old this behavior is.  So if we are to accept this,
> I'd like to have a few people step forward and run with the change for
> a month or so, to see there are no adverse effects.  We've been burnt
> several times lately by changes in keyboard-input stuff that broke
> subtle but very useful features.

Michael, any findings so far?  Do you recommend that we push that
change?

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27470; Package emacs. (Sun, 23 Jul 2017 15:45:01 GMT) Full text and rfc822 format available.

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

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 27470 <at> debbugs.gnu.org
Subject: Re: bug#27470: 26.0.50; this-command-keys and interactive input
Date: Sun, 23 Jul 2017 17:44:21 +0200
Eli Zaretskii <eliz <at> gnu.org> writes:

> Michael, any findings so far?

No, everything seems to be fine.

> Do you recommend that we push that change?

It solves my problem, so - yes!  But I can't judge whether it could
potentially cause any trouble.  Anyway, it's small and easily
revertible, so I see no reason to hold it back.


Thanks,

Michael.




Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Fri, 28 Jul 2017 12:43:01 GMT) Full text and rfc822 format available.

Notification sent to Michael Heerdegen <michael_heerdegen <at> web.de>:
bug acknowledged by developer. (Fri, 28 Jul 2017 12:43:02 GMT) Full text and rfc822 format available.

Message #25 received at 27470-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: 27470-done <at> debbugs.gnu.org
Subject: Re: bug#27470: 26.0.50; this-command-keys and interactive input
Date: Fri, 28 Jul 2017 15:41:46 +0300
> From: Michael Heerdegen <michael_heerdegen <at> web.de>
> Cc: 27470 <at> debbugs.gnu.org
> Date: Sun, 23 Jul 2017 17:44:21 +0200
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > Michael, any findings so far?
> 
> No, everything seems to be fine.
> 
> > Do you recommend that we push that change?
> 
> It solves my problem, so - yes!  But I can't judge whether it could
> potentially cause any trouble.  Anyway, it's small and easily
> revertible, so I see no reason to hold it back.

Pushed to master.

Thanks for testing this.




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

This bug report was last modified 7 years and 352 days ago.

Previous Next


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