all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Sean Whitton via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 71277@debbugs.gnu.org
Subject: bug#71277: 30.0.50; last-prefix-arg lost when universal-argument used
Date: Thu, 30 May 2024 12:47:29 +0100	[thread overview]
Message-ID: <87bk4nv7vy.fsf@zephyr.silentflame.com> (raw)

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





             reply	other threads:[~2024-05-30 11:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-30 11:47 Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-05-30 12:14 ` bug#71277: 30.0.50; last-prefix-arg lost when universal-argument used 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bk4nv7vy.fsf@zephyr.silentflame.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=71277@debbugs.gnu.org \
    --cc=spwhitton@spwhitton.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.