aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Rudalics <[email protected]>2011-05-29 15:11:23 -0400
committerChong Yidong <[email protected]>2011-05-29 15:11:23 -0400
commit159daf87947f31a0e7f82769f1a3861500ea08e0 (patch)
treec573a1788a2a203f719661cd499b292b6564cdba
parent56dd2d861f0beab1be2b12900fda133e48bd60fa (diff)
* menu-bar.el (kill-this-buffer-enabled-p): Avoid looping over entire buffer list (Bug#8184).
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/menu-bar.el19
2 files changed, 16 insertions, 8 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6c21786bce..c54e48ef52 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2011-05-29 Martin Rudalics <[email protected]>
+
+ * menu-bar.el (kill-this-buffer-enabled-p): Avoid looping over
+ entire buffer list (Bug#8184).
+
2011-05-29 Chong Yidong <[email protected]>
* image.el (imagemagick-types-inhibit)
diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el
index 8a33381b61..343a9c6dd0 100644
--- a/lisp/menu-bar.el
+++ b/lisp/menu-bar.el
@@ -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))