]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix regression in 'kill-this-buffer' (bug#78809)
authorStephen Berman <stephen.berman@gmx.net>
Tue, 17 Jun 2025 14:08:32 +0000 (16:08 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 18 Jun 2025 08:15:07 +0000 (10:15 +0200)
This restores the ability to use 'kill-this-buffer' when a
keyboard event pops up the Global Menu.  Instead of raising an
error if the command was not called by a mouse event, an error is
now raised if it was not called from a menu or a tool bar.

* lisp/menu-bar.el (kill-this-buffer): Remove optional EVENT from
argument list and "e" code from interactive spec.  Adjust doc
string.  Use 'last-command-event' to determine if command was
called from a menu or a tool bar.  Use 'event--posn-at-point' in
test for frame.

* lisp/net/eudc-hotlist.el (eudc-hotlist-quit-edit):
* lisp/net/eudc.el (eudc-display-records, eudc-query-form):
* lisp/vc/pcvs.el (cvs-mode-map): Replace uses of
'kill-this-buffer' by 'kill-current-buffer'.

(cherry picked from commit 79e50ddb9ca8b9fd3c60ba324758e84d0b535e66)

lisp/menu-bar.el
lisp/net/eudc-hotlist.el
lisp/net/eudc.el
lisp/vc/pcvs.el

index e231b125025f0e7e39fe5e7d55f760c2ed1c4186..8e9b9b1103872885bd6540070f8ac3a96003ef13 100644 (file)
@@ -2192,31 +2192,34 @@ updating the menu."
         (not (window-minibuffer-p
               (frame-selected-window menu-frame))))))
 
-(defun kill-this-buffer (&optional event) ; for the menu bar
+(defun kill-this-buffer ()
   "Kill the current buffer.
 When called in the minibuffer, get out of the minibuffer
 using `abort-recursive-edit'.
 
-This command must be bound to a mouse event, and can be reliably
-invoked only from the menu bar, otherwise it could decide to silently
-do nothing or signal an error.  Use `kill-current-buffer' if you
-need to invoke a similar command from keyboard."
-  (interactive "e")
+This command can be invoked only from a menu or a tool bar.  If you want
+to invoke a similar command with `M-x', use `kill-current-buffer'."
+  (interactive)
   ;; This colossus of a conditional is necessary to account for the wide
   ;; variety of this command's callers.
-  (if (let* ((window (or (and event (event-start event)
-                              (posn-window (event-start event)))
-                         last-event-frame
-                         (selected-frame)))
-             (frame (if (framep window) window
-                      (window-frame window))))
-        (not (window-minibuffer-p (frame-selected-window frame))))
-      (progn (kill-buffer (current-buffer))
-             ;; Also close the current window if `menu-bar-close-window' is
-             ;; set.
-             (when menu-bar-close-window
-               (ignore-errors (delete-window))))
-    (abort-recursive-edit)))
+  (if (let ((lce last-command-event))
+        (eq (if (atom lce)              ; Selected menu item.
+                lce
+              (car lce))                ; Clicked tool bar icon.
+            'kill-buffer))
+      (if (let* ((window (or (posn-window (event--posn-at-point))
+                             last-event-frame
+                            (selected-frame)))
+                (frame (if (framep window) window
+                         (window-frame window))))
+           (not (window-minibuffer-p (frame-selected-window frame))))
+         (progn (kill-buffer (current-buffer))
+                ;; Also close the current window if
+                ;; `menu-bar-close-window' is set.
+                (when menu-bar-close-window
+                  (ignore-errors (delete-window))))
+        (abort-recursive-edit))
+    (error "This command must be called from a menu or a tool bar")))
 
 (defun kill-this-buffer-enabled-p ()
   "Return non-nil if the `kill-this-buffer' menu item should be enabled.
index 144e7dba3c5a58390c10ca78ffcd723c6ecab572..f11a179a02c219aba3c0bfbbe9b5c4648b5fb38e 100644 (file)
@@ -128,7 +128,7 @@ These are the special commands of this mode:\\<eudc-hotlist-mode-map>
     (setq eudc-server-hotlist (nreverse hotlist))
     (eudc-install-menu)
     (eudc-save-options)
-    (kill-this-buffer)))
+    (kill-current-buffer)))
 
 (defun eudc-hotlist-select-server ()
   "Select the server at point as the current server."
index 1852bd137da70c15a22dacbcacab9c0542a3ca07..2e02e932234e0d0df95d5b74b5356622dff2ae8e 100644 (file)
@@ -571,7 +571,7 @@ otherwise they are formatted according to `eudc-user-attribute-names-alist'."
        (widget-insert " ")
        (widget-create 'push-button
                       :notify (lambda (&rest _ignore)
-                                (kill-this-buffer))
+                                (kill-current-buffer))
                       "Quit")
        (eudc-mode)
        (widget-setup)
@@ -1096,7 +1096,7 @@ queries the server for the existing fields and displays a corresponding form."
     (widget-insert " ")
     (widget-create 'push-button
                   :notify (lambda (&rest _ignore)
-                            (kill-this-buffer))
+                            (kill-current-buffer))
                   "Quit")
     (goto-char pt)
     (use-local-map widget-keymap)
index 2297d0a432dec3876eba4fda000ac37a0ef592d4..b5dd3bf1ce6a7dd063349f07239ce7bb33c66309 100644 (file)
   "?"              #'cvs-help
   "h"              #'cvs-help
   "q"              #'cvs-bury-buffer
-  "z"              #'kill-this-buffer
+  "z"              #'kill-current-buffer
   "F"              #'cvs-mode-set-flags
   "!"              #'cvs-mode-force-command
   "C-c C-c"        #'cvs-mode-kill-process