From 92fa2b60c613c653ecea262a04ab8e7f3a8ff2f9 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 13 Sep 2025 11:56:15 +0300 Subject: [PATCH] Fix 'kill-region' when buffer has been changed outside of Emacs * lisp/subr.el (read-char-choice): Let-bind 'last-command' to prevent it from being overwritten by 'recursive-edit'. (Bug#79388) --- lisp/subr.el | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lisp/subr.el b/lisp/subr.el index 35bb00e0c49..da208d7063f 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3625,7 +3625,13 @@ argument INHIBIT-KEYBOARD-QUIT is ignored. However, if function is used instead (see `read-char-choice-with-read-key'), and INHIBIT-KEYBOARD-QUIT is passed to it." (if (not read-char-choice-use-read-key) - (read-char-from-minibuffer prompt chars) + ;; We are about to enter recursive-edit, which sets + ;; 'last-command'. If the callers of this function have some + ;; logic based on 'last-command's value (example: 'kill-region'), + ;; that could interfere with their logic. So we let-bind + ;; 'last-command' here to prevent that. + (let ((last-command last-command)) + (read-char-from-minibuffer prompt chars)) (read-char-choice-with-read-key prompt chars inhibit-keyboard-quit))) (defun read-char-choice-with-read-key (prompt chars &optional inhibit-keyboard-quit)