(HAVE_SELECT, HAVE_TIMEVAL): Definitions deleted.
[bpt/emacs.git] / lisp / menu-bar.el
CommitLineData
235aa29b
ER
1;;; menu-bar.el --- define a default menu bar.
2
3;; Author: RMS
b7f66977 4;; Keywords: internal
235aa29b 5
f8c25f1b 6;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
1db87953
RS
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation; either version 2, or (at your option)
13;; any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs; see the file COPYING. If not, write to
22;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
235aa29b 24;;; Code:
1db87953 25
b132f2b1
RM
26;; Don't clobber an existing menu-bar keymap, to preserve any menu-bar key
27;; definitions made in loaddefs.el.
28(or (lookup-key global-map [menu-bar])
29 (define-key global-map [menu-bar] (make-sparse-keymap "menu-bar")))
22390f50 30(defvar menu-bar-help-menu (make-sparse-keymap "Help"))
ffbdd83d
RS
31
32;; Force Help item to come last, after the major mode's own items.
da183f87 33(setq menu-bar-final-items '(help))
ffbdd83d 34
da183f87 35(define-key global-map [menu-bar help] (cons "Help" menu-bar-help-menu))
ffbdd83d
RS
36(defvar menu-bar-search-menu (make-sparse-keymap "Search"))
37(define-key global-map [menu-bar search] (cons "Search" menu-bar-search-menu))
22390f50 38(defvar menu-bar-edit-menu (make-sparse-keymap "Edit"))
40954111 39(define-key global-map [menu-bar edit] (cons "Edit" menu-bar-edit-menu))
ffbdd83d
RS
40(defvar menu-bar-tools-menu (make-sparse-keymap "Tools"))
41(define-key global-map [menu-bar tools] (cons "Tools" menu-bar-tools-menu))
42(defvar menu-bar-files-menu (make-sparse-keymap "Files"))
43(define-key global-map [menu-bar files] (cons "Files" menu-bar-files-menu))
9bb8e471 44\f
9dcdc43d
RS
45(defvar vc-menu-map (make-sparse-keymap "Version Control"))
46
e1726722 47(define-key menu-bar-tools-menu [calendar] '("Display Calendar" . calendar))
ffbdd83d
RS
48(define-key menu-bar-tools-menu [rmail] '("Read Mail" . rmail))
49(define-key menu-bar-tools-menu [gnus] '("Read Net News" . gnus))
50
51(define-key menu-bar-tools-menu [separator-vc]
52 '("--"))
53
54(define-key menu-bar-tools-menu [vc-menu]
55 (cons "Version Control" vc-menu-map))
9bb8e471 56
ffbdd83d 57(define-key menu-bar-tools-menu [separator-compare]
9bb8e471
RS
58 '("--"))
59
ffbdd83d 60(define-key menu-bar-tools-menu [epatch]
080ac1ac 61 '("Apply Patch" . menu-bar-epatch-menu))
ffbdd83d 62(define-key menu-bar-tools-menu [ediff-merge]
5438ecd3 63 '("Merge" . menu-bar-ediff-merge-menu))
ffbdd83d 64(define-key menu-bar-tools-menu [ediff]
40a8cde1 65 '("Compare" . menu-bar-ediff-menu))
9bb8e471 66
ffbdd83d 67(define-key menu-bar-tools-menu [separator-print]
9bb8e471
RS
68 '("--"))
69
ffbdd83d
RS
70(put 'print-region 'menu-enable 'mark-active)
71(put 'ps-print-region-with-faces 'menu-enable 'mark-active)
72
73(define-key menu-bar-tools-menu [ps-print-region]
74 '("Postscript Print Region" . ps-print-region-with-faces))
75(define-key menu-bar-tools-menu [ps-print-buffer]
76 '("Postscript Print Buffer" . ps-print-buffer-with-faces))
77(define-key menu-bar-tools-menu [print-region]
78 '("Print Region" . print-region))
79(define-key menu-bar-tools-menu [print-buffer]
80 '("Print Buffer" . print-buffer))
81\f
82(define-key menu-bar-files-menu [exit-emacs]
83 '("Exit Emacs" . save-buffers-kill-emacs))
84
85(define-key menu-bar-files-menu [separator-exit]
86 '("--"))
87
88(define-key menu-bar-files-menu [one-window]
89 '("One Window" . delete-other-windows))
90
91(define-key menu-bar-files-menu [split-window]
92 '("Split Window" . split-window-vertically))
9bb8e471 93
ca1a9692
RS
94(if (fboundp 'delete-frame)
95 (progn
ffbdd83d 96 (define-key menu-bar-files-menu [delete-frame]
ca1a9692 97 '("Delete Frame" . delete-frame))
ffbdd83d
RS
98 (define-key menu-bar-files-menu [make-frame-on-display]
99 '("Open New Display..." . make-frame-on-display))
100 (define-key menu-bar-files-menu [make-frame]
ca1a9692 101 '("Make New Frame" . make-frame))))
9bb8e471 102
ffbdd83d 103(define-key menu-bar-files-menu [separator-buffers]
9bb8e471
RS
104 '("--"))
105
ffbdd83d
RS
106(define-key menu-bar-files-menu [kill-buffer]
107 '("Kill Current Buffer" . kill-this-buffer))
108(define-key menu-bar-files-menu [insert-file]
df4d8e01 109 '("Insert File" . insert-file))
ffbdd83d 110(define-key menu-bar-files-menu [revert-buffer]
2f1139a4 111 '("Revert Buffer" . revert-buffer))
ffbdd83d 112(define-key menu-bar-files-menu [write-file]
2f1139a4 113 '("Save Buffer As..." . write-file))
ffbdd83d
RS
114(define-key menu-bar-files-menu [save-buffer] '("Save Buffer" . save-buffer))
115(define-key menu-bar-files-menu [dired] '("Open Directory..." . dired))
116(define-key menu-bar-files-menu [open-file] '("Open File..." . find-file))
40a8cde1
RS
117
118;; This is just one element of the ediff menu--the first.
119(define-key menu-bar-ediff-menu [window]
120 '("This Window And Next Window" . compare-windows))
9bb8e471 121\f
ffbdd83d
RS
122(defun nonincremental-search-forward (string)
123 "Read a string and search for it nonincrementally."
124 (interactive "sSearch for string: ")
125 (if (equal string "")
126 (search-forward (car search-ring))
127 (isearch-update-ring string nil)
128 (search-forward string)))
129
130(defun nonincremental-search-backward (string)
131 "Read a string and search backward for it nonincrementally."
132 (interactive "sSearch for string: ")
133 (if (equal string "")
134 (search-backward (car search-ring))
135 (isearch-update-ring string nil)
136 (search-backward string)))
137
138(defun nonincremental-re-search-forward (string)
139 "Read a regular expression and search for it nonincrementally."
140 (interactive "sSearch for regexp: ")
141 (if (equal string "")
142 (re-search-forward (car regexp-search-ring))
143 (isearch-update-ring string t)
144 (re-search-forward string)))
145
146(defun nonincremental-re-search-backward (string)
147 "Read a regular expression and search backward for it nonincrementally."
148 (interactive "sSearch for regexp: ")
149 (if (equal string "")
150 (re-search-backward (car regexp-search-ring))
151 (isearch-update-ring string t)
152 (re-search-backward string)))
153
154(defun noninteractive-repeat-search-forward ()
155 "Search forward for the previous search string."
156 (interactive)
157 (search-forward (car search-ring)))
158
159(defun noninteractive-repeat-search-backward ()
160 "Search backward for the previous search string."
161 (interactive)
162 (search-backward (car search-ring)))
163
164(defun noninteractive-repeat-re-search-forward ()
165 "Search forward for the previous regular expression."
166 (interactive)
167 (re-search-forward (car regexp-search-ring)))
168
169(defun noninteractive-repeat-re-search-backward ()
170 "Search backward for the previous regular expression."
171 (interactive)
172 (re-search-backward (car regexp-search-ring)))
173
174(define-key menu-bar-search-menu [query-replace]
33aa8946 175 '("Query Replace" . query-replace))
ffbdd83d
RS
176(define-key menu-bar-search-menu [find-tag]
177 '("Find Tag" . find-tag))
178(put 'find-tag 'menu-enable 'tags-table-list)
179(define-key menu-bar-search-menu [bookmark]
180 '("Bookmarks" . menu-bar-bookmark-map))
181
182(define-key menu-bar-search-menu [separator-search]
183 '("--"))
184
185(define-key menu-bar-search-menu [nonincremental-repeat-re-search-back]
186 '("Repeat Regexp Backwards" . nonincremental-repeat-re-search-backward))
187(define-key menu-bar-search-menu [nonincremental-repeat-search-back]
188 '("Repeat Backwards" . nonincremental-repeat-search-backward))
189(define-key menu-bar-search-menu [nonincremental-repeat-re-search-fwd]
190 '("Repeat Regexp" . nonincremental-repeat-re-search-forward))
191(define-key menu-bar-search-menu [nonincremental-repeat-search-fwd]
192 '("Repeat Search" . nonincremental-repeat-search-forward))
193
194(define-key menu-bar-search-menu [separator-repeat]
9bb8e471
RS
195 '("--"))
196
ffbdd83d
RS
197(define-key menu-bar-search-menu [re-search-back]
198 '("Regexp Search Backwards" . nonincremental-re-search-backward))
199(define-key menu-bar-search-menu [search-back]
200 '("Search Backwards" . nonincremental-search-backward))
201(define-key menu-bar-search-menu [re-search-fwd]
202 '("Regexp Search" . nonincremental-re-search-forward))
203(define-key menu-bar-search-menu [search-fwd]
204 '("Search" . nonincremental-search-forward))
205\f
9bb8e471
RS
206(define-key menu-bar-edit-menu [spell] '("Spell" . ispell-menu-map))
207(define-key menu-bar-edit-menu [fill] '("Fill" . fill-region))
6507ffb1 208(define-key menu-bar-edit-menu [props] '("Text Properties" . facemenu-menu))
9bb8e471
RS
209
210(define-key menu-bar-edit-menu [separator-edit]
211 '("--"))
212
213(define-key menu-bar-edit-menu [clear] '("Clear" . delete-region))
3dd92899 214
e1726722 215(define-key menu-bar-edit-menu [paste] '("Paste Most Recent" . yank))
3dd92899
KH
216
217(defvar yank-menu (cons "Select Yank" nil))
218(fset 'yank-menu (cons 'keymap yank-menu))
219(define-key menu-bar-edit-menu [select-paste] '("Select and Paste" . yank-menu))
4c0317b1 220(define-key menu-bar-edit-menu [copy] '("Copy" . menu-bar-kill-ring-save))
057d49d1
RS
221(define-key menu-bar-edit-menu [cut] '("Cut" . kill-region))
222(define-key menu-bar-edit-menu [undo] '("Undo" . undo))
223
4c0317b1
RS
224(defun menu-bar-kill-ring-save (beg end)
225 (interactive "r")
226 (if (mouse-region-match)
227 (message "Select a region with the mouse does `copy' automatically")
228 (kill-ring-save beg end)))
229
057d49d1
RS
230(put 'fill-region 'menu-enable 'mark-active)
231(put 'kill-region 'menu-enable 'mark-active)
4c0317b1 232(put 'menu-bar-kill-ring-save 'menu-enable 'mark-active)
057d49d1 233(put 'yank 'menu-enable '(x-selection-exists-p))
3dd92899 234(put 'yank-menu 'menu-enable '(cdr yank-menu))
4c0317b1
RS
235(put 'delete-region 'menu-enable '(and mark-active
236 (not (mouse-region-match))))
057d49d1
RS
237(put 'undo 'menu-enable '(if (eq last-command 'undo)
238 pending-undo-list
239 (consp buffer-undo-list)))
3a841b0b 240(put 'query-replace 'menu-enable '(not buffer-read-only))
db774a16 241
9e18f0a0
RS
242(autoload 'ispell-menu-map "ispell" nil t 'keymap)
243
f9cf0be2 244;; These are alternative definitions for the cut, paste and copy
4c0317b1 245;; menu items. Use them if your system expects these to use the clipboard.
f9cf0be2 246
f9cf0be2
RS
247(put 'clipboard-kill-region 'menu-enable 'mark-active)
248(put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
249(put 'clipboard-yank 'menu-enable
250 '(or (x-selection-exists-p) (x-selection-exists-p 'CLIPBOARD)))
251
252(defun clipboard-yank ()
253 "Reinsert the last stretch of killed text, or the clipboard contents."
254 (interactive)
255 (let ((x-select-enable-clipboard t))
256 (yank)))
257
258(defun clipboard-kill-ring-save (beg end)
259 "Copy region to kill ring, and save in the X clipboard."
260 (interactive "r")
261 (let ((x-select-enable-clipboard t))
262 (kill-ring-save beg end)))
263
264(defun clipboard-kill-region (beg end)
265 "Kill the region, and save it in the X clipboard."
266 (interactive "r")
267 (let ((x-select-enable-clipboard t))
268 (kill-region beg end)))
269
270(defun menu-bar-enable-clipboard ()
5cbdeb30
RS
271 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
272Do the same for the keys of the same name."
f9cf0be2 273 (interactive)
5754d7f2
RS
274 ;; We can't use constant list structure here because it becomes pure,
275 ;; and because it gets modified with cache data.
276 (define-key menu-bar-edit-menu [paste]
277 (cons "Paste" 'clipboard-yank))
278 (define-key menu-bar-edit-menu [copy]
279 (cons "Copy" 'clipboard-kill-ring-save))
280 (define-key menu-bar-edit-menu [cut]
5cbdeb30
RS
281 (cons "Cut" 'clipboard-kill-region))
282
283 (define-key global-map [f20] 'clipboard-kill-region)
284 (define-key global-map [f16] 'clipboard-kill-ring-save)
285 (define-key global-map [f18] 'clipboard-yank)
286 ;; X11R6 versions
287 (define-key global-map [cut] 'clipboard-kill-region)
288 (define-key global-map [copy] 'clipboard-kill-ring-save)
289 (define-key global-map [paste] 'clipboard-yank))
f9cf0be2 290\f
efb166ff
RS
291(define-key menu-bar-help-menu [emacs-version]
292 '("Show Version" . emacs-version))
48433a65
RS
293(define-key menu-bar-help-menu [report-emacs-bug]
294 '("Send Bug Report" . report-emacs-bug))
ca9b40a1 295(define-key menu-bar-help-menu [emacs-tutorial]
db774a16 296 '("Emacs Tutorial" . help-with-tutorial))
2f1139a4
RS
297(define-key menu-bar-help-menu [man] '("Man..." . manual-entry))
298(define-key menu-bar-help-menu [describe-variable]
299 '("Describe Variable..." . describe-variable))
300(define-key menu-bar-help-menu [describe-function]
301 '("Describe Function..." . describe-function))
302(define-key menu-bar-help-menu [describe-key]
303 '("Describe Key..." . describe-key))
304(define-key menu-bar-help-menu [list-keybindings]
305 '("List Keybindings" . describe-bindings))
306(define-key menu-bar-help-menu [command-apropos]
307 '("Command Apropos..." . command-apropos))
308(define-key menu-bar-help-menu [describe-mode]
309 '("Describe Mode" . describe-mode))
e1726722 310(define-key menu-bar-help-menu [info] '("Browse Manuals" . info))
889560ed 311(define-key menu-bar-help-menu [emacs-faq] '("Emacs FAQ" . view-emacs-FAQ))
2f1139a4 312(define-key menu-bar-help-menu [emacs-news] '("Emacs News" . view-emacs-news))
889560ed 313
db774a16
RS
314(defun kill-this-buffer () ; for the menubar
315 "Kills the current buffer."
316 (interactive)
317 (kill-buffer (current-buffer)))
318
2f1139a4
RS
319(defun kill-this-buffer-enabled-p ()
320 (let ((count 0)
321 (buffers (buffer-list)))
322 (while buffers
323 (or (string-match "^ " (buffer-name (car buffers)))
324 (setq count (1+ count)))
325 (setq buffers (cdr buffers)))
326 (> count 1)))
327
db774a16 328(put 'save-buffer 'menu-enable '(buffer-modified-p))
da183f87
RS
329(put 'revert-buffer 'menu-enable
330 '(or revert-buffer-function revert-buffer-insert-file-contents-function
331 (and (buffer-file-name)
660fa562
RM
332 (or (buffer-modified-p)
333 (not (verify-visited-file-modtime (current-buffer)))))))
a0213a97
RS
334;; Permit deleting frame if it would leave a visible or iconified frame.
335(put 'delete-frame 'menu-enable
336 '(let ((frames (frame-list))
337 (count 0))
338 (while frames
339 (if (cdr (assq 'visibility (frame-parameters (car frames))))
340 (setq count (1+ count)))
341 (setq frames (cdr frames)))
342 (> count 1)))
2f1139a4
RS
343(put 'kill-this-buffer 'menu-enable '(kill-this-buffer-enabled-p))
344
db774a16
RS
345(put 'advertised-undo 'menu-enable
346 '(and (not (eq t buffer-undo-list))
347 (if (eq last-command 'undo)
2f1139a4
RS
348 (and (boundp 'pending-undo-list)
349 pending-undo-list)
350 buffer-undo-list)))
2877eac2 351
c3e1d435 352(defvar yank-menu-length 20
3dd92899
KH
353 "*Maximum length to display in the yank-menu.")
354
355(defun menu-bar-update-yank-menu (string old)
356 (let ((front (car (cdr yank-menu)))
357 (menu-string (if (<= (length string) yank-menu-length)
358 string
c3e1d435
RS
359 (concat
360 (substring string 0 (/ yank-menu-length 2))
361 "..."
362 (substring string (- (/ yank-menu-length 2)))))))
3dd92899
KH
363 ;; If we're supposed to be extending an existing string, and that
364 ;; string really is at the front of the menu, then update it in place.
365 (if (and old (or (eq old (car front))
366 (string= old (car front))))
dfabc98f 367 (progn
3dd92899
KH
368 (setcar front string)
369 (setcar (cdr front) menu-string))
370 (setcdr yank-menu
371 (cons
372 (cons string (cons menu-string 'menu-bar-select-yank))
373 (cdr yank-menu)))))
374 (if (> (length (cdr yank-menu)) kill-ring-max)
375 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
376
377(defun menu-bar-select-yank ()
378 (interactive "*")
379 (push-mark (point))
380 (insert last-command-event))
40954111 381\f
09642d97
RS
382(define-key global-map [menu-bar buffer] '("Buffers" . menu-bar-buffers))
383
384(defalias 'menu-bar-buffers (make-sparse-keymap "Buffers"))
40954111 385
40954111
RS
386(defvar buffers-menu-max-size 10
387 "*Maximum number of entries which may appear on the Buffers menu.
388If this is 10, then only the ten most-recently-selected buffers are shown.
389If this is nil, then all buffers are shown.
390A large number or nil slows down menu responsiveness.")
391
d0690d12
RS
392(defvar list-buffers-directory nil)
393
08e8171f
RS
394(defvar menu-bar-update-buffers-maxbuf)
395
09642d97
RS
396(defun menu-bar-select-buffer ()
397 (interactive)
398 (switch-to-buffer last-command-event))
399
400(defun menu-bar-select-frame ()
401 (interactive)
402 (make-frame-visible last-command-event)
403 (raise-frame last-command-event)
404 (select-frame last-command-event))
405
c171b42f
RS
406(defun menu-bar-update-buffers-1 (elt)
407 (cons (format
08e8171f 408 (format "%%%ds %%s%%s %%s" menu-bar-update-buffers-maxbuf)
c171b42f
RS
409 (cdr elt)
410 (if (buffer-modified-p (car elt))
411 "*" " ")
412 (save-excursion
413 (set-buffer (car elt))
414 (if buffer-read-only "%" " "))
415 (let ((file
416 (or (buffer-file-name (car elt))
417 (save-excursion
418 (set-buffer (car elt))
419 list-buffers-directory)
420 "")))
421 (setq file (or (file-name-directory file)
422 ""))
423 (if (> (length file) 20)
424 (setq file (concat "..." (substring file -17))))
425 file))
426 (car elt)))
427
09642d97 428(defun menu-bar-update-buffers ()
29397c58 429 ;; If user discards the Buffers item, play along.
4d587a6c 430 (and (lookup-key (current-global-map) [menu-bar buffer])
29397c58
RS
431 (frame-or-buffer-changed-p)
432 (let ((buffers (buffer-list))
433 (frames (frame-list))
434 buffers-menu frames-menu)
435 ;; If requested, list only the N most recently selected buffers.
436 (if (and (integerp buffers-menu-max-size)
437 (> buffers-menu-max-size 1))
438 (if (> (length buffers) buffers-menu-max-size)
439 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
440
441 ;; Make the menu of buffers proper.
442 (setq buffers-menu
443 (cons "Select Buffer"
c171b42f
RS
444 (let* ((buffer-list
445 (mapcar 'list buffers))
446 tail
08e8171f 447 (menu-bar-update-buffers-maxbuf 0)
c171b42f
RS
448 (maxlen 0)
449 alist
450 head)
451 ;; Put into each element of buffer-list
452 ;; the name for actual display,
453 ;; perhaps truncated in the middle.
454 (setq tail buffer-list)
455 (while tail
456 (let ((name (buffer-name (car (car tail)))))
457 (setcdr (car tail)
458 (if (> (length name) 27)
459 (concat (substring name 0 12)
460 "..."
461 (substring name -12))
462 name)))
463 (setq tail (cdr tail)))
464 ;; Compute the maximum length of any name.
465 (setq tail buffer-list)
29397c58 466 (while tail
c171b42f 467 (or (eq ?\ (aref (cdr (car tail)) 0))
08e8171f
RS
468 (setq menu-bar-update-buffers-maxbuf
469 (max menu-bar-update-buffers-maxbuf
c171b42f 470 (length (cdr (car tail))))))
29397c58 471 (setq tail (cdr tail)))
c171b42f
RS
472 ;; Set ALIST to an alist of the form
473 ;; ITEM-STRING . BUFFER
474 (setq tail buffer-list)
29397c58
RS
475 (while tail
476 (let ((elt (car tail)))
c171b42f 477 (or (eq ?\ (aref (cdr elt) 0))
29397c58 478 (setq alist (cons
c171b42f 479 (menu-bar-update-buffers-1 elt)
29397c58
RS
480 alist)))
481 (and alist (> (length (car (car alist))) maxlen)
482 (setq maxlen (length (car (car alist))))))
483 (setq tail (cdr tail)))
484 (setq alist (nreverse alist))
485 (nconc (mapcar '(lambda (pair)
486 ;; This is somewhat risque, to use
487 ;; the buffer name itself as the event
488 ;; type to define, but it works.
489 ;; It would not work to use the buffer
490 ;; since a buffer as an event has its
491 ;; own meaning.
492 (nconc (list (buffer-name (cdr pair))
493 (car pair)
494 (cons nil nil))
495 'menu-bar-select-buffer))
496 alist)
497 (list
096ec7e7 498 (cons
29397c58
RS
499 'list-buffers
500 (cons
501 (concat (make-string (max (- (/ maxlen 2) 8) 0)
502 ?\ )
503 "List All Buffers")
504 'list-buffers)))))))
505
506
507 ;; Make a Frames menu if we have more than one frame.
508 (if (cdr frames)
509 (setq frames-menu
510 (cons "Select Frame"
511 (mapcar '(lambda (frame)
512 (nconc (list frame
513 (cdr (assq 'name
514 (frame-parameters frame)))
515 (cons nil nil))
516 'menu-bar-select-frame))
517 frames))))
518 (if buffers-menu
519 (setq buffers-menu (cons 'keymap buffers-menu)))
520 (if frames-menu
521 (setq frames-menu (cons 'keymap frames-menu)))
4d587a6c 522 (define-key (current-global-map) [menu-bar buffer]
29397c58
RS
523 (cons "Buffers"
524 (if (and buffers-menu frames-menu)
525 (list 'keymap "Buffers and Frames"
526 (cons 'buffers (cons "Buffers" buffers-menu))
527 (cons 'frames (cons "Frames" frames-menu)))
528 (or buffers-menu frames-menu 'undefined)))))))
09642d97
RS
529
530(add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
2f1139a4 531
40954111
RS
532;; this version is too slow
533;;;(defun format-buffers-menu-line (buffer)
534;;; "Returns a string to represent the given buffer in the Buffer menu.
535;;;nil means the buffer shouldn't be listed. You can redefine this."
536;;; (if (string-match "\\` " (buffer-name buffer))
537;;; nil
538;;; (save-excursion
539;;; (set-buffer buffer)
540;;; (let ((size (buffer-size)))
541;;; (format "%s%s %-19s %6s %-15s %s"
542;;; (if (buffer-modified-p) "*" " ")
543;;; (if buffer-read-only "%" " ")
544;;; (buffer-name)
545;;; size
546;;; mode-name
547;;; (or (buffer-file-name) ""))))))
548\f
7b7d6615
RS
549(defvar menu-bar-mode nil)
550
057d49d1 551(defun menu-bar-mode (flag)
dfd29450 552 "Toggle display of a menu bar on each frame.
057d49d1
RS
553This command applies to all frames that exist and frames to be
554created in the future.
555With a numeric argument, if the argument is negative,
dfd29450 556turn off menu bars; otherwise, turn on menu bars."
dad8e392 557 (interactive "P")
dad8e392 558
7b7d6615
RS
559 ;; Make menu-bar-mode and default-frame-alist consistent.
560 (let ((default (assq 'menu-bar-lines default-frame-alist)))
561 (if default
562 (setq menu-bar-mode (not (eq (cdr default) 0)))
563 (setq default-frame-alist
564 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
565 default-frame-alist))))
566
567 ;; Toggle or set the mode, according to FLAG.
568 (setq menu-bar-mode (if (null flag) (not menu-bar-mode)
569 (> (prefix-numeric-value flag) 0)))
570
571 ;; Apply it to default-frame-alist.
572 (let ((parameter (assq 'menu-bar-lines default-frame-alist)))
573 (if (consp parameter)
574 (setcdr parameter (if menu-bar-mode 1 0))
575 (setq default-frame-alist
576 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
577 default-frame-alist))))
578
579 ;; Apply it to existing frames.
580 (let ((frames (frame-list)))
581 (while frames
582 (let ((height (cdr (assq 'height (frame-parameters (car frames))))))
583 (modify-frame-parameters (car frames)
584 (list (cons 'menu-bar-lines
585 (if menu-bar-mode 1 0))))
586 (modify-frame-parameters (car frames)
587 (list (cons 'height height))))
588 (setq frames (cdr frames)))))
1db87953 589
bffa5d4d
RS
590(provide 'menu-bar)
591
235aa29b 592;;; menu-bar.el ends here