all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#71277: 30.0.50; last-prefix-arg lost when universal-argument used
@ 2024-05-30 11:47 Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-05-30 12:14 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-05-30 11:47 UTC (permalink / raw)
  To: 71277

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





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

* bug#71277: 30.0.50; last-prefix-arg lost when universal-argument used
  2024-05-30 11:47 bug#71277: 30.0.50; last-prefix-arg lost when universal-argument used Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-05-30 12:14 ` Eli Zaretskii
  2024-05-30 14:42   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2024-05-30 12:14 UTC (permalink / raw)
  To: Sean Whitton, Stefan Monnier; +Cc: 71277

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





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

* bug#71277: 30.0.50; last-prefix-arg lost when universal-argument used
  2024-05-30 12:14 ` Eli Zaretskii
@ 2024-05-30 14:42   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-05-30 15:31     ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-05-30 14:42 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 71277, Sean Whitton

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






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

* bug#71277: 30.0.50; last-prefix-arg lost when universal-argument used
  2024-05-30 14:42   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-05-30 15:31     ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 4+ messages in thread
From: Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-05-30 15:31 UTC (permalink / raw)
  To: Stefan Monnier, 71277-done

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





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

end of thread, other threads:[~2024-05-30 15:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-30 11:47 bug#71277: 30.0.50; last-prefix-arg lost when universal-argument used Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-30 12:14 ` Eli Zaretskii
2024-05-30 14:42   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-30 15:31     ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors

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.