GNU bug report logs - #71277
30.0.50; last-prefix-arg lost when universal-argument used

Previous Next

Package: emacs;

Reported by: Sean Whitton <spwhitton <at> spwhitton.name>

Date: Thu, 30 May 2024 11:48:02 UTC

Severity: normal

Found in version 30.0.50

Done: Sean Whitton <spwhitton <at> spwhitton.name>

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 71277 in the body.
You can then email your comments to 71277 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#71277; Package emacs. (Thu, 30 May 2024 11:48:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Sean Whitton <spwhitton <at> spwhitton.name>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 30 May 2024 11:48:02 GMT) Full text and rfc822 format available.

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

From: Sean Whitton <spwhitton <at> spwhitton.name>
To: bug-gnu-emacs <at> gnu.org
Subject: 30.0.50; last-prefix-arg lost when universal-argument used
Date: Thu, 30 May 2024 12:47:29 +0100
Hello,

Consider

    (defun counter ()
      (interactive)
      (when (eq last-command this-command)
	(setq current-prefix-arg
	      (+ (prefix-numeric-value current-prefix-arg)
		 (prefix-numeric-value last-prefix-arg))))
      (message "%s!" (prefix-numeric-value current-prefix-arg)))
    (global-set-key "\M-." #'counter)

If you type M-. M-. M-. then you see "3!" as expected.

Similarly if you type "C-u M-. M-. M-." then you see "6!".

However, if you type "M-. M-. C-u M-." then you get "5!".

Unlses something is wrong with my arithmetic, this is not correct.
You should get "6!" after the third example too.
The use of C-u clobbers last-prefix-arg, basically.

I believe this will fix it:

-- >8 --
Subject: [PATCH] universal-argument--preserve: Preserve last-prefix-arg

* lisp/simple.el (universal-argument--preserve): Set
current-prefix-arg to last-prefix-arg in order to preserve
last-prefix-arg, too.
---
 lisp/simple.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 44197c3189a..76fb81c9df5 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5414,7 +5414,8 @@ universal-argument--description
 (add-hook 'prefix-command-preserve-state-hook
           #'universal-argument--preserve)
 (defun universal-argument--preserve ()
-  (setq prefix-arg current-prefix-arg))
+  (setq prefix-arg current-prefix-arg)
+  (setq current-prefix-arg last-prefix-arg))
 
 (defvar universal-argument-map
   (let ((map (make-sparse-keymap))
-- 
Sean Whitton




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#71277; Package emacs. (Thu, 30 May 2024 12:16:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Sean Whitton <spwhitton <at> spwhitton.name>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 71277 <at> debbugs.gnu.org
Subject: Re: bug#71277: 30.0.50;
 last-prefix-arg lost when universal-argument used
Date: Thu, 30 May 2024 15:14:26 +0300
> Date: Thu, 30 May 2024 12:47:29 +0100
> From:  Sean Whitton via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
>     (defun counter ()
>       (interactive)
>       (when (eq last-command this-command)
> 	(setq current-prefix-arg
> 	      (+ (prefix-numeric-value current-prefix-arg)
> 		 (prefix-numeric-value last-prefix-arg))))
>       (message "%s!" (prefix-numeric-value current-prefix-arg)))
>     (global-set-key "\M-." #'counter)
> 
> If you type M-. M-. M-. then you see "3!" as expected.
> 
> Similarly if you type "C-u M-. M-. M-." then you see "6!".
> 
> However, if you type "M-. M-. C-u M-." then you get "5!".
> 
> Unlses something is wrong with my arithmetic, this is not correct.
> You should get "6!" after the third example too.
> The use of C-u clobbers last-prefix-arg, basically.
> 
> I believe this will fix it:

Thanks, I'm adding Stefan to this discussion.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#71277; Package emacs. (Thu, 30 May 2024 14:43:01 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 71277 <at> debbugs.gnu.org, Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#71277: 30.0.50; last-prefix-arg lost when
 universal-argument used
Date: Thu, 30 May 2024 10:42:29 -0400
>> Unlses something is wrong with my arithmetic, this is not correct.
>> You should get "6!" after the third example too.
>> The use of C-u clobbers last-prefix-arg, basically.
>> 
>> I believe this will fix it:
>
> Thanks, I'm adding Stefan to this discussion.

Hmm... I didn't know about `last-prefix-arg`.
[ I'm not sure I like the idea of such a variable, but
  well... it's there.  ]
The patch looks fine to me, thank you.


        Stefan





Reply sent to Sean Whitton <spwhitton <at> spwhitton.name>:
You have taken responsibility. (Thu, 30 May 2024 15:32:01 GMT) Full text and rfc822 format available.

Notification sent to Sean Whitton <spwhitton <at> spwhitton.name>:
bug acknowledged by developer. (Thu, 30 May 2024 15:32:02 GMT) Full text and rfc822 format available.

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

From: Sean Whitton <spwhitton <at> spwhitton.name>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>, 71277-done <at> debbugs.gnu.org
Subject: Re: bug#71277: 30.0.50; last-prefix-arg lost when
 universal-argument used
Date: Thu, 30 May 2024 16:31:23 +0100
Hello,

On Thu 30 May 2024 at 10:42am -04, Stefan Monnier wrote:

>>> Unlses something is wrong with my arithmetic, this is not correct.
>>> You should get "6!" after the third example too.
>>> The use of C-u clobbers last-prefix-arg, basically.
>>>
>>> I believe this will fix it:
>>
>> Thanks, I'm adding Stefan to this discussion.
>
> Hmm... I didn't know about `last-prefix-arg`.
> [ I'm not sure I like the idea of such a variable, but
>   well... it's there.  ]
> The patch looks fine to me, thank you.

Installed, thanks for the review.

-- 
Sean Whitton




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

This bug report was last modified 356 days ago.

Previous Next


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