]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix kill-this-buffer's detection of minibuffer frames
authorPo Lu <luangruo@yahoo.com>
Sun, 19 May 2024 12:57:09 +0000 (12:57 +0000)
committerEshel Yaron <me@eshelyaron.com>
Thu, 23 May 2024 07:43:17 +0000 (09:43 +0200)
* lisp/menu-bar.el (kill-this-buffer): Don't test against
menu-updating-frame, because this variable is only meaningful
during menu bar updates.

(cherry picked from commit 627d60910b82d35bb5f19fa139de7878cccf082e)

lisp/menu-bar.el

index d0e30e58cb905a59106a3e2c632c03dcbba524a6..aa2939daf3544c1750fa8affd308eb88e3b3274b 100644 (file)
@@ -2233,26 +2233,29 @@ updating the menu."
         (not (window-minibuffer-p
               (frame-selected-window menu-frame))))))
 
-(defun kill-this-buffer ()     ; for the menu bar
+(defun kill-this-buffer (&optional event) ; for the menu bar
   "Kill the current buffer.
 When called in the minibuffer, get out of the minibuffer
 using `abort-recursive-edit'.
 
 This command can be reliably invoked only from the menu bar,
 otherwise it could decide to silently do nothing."
-  (interactive)
-  (cond
-   ;; Don't do anything when `menu-frame' is not alive or visible
-   ;; (Bug#8184).
-   ((not (menu-bar-menu-frame-live-and-visible-p)))
-   ((menu-bar-non-minibuffer-window-p)
-    (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))))
-   (t
-    (abort-recursive-edit))))
+  (interactive "e")
+  ;; This clossus 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)))
 
 (defun kill-this-buffer-enabled-p ()
   "Return non-nil if the `kill-this-buffer' menu item should be enabled.