From: Po Lu Date: Sun, 19 May 2024 12:57:09 +0000 (+0000) Subject: Fix kill-this-buffer's detection of minibuffer frames X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d0b8aa1bb4c7d0b2d299dff00e1501f745dd50e9;p=emacs.git Fix kill-this-buffer's detection of minibuffer frames * 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) --- diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index d0e30e58cb9..aa2939daf35 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -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.