1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-26 19:18:50 +00:00

(menu-bar-update-buffers): If Buffers item is gone,

don't bring it back.
This commit is contained in:
Richard M. Stallman 1994-07-24 05:34:16 +00:00
parent 0ab39c81ae
commit 29397c5869

View File

@ -286,100 +286,102 @@ A large number or nil slows down menu responsiveness.")
(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)