progmodes/cc-engine.el (c-guess-continued-construct): Correct the
[bpt/emacs.git] / lisp / menu-bar.el
index 8a33381..437bd52 100644 (file)
@@ -1823,14 +1823,17 @@ using `abort-recursive-edit'."
     (abort-recursive-edit)))
 
 (defun kill-this-buffer-enabled-p ()
-  (let ((count 0)
-       (buffers (buffer-list)))
-    (while buffers
-      (or (string-match "^ " (buffer-name (car buffers)))
-         (setq count (1+ count)))
-      (setq buffers (cdr buffers)))
-    (or (not (menu-bar-non-minibuffer-window-p))
-       (> count 1))))
+  "Return non-nil if the `kill-this-buffer' menu item should be enabled."
+  (or (not (menu-bar-non-minibuffer-window-p))
+      (let (found-1)
+       ;; Instead of looping over entire buffer list, stop once we've
+       ;; found two "killable" buffers (Bug#8184).
+       (catch 'found-2
+         (dolist (buffer (buffer-list))
+           (unless (string-match-p "^ " (buffer-name buffer))
+             (if (not found-1)
+                 (setq found-1 t)
+               (throw 'found-2 t))))))))
 
 (put 'dired 'menu-enable '(menu-bar-non-minibuffer-window-p))
 
@@ -1974,6 +1977,10 @@ Buffers menu is regenerated."
 ;; Used to cache the menu entries for commands in the Buffers menu
 (defvar menu-bar-buffers-menu-command-entries nil)
 
+(defvar menu-bar-select-buffer-function 'switch-to-buffer
+  "Function to select the buffer chosen from the `Buffers' menu-bar menu.
+It must accept a buffer as its only required argument.")
+
 (defun menu-bar-update-buffers (&optional force)
   ;; If user discards the Buffers item, play along.
   (and (lookup-key (current-global-map) [menu-bar buffer])
@@ -2019,7 +2026,7 @@ Buffers menu is regenerated."
                                        (cons nil nil))
                                  `(lambda ()
                                      (interactive)
-                                     (switch-to-buffer ,(cdr pair))))))
+                                     (funcall menu-bar-select-buffer-function ,(cdr pair))))))
                    (list buffers-vec))))
 
         ;; Make a Frames menu if we have more than one frame.