changeset 7234:b642c8ba8ea3

Don't call menu-bar-mode here. (menu-bar-update-buffers): Check whether frames ad buffers have actually changed; if not, do nothing.
author Richard M. Stallman <rms@gnu.org>
date Sat, 30 Apr 1994 21:18:03 +0000
parents da74d15b3571
children d4db2cd4f7c7
files lisp/menu-bar.el
diffstat 1 files changed, 96 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/menu-bar.el	Sat Apr 30 20:40:34 1994 +0000
+++ b/lisp/menu-bar.el	Sat Apr 30 21:18:03 1994 +0000
@@ -254,99 +254,108 @@
   (raise-frame last-command-event)
   (select-frame last-command-event))
 
+(defvar menu-bar-update-buffers-last-buffers nil)
+(defvar menu-bar-update-buffers-last-frames nil)
+
 (defun menu-bar-update-buffers ()
   (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 (and (equal buffers menu-bar-update-buffers-last-buffers)
+	     (equal frames menu-bar-update-buffers-last-frames))
+	nil
+      (setq menu-bar-update-buffers-last-buffers buffers)
+      (setq menu-bar-update-buffers-last-frames frames)
+      ;; 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)))
-		      (if (not (string-match "^ "
-					     (buffer-name elt)))
-			  (setq alist (cons
+      ;; 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)))
+			(if (not (string-match "^ "
+					       (buffer-name elt)))
+			    (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
 				       (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
-				     (cons
-				      (concat (make-string (max (- (/ maxlen
-								      2)
-								   8)
-								0) ?\ )
-					      "List All Buffers")
-				      'list-buffers)))))))
+					(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 (frame-list))
-	(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))
-			    (frame-list)))))
-    (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 frame)
+	  (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))
+			      frame))))
+      (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)
 
@@ -400,10 +409,6 @@
 					    (if menu-bar-mode 1 0))))
        (setq frames (cdr frames))))))
 
-;; Make frames created from now on have a menu bar.
-(if window-system
-    (menu-bar-mode t))
-
 (provide 'menu-bar)
 
 ;;; menu-bar.el ends here