changeset 8316:abf26f5c67e4

(menu-bar-update-buffers): If Buffers item is gone, don't bring it back.
author Richard M. Stallman <rms@gnu.org>
date Sun, 24 Jul 1994 05:34:16 +0000
parents 8921d0012bd5
children c59be9428778
files lisp/menu-bar.el
diffstat 1 files changed, 92 insertions(+), 90 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/menu-bar.el	Sun Jul 24 04:18:02 1994 +0000
+++ b/lisp/menu-bar.el	Sun Jul 24 05:34:16 1994 +0000
@@ -286,100 +286,102 @@
   (select-frame last-command-event))
 
 (defun menu-bar-update-buffers ()
-  (if (frame-or-buffer-changed-p)
-      (let ((buffers (buffer-list))
-	    (frames (frame-list))
-	    buffers-menu frames-menu)
-	;; If requested, list only the N most recently selected buffers.
-	(if (and (integerp buffers-menu-max-size)
-		 (> buffers-menu-max-size 1))
-	    (if (> (length buffers) buffers-menu-max-size)
-		(setcdr (nthcdr buffers-menu-max-size buffers) nil)))
+  ;; If user discards the Buffers item, play along.
+  (and (lookup-key global-map [menu-bar buffer])
+       (frame-or-buffer-changed-p)
+       (let ((buffers (buffer-list))
+	     (frames (frame-list))
+	     buffers-menu frames-menu)
+	 ;; If requested, list only the N most recently selected buffers.
+	 (if (and (integerp buffers-menu-max-size)
+		  (> buffers-menu-max-size 1))
+	     (if (> (length buffers) buffers-menu-max-size)
+		 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
 
-	;; Make the menu of buffers proper.
-	(setq buffers-menu
-	      (cons "Select Buffer"
-		    (let ((tail buffers)
-			  (maxbuf 0)
-			  (maxlen 0)
-			  alist
-			  head)
-		      (while tail
-			(or (eq ?\ (aref (buffer-name (car tail)) 0))
-			    (setq maxbuf
-				  (max maxbuf
-				       (length (buffer-name (car tail))))))
-			(setq tail (cdr tail)))
-		      (setq tail buffers)
-		      (while tail
-			(let ((elt (car tail)))
-			  (or (eq ?\ (aref (buffer-name elt) 0))
-			      (setq alist (cons
-					   (cons
-					    (format
-					     (format "%%%ds  %%s%%s  %%s"
-						     maxbuf)
-					     (buffer-name elt)
-					     (if (buffer-modified-p elt)
-						 "*" " ")
-					     (save-excursion
-					       (set-buffer elt)
-					       (if buffer-read-only "%" " "))
-					     (or (buffer-file-name elt)
-						 (save-excursion
-						   (set-buffer elt)
-						   list-buffers-directory)
-						 ""))
-					    elt)
-					   alist)))
-			  (and alist (> (length (car (car alist))) maxlen)
-			       (setq maxlen (length (car (car alist))))))
-			(setq tail (cdr tail)))
-		      (setq alist (nreverse alist))
-		      (nconc (mapcar '(lambda (pair)
-					;; This is somewhat risque, to use
-					;; the buffer name itself as the event
-					;; type to define, but it works.
-					;; It would not work to use the buffer
-					;; since a buffer as an event has its
-					;; own meaning.
-					(nconc (list (buffer-name (cdr pair))
-						     (car pair)
-						     (cons nil nil))
-					       'menu-bar-select-buffer))
-				     alist)
-			     (list
-			      (cons
-			       'list-buffers
+	 ;; Make the menu of buffers proper.
+	 (setq buffers-menu
+	       (cons "Select Buffer"
+		     (let ((tail buffers)
+			   (maxbuf 0)
+			   (maxlen 0)
+			   alist
+			   head)
+		       (while tail
+			 (or (eq ?\ (aref (buffer-name (car tail)) 0))
+			     (setq maxbuf
+				   (max maxbuf
+					(length (buffer-name (car tail))))))
+			 (setq tail (cdr tail)))
+		       (setq tail buffers)
+		       (while tail
+			 (let ((elt (car tail)))
+			   (or (eq ?\ (aref (buffer-name elt) 0))
+			       (setq alist (cons
+					    (cons
+					     (format
+					      (format "%%%ds  %%s%%s  %%s"
+						      maxbuf)
+					      (buffer-name elt)
+					      (if (buffer-modified-p elt)
+						  "*" " ")
+					      (save-excursion
+						(set-buffer elt)
+						(if buffer-read-only "%" " "))
+					      (or (buffer-file-name elt)
+						  (save-excursion
+						    (set-buffer elt)
+						    list-buffers-directory)
+						  ""))
+					     elt)
+					    alist)))
+			   (and alist (> (length (car (car alist))) maxlen)
+				(setq maxlen (length (car (car alist))))))
+			 (setq tail (cdr tail)))
+		       (setq alist (nreverse alist))
+		       (nconc (mapcar '(lambda (pair)
+					 ;; This is somewhat risque, to use
+					 ;; the buffer name itself as the event
+					 ;; type to define, but it works.
+					 ;; It would not work to use the buffer
+					 ;; since a buffer as an event has its
+					 ;; own meaning.
+					 (nconc (list (buffer-name (cdr pair))
+						      (car pair)
+						      (cons nil nil))
+						'menu-bar-select-buffer))
+				      alist)
+			      (list
 			       (cons
-				(concat (make-string (max (- (/ maxlen 2) 8) 0)
-						     ?\ )
-					"List All Buffers")
-				'list-buffers)))))))
+				'list-buffers
+				(cons
+				 (concat (make-string (max (- (/ maxlen 2) 8) 0)
+						      ?\ )
+					 "List All Buffers")
+				 'list-buffers)))))))
 
 
-	;; Make a Frames menu if we have more than one frame.
-	(if (cdr frames)
-	    (setq frames-menu
-		  (cons "Select Frame"
-			(mapcar '(lambda (frame)
-				   (nconc (list frame
-						(cdr (assq 'name
-							   (frame-parameters frame)))
-						(cons nil nil))
-					  'menu-bar-select-frame))
-				frames))))
-	(if buffers-menu
-	    (setq buffers-menu (cons 'keymap buffers-menu)))
-	(if frames-menu
-	    (setq frames-menu (cons 'keymap frames-menu)))
-	(define-key global-map [menu-bar buffer]
-	  (cons "Buffers"
-		(if (and buffers-menu frames-menu)
-		    (list 'keymap "Buffers and Frames"
-			  (cons 'buffers (cons "Buffers" buffers-menu))
-			  (cons 'frames (cons "Frames" frames-menu)))
-		  (or buffers-menu frames-menu 'undefined)))))))
+	 ;; Make a Frames menu if we have more than one frame.
+	 (if (cdr frames)
+	     (setq frames-menu
+		   (cons "Select Frame"
+			 (mapcar '(lambda (frame)
+				    (nconc (list frame
+						 (cdr (assq 'name
+							    (frame-parameters frame)))
+						 (cons nil nil))
+					   'menu-bar-select-frame))
+				 frames))))
+	 (if buffers-menu
+	     (setq buffers-menu (cons 'keymap buffers-menu)))
+	 (if frames-menu
+	     (setq frames-menu (cons 'keymap frames-menu)))
+	 (define-key global-map [menu-bar buffer]
+	   (cons "Buffers"
+		 (if (and buffers-menu frames-menu)
+		     (list 'keymap "Buffers and Frames"
+			   (cons 'buffers (cons "Buffers" buffers-menu))
+			   (cons 'frames (cons "Frames" frames-menu)))
+		   (or buffers-menu frames-menu 'undefined)))))))
 
 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)