1 ;;; menu-bar.el --- define a default menu bar.
3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
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)
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.
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 the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;; Avishai Yacobi suggested some menu rearrangements.
31 (defvar buffers-menu-max-size
10
32 "*Maximum number of entries which may appear on the Buffers menu.
33 If this is 10, then only the ten most-recently-selected buffers are shown.
34 If this is nil, then all buffers are shown.
35 A large number or nil slows down menu responsiveness.")
37 ;; Don't clobber an existing menu-bar keymap, to preserve any menu-bar key
38 ;; definitions made in loaddefs.el.
39 (or (lookup-key global-map
[menu-bar
])
40 (define-key global-map
[menu-bar
] (make-sparse-keymap "menu-bar")))
41 (defvar menu-bar-help-menu
(make-sparse-keymap "Help"))
43 ;; Force Help item to come last, after the major mode's own items.
44 ;; The symbol used to be called `help', but that gets confused with the
46 (setq menu-bar-final-items
'(help-menu))
48 (define-key global-map
[menu-bar help-menu
] (cons "Help" menu-bar-help-menu
))
49 (defvar menu-bar-search-menu
(make-sparse-keymap "Search"))
50 (define-key global-map
[menu-bar search
] (cons "Search" menu-bar-search-menu
))
51 (defvar menu-bar-edit-menu
(make-sparse-keymap "Edit"))
52 (define-key global-map
[menu-bar edit
] (cons "Edit" menu-bar-edit-menu
))
53 (defvar menu-bar-tools-menu
(make-sparse-keymap "Tools"))
54 (define-key global-map
[menu-bar tools
] (cons "Tools" menu-bar-tools-menu
))
55 (defvar menu-bar-files-menu
(make-sparse-keymap "Files"))
56 (define-key global-map
[menu-bar files
] (cons "Files" menu-bar-files-menu
))
58 ;; This alias is for compatibility with 19.28 and before.
59 (defvar menu-bar-file-menu menu-bar-files-menu
)
61 (defvar vc-menu-map
(make-sparse-keymap "Version Control"))
63 (define-key menu-bar-tools-menu
[calendar] '("Display Calendar" . calendar))
64 (define-key menu-bar-tools-menu [rmail] '("Read Mail" . rmail))
65 (define-key menu-bar-tools-menu [gnus] '("Read Net News" . gnus))
67 (define-key menu-bar-tools-menu [separator-vc]
70 (define-key menu-bar-tools-menu [vc]
71 (cons "Version Control" vc-menu-map))
73 (define-key menu-bar-tools-menu [separator-compare]
76 (define-key menu-bar-tools-menu [ediff-doc]
77 '("Ediff Manual..." . ediff-documentation))
78 (define-key menu-bar-tools-menu [eregistry]
79 '("List Ediff Sessions..." . ediff-show-registry))
80 (define-key menu-bar-tools-menu [epatch]
81 '("Apply Patch" . menu-bar-epatch-menu))
82 (define-key menu-bar-tools-menu [ediff-merge]
83 '("Merge" . menu-bar-ediff-merge-menu))
84 (define-key menu-bar-tools-menu [compare]
85 '("Compare" . menu-bar-ediff-menu))
87 (define-key menu-bar-tools-menu [separator-print]
90 (put 'print-region 'menu-enable 'mark-active)
91 (put 'ps-print-region-with-faces 'menu-enable 'mark-active)
93 (define-key menu-bar-tools-menu [ps-print-region]
94 '("Postscript Print Region" . ps-print-region-with-faces))
95 (define-key menu-bar-tools-menu [ps-print-buffer]
96 '("Postscript Print Buffer" . ps-print-buffer-with-faces))
97 (define-key menu-bar-tools-menu [print-region]
98 '("Print Region" . print-region))
99 (define-key menu-bar-tools-menu [print-buffer]
100 '("Print Buffer" . print-buffer))
102 (define-key menu-bar-files-menu [exit-emacs]
103 '("Exit Emacs" . save-buffers-kill-emacs))
105 (define-key menu-bar-files-menu [separator-exit]
108 (define-key menu-bar-files-menu [one-window]
109 '("One Window" . delete-other-windows))
111 (define-key menu-bar-files-menu [split-window]
112 '("Split Window" . split-window-vertically))
114 (if (fboundp 'delete-frame)
116 ;; Don't use delete-frame as event name
117 ;; because that is a special event.
118 (define-key menu-bar-files-menu [delete-this-frame]
119 '("Delete Frame" . delete-frame))
120 (define-key menu-bar-files-menu [make-frame-on-display]
121 '("Open New Display..." . make-frame-on-display))
122 (define-key menu-bar-files-menu [make-frame]
123 '("Make New Frame" . make-frame))))
125 (define-key menu-bar-files-menu [separator-buffers]
128 (define-key menu-bar-files-menu [kill-buffer]
129 '("Kill Current Buffer" . kill-this-buffer))
130 (define-key menu-bar-files-menu [insert-file]
131 '("Insert File..." . insert-file))
132 (define-key menu-bar-files-menu [revert-buffer]
133 '("Revert Buffer" . revert-buffer))
134 (define-key menu-bar-files-menu [write-file]
135 '("Save Buffer As..." . write-file))
136 (define-key menu-bar-files-menu [save-buffer] '("Save Buffer" . save-buffer))
137 (define-key menu-bar-files-menu [dired] '("Open Directory..." . dired))
138 (define-key menu-bar-files-menu [open-file] '("Open File..." . find-file))
141 (defun nonincremental-search-forward (string)
142 "Read a string and search for it nonincrementally."
143 (interactive "sSearch for string: ")
144 (if (equal string "")
145 (search-forward (car search-ring))
146 (isearch-update-ring string nil)
147 (search-forward string)))
149 (defun nonincremental-search-backward (string)
150 "Read a string and search backward for it nonincrementally."
151 (interactive "sSearch for string: ")
152 (if (equal string "")
153 (search-backward (car search-ring))
154 (isearch-update-ring string nil)
155 (search-backward string)))
157 (defun nonincremental-re-search-forward (string)
158 "Read a regular expression and search for it nonincrementally."
159 (interactive "sSearch for regexp: ")
160 (if (equal string "")
161 (re-search-forward (car regexp-search-ring))
162 (isearch-update-ring string t)
163 (re-search-forward string)))
165 (defun nonincremental-re-search-backward (string)
166 "Read a regular expression and search backward for it nonincrementally."
167 (interactive "sSearch for regexp: ")
168 (if (equal string "")
169 (re-search-backward (car regexp-search-ring))
170 (isearch-update-ring string t)
171 (re-search-backward string)))
173 (defun nonincremental-repeat-search-forward ()
174 "Search forward for the previous search string."
176 (search-forward (car search-ring)))
178 (defun nonincremental-repeat-search-backward ()
179 "Search backward for the previous search string."
181 (search-backward (car search-ring)))
183 (defun nonincremental-repeat-re-search-forward ()
184 "Search forward for the previous regular expression."
186 (re-search-forward (car regexp-search-ring)))
188 (defun nonincremental-repeat-re-search-backward ()
189 "Search backward for the previous regular expression."
191 (re-search-backward (car regexp-search-ring)))
193 (define-key menu-bar-search-menu [query-replace-regexp]
194 '("Query Replace Regexp..." . query-replace-regexp))
195 (define-key menu-bar-search-menu [query-replace]
196 '("Query Replace..." . query-replace))
197 (define-key menu-bar-search-menu [find-tag]
198 '("Find Tag..." . find-tag))
199 (define-key menu-bar-search-menu [bookmark]
200 '("Bookmarks" . menu-bar-bookmark-map))
202 (define-key menu-bar-search-menu [separator-search]
205 (define-key menu-bar-search-menu [repeat-regexp-back]
206 '("Repeat Regexp Backwards" . nonincremental-repeat-re-search-backward))
207 (define-key menu-bar-search-menu [repeat-search-back]
208 '("Repeat Backwards" . nonincremental-repeat-search-backward))
209 (define-key menu-bar-search-menu [repeat-regexp-fwd]
210 '("Repeat Regexp" . nonincremental-repeat-re-search-forward))
211 (define-key menu-bar-search-menu [repeat-search-fwd]
212 '("Repeat Search" . nonincremental-repeat-search-forward))
214 (define-key menu-bar-search-menu [separator-repeat]
217 (define-key menu-bar-search-menu [re-search-backward]
218 '("Regexp Search Backwards..." . nonincremental-re-search-backward))
219 (define-key menu-bar-search-menu [search-backward]
220 '("Search Backwards..." . nonincremental-search-backward))
221 (define-key menu-bar-search-menu [re-search-forward]
222 '("Regexp Search..." . nonincremental-re-search-forward))
223 (define-key menu-bar-search-menu [search-forward]
224 '("Search..." . nonincremental-search-forward))
226 (if (fboundp 'start-process)
227 (define-key menu-bar-edit-menu [spell] '("Spell" . ispell-menu-map)))
228 (define-key menu-bar-edit-menu [fill] '("Fill" . fill-region))
229 (define-key menu-bar-edit-menu [props] '("Text Properties" . facemenu-menu))
231 (define-key menu-bar-edit-menu [separator-edit]
234 (define-key menu-bar-edit-menu [clear] '("Clear" . delete-region))
236 (define-key menu-bar-edit-menu [paste] '("Paste Most Recent" . yank))
238 (defvar yank-menu (cons "Select Yank" nil))
239 (fset 'yank-menu (cons 'keymap yank-menu))
240 (define-key menu-bar-edit-menu [select-paste] '("Select and Paste" . yank-menu))
241 (define-key menu-bar-edit-menu [copy] '("Copy" . menu-bar-kill-ring-save))
242 (define-key menu-bar-edit-menu [cut] '("Cut" . kill-region))
243 (define-key menu-bar-edit-menu [undo] '("Undo" . undo))
245 (defun menu-bar-kill-ring-save (beg end)
247 (if (mouse-region-match)
248 (message "Select a region with the mouse does `copy' automatically")
249 (kill-ring-save beg end)))
251 (put 'fill-region 'menu-enable '(and mark-active (not buffer-read-only)))
252 (put 'kill-region 'menu-enable '(and mark-active (not buffer-read-only)))
253 (put 'menu-bar-kill-ring-save 'menu-enable 'mark-active)
254 (put 'yank 'menu-enable '(and (x-selection-exists-p) (not buffer-read-only)))
255 (put 'yank-menu 'menu-enable '(and (cdr yank-menu) (not buffer-read-only)))
256 (put 'delete-region 'menu-enable '(and mark-active
257 (not buffer-read-only)
258 (not (mouse-region-match))))
259 (put 'undo 'menu-enable '(and (not buffer-read-only)
260 (if (eq last-command 'undo)
262 (consp buffer-undo-list))))
263 (put 'query-replace 'menu-enable '(not buffer-read-only))
264 (put 'query-replace-regexp 'menu-enable '(not buffer-read-only))
266 (autoload 'ispell-menu-map "ispell" nil t 'keymap)
268 ;; These are alternative definitions for the cut, paste and copy
269 ;; menu items. Use them if your system expects these to use the clipboard.
271 (put 'clipboard-kill-region 'menu-enable 'mark-active)
272 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
273 (put 'clipboard-yank 'menu-enable
274 '(or (x-selection-exists-p) (x-selection-exists-p 'CLIPBOARD)))
276 (defun clipboard-yank ()
277 "Reinsert the last stretch of killed text, or the clipboard contents."
279 (let ((x-select-enable-clipboard t))
282 (defun clipboard-kill-ring-save (beg end)
283 "Copy region to kill ring, and save in the X clipboard."
285 (let ((x-select-enable-clipboard t))
286 (kill-ring-save beg end)))
288 (defun clipboard-kill-region (beg end)
289 "Kill the region, and save it in the X clipboard."
291 (let ((x-select-enable-clipboard t))
292 (kill-region beg end)))
294 (defun menu-bar-enable-clipboard ()
295 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
296 Do the same for the keys of the same name."
298 ;; We can't use constant list structure here because it becomes pure,
299 ;; and because it gets modified with cache data.
300 (define-key menu-bar-edit-menu [paste]
301 (cons "Paste" 'clipboard-yank))
302 (define-key menu-bar-edit-menu [copy]
303 (cons "Copy" 'clipboard-kill-ring-save))
304 (define-key menu-bar-edit-menu [cut]
305 (cons "Cut" 'clipboard-kill-region))
307 (define-key global-map [f20] 'clipboard-kill-region)
308 (define-key global-map [f16] 'clipboard-kill-ring-save)
309 (define-key global-map [f18] 'clipboard-yank)
311 (define-key global-map [cut] 'clipboard-kill-region)
312 (define-key global-map [copy] 'clipboard-kill-ring-save)
313 (define-key global-map [paste] 'clipboard-yank))
315 (define-key menu-bar-help-menu [emacs-version]
316 '("Show Version" . emacs-version))
317 (define-key menu-bar-help-menu [report-emacs-bug]
318 '("Send Bug Report..." . report-emacs-bug))
319 (define-key menu-bar-help-menu [finder-by-keyword]
320 '("Find Lisp Packages..." . finder-by-keyword))
321 (define-key menu-bar-help-menu [emacs-tutorial]
322 '("Emacs Tutorial" . help-with-tutorial))
323 (define-key menu-bar-help-menu [man]
324 '("Man..." . manual-entry))
325 (define-key menu-bar-help-menu [describe-variable]
326 '("Describe Variable..." . describe-variable))
327 (define-key menu-bar-help-menu [describe-function]
328 '("Describe Function..." . describe-function))
329 (define-key menu-bar-help-menu [describe-key]
330 '("Describe Key..." . describe-key))
331 (define-key menu-bar-help-menu [list-keybindings]
332 '("List Keybindings" . describe-bindings))
333 (define-key menu-bar-help-menu [command-apropos]
334 '("Command Apropos..." . command-apropos))
335 (define-key menu-bar-help-menu [describe-mode]
336 '("Describe Mode" . describe-mode))
337 (define-key menu-bar-help-menu [info] '("Browse Manuals" . info))
338 (define-key menu-bar-help-menu [emacs-faq] '("Emacs FAQ" . view-emacs-FAQ))
339 (define-key menu-bar-help-menu [emacs-news] '("Emacs News" . view-emacs-news))
341 (defun kill-this-buffer () ; for the menubar
342 "Kills the current buffer."
344 (kill-buffer (current-buffer)))
346 (defun kill-this-buffer-enabled-p ()
348 (buffers (buffer-list)))
350 (or (string-match "^ " (buffer-name (car buffers)))
351 (setq count (1+ count)))
352 (setq buffers (cdr buffers)))
353 (and (not (window-minibuffer-p (selected-window)))
356 (put 'kill-this-buffer 'menu-enable '(kill-this-buffer-enabled-p))
358 (put 'save-buffer 'menu-enable
359 '(and (buffer-modified-p)
360 (not (window-minibuffer-p (selected-window)))))
362 (put 'write-file 'menu-enable
363 '(not (window-minibuffer-p (selected-window))))
365 (put 'find-file 'menu-enable
366 '(not (window-minibuffer-p (selected-window))))
368 (put 'dired 'menu-enable
369 '(not (window-minibuffer-p (selected-window))))
371 (put 'insert-file 'menu-enable
372 '(not (window-minibuffer-p (selected-window))))
374 (put 'revert-buffer 'menu-enable
375 '(or revert-buffer-function revert-buffer-insert-file-contents-function
376 (and (buffer-file-name)
377 (or (buffer-modified-p)
378 (not (verify-visited-file-modtime (current-buffer)))))))
380 ;; Permit deleting frame if it would leave a visible or iconified frame.
381 (put 'delete-frame 'menu-enable
382 '(delete-frame-enabled-p))
384 (defun delete-frame-enabled-p ()
385 "Return non-nil if `delete-frame' should be enabled in the menu bar."
386 (let ((frames (frame-list))
389 (if (frame-visible-p (car frames))
390 (setq count (1+ count)))
391 (setq frames (cdr frames)))
394 (put 'advertised-undo 'menu-enable
395 '(and (not (eq t buffer-undo-list))
396 (if (eq last-command 'undo)
397 (and (boundp 'pending-undo-list)
401 (defvar yank-menu-length 20
402 "*Maximum length to display in the yank-menu.")
404 (defun menu-bar-update-yank-menu (string old)
405 (let ((front (car (cdr yank-menu)))
406 (menu-string (if (<= (length string) yank-menu-length)
409 (substring string 0 (/ yank-menu-length 2))
411 (substring string (- (/ yank-menu-length 2)))))))
412 ;; Don't let the menu string be all dashes
413 ;; because that has a special meaning in a menu.
414 (if (string-match "\\`-+\\'" menu-string)
415 (setq menu-string (concat menu-string " ")))
416 ;; If we're supposed to be extending an existing string, and that
417 ;; string really is at the front of the menu, then update it in place.
418 (if (and old (or (eq old (car front))
419 (string= old (car front))))
421 (setcar front string)
422 (setcar (cdr front) menu-string))
425 (cons string (cons menu-string 'menu-bar-select-yank))
427 (if (> (length (cdr yank-menu)) kill-ring-max)
428 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
430 (defun menu-bar-select-yank ()
433 (insert last-command-event))
435 ;; This definition is just to show what this looks like.
436 ;; It gets overridden below when menu-bar-update-buffers is called.
437 (define-key global-map [menu-bar buffer]
438 (cons "Buffers" (make-sparse-keymap "Buffers")))
440 (defvar list-buffers-directory nil)
442 (defvar menu-bar-update-buffers-maxbuf)
444 (defun menu-bar-select-buffer ()
446 (switch-to-buffer last-command-event))
448 (defun menu-bar-select-frame ()
450 (make-frame-visible last-command-event)
451 (raise-frame last-command-event)
452 (select-frame last-command-event))
454 (defun menu-bar-update-buffers-1 (elt)
456 (format "%%%ds %%s%%s %%s" menu-bar-update-buffers-maxbuf)
458 (if (buffer-modified-p (car elt))
461 (set-buffer (car elt))
462 (if buffer-read-only "%" " "))
464 (or (buffer-file-name (car elt))
466 (set-buffer (car elt))
467 list-buffers-directory)
469 (setq file (or (file-name-directory file)
471 (if (> (length file) 20)
472 (setq file (concat "..." (substring file -17))))
476 (defvar menu-bar-buffers-menu-list-buffers-entry nil)
478 (defun menu-bar-update-buffers ()
479 ;; If user discards the Buffers item, play along.
480 (and (lookup-key (current-global-map) [menu-bar buffer])
481 (frame-or-buffer-changed-p)
482 (let ((buffers (buffer-list))
483 (frames (frame-list))
484 buffers-menu frames-menu)
485 ;; If requested, list only the N most recently selected buffers.
486 (if (and (integerp buffers-menu-max-size)
487 (> buffers-menu-max-size 1))
488 (if (> (length buffers) buffers-menu-max-size)
489 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
491 ;; Make the menu of buffers proper.
493 (cons "Select Buffer"
495 (mapcar 'list buffers))
497 (menu-bar-update-buffers-maxbuf 0)
501 ;; Put into each element of buffer-list
502 ;; the name for actual display,
503 ;; perhaps truncated in the middle.
504 (setq tail buffer-list)
506 (let ((name (buffer-name (car (car tail)))))
508 (if (> (length name) 27)
509 (concat (substring name 0 12)
511 (substring name -12))
513 (setq tail (cdr tail)))
514 ;; Compute the maximum length of any name.
515 (setq tail buffer-list)
517 (or (eq ?\ (aref (cdr (car tail)) 0))
518 (setq menu-bar-update-buffers-maxbuf
519 (max menu-bar-update-buffers-maxbuf
520 (length (cdr (car tail))))))
521 (setq tail (cdr tail)))
522 ;; Set ALIST to an alist of the form
523 ;; ITEM-STRING . BUFFER
524 (setq tail buffer-list)
526 (let ((elt (car tail)))
527 (or (eq ?\ (aref (cdr elt) 0))
529 (menu-bar-update-buffers-1 elt)
531 (and alist (> (length (car (car alist))) maxlen)
532 (setq maxlen (length (car (car alist))))))
533 (setq tail (cdr tail)))
534 (setq alist (nreverse alist))
535 ;; Make the menu item for list-buffers
536 ;; or reuse the one we already have.
537 ;; The advantage in reusing one
538 ;; is that it already has the keyboard equivalent
539 ;; cached, so we save the time to look that up again.
540 (or menu-bar-buffers-menu-list-buffers-entry
541 (setq menu-bar-buffers-menu-list-buffers-entry
547 ;; Update the item string for menu's new width.
548 (setcar (cdr menu-bar-buffers-menu-list-buffers-entry)
549 (concat (make-string (max (- (/ maxlen 2) 8) 0)
552 ;; Now make the actual list of items,
553 ;; ending with the list-buffers item.
554 (nconc (mapcar '(lambda (pair)
555 ;; This is somewhat risque, to use
556 ;; the buffer name itself as the event
557 ;; type to define, but it works.
558 ;; It would not work to use the buffer
559 ;; since a buffer as an event has its
561 (nconc (list (buffer-name (cdr pair))
564 'menu-bar-select-buffer))
566 (list menu-bar-buffers-menu-list-buffers-entry)))))
569 ;; Make a Frames menu if we have more than one frame.
573 (mapcar '(lambda (frame)
576 (frame-parameters frame)))
578 'menu-bar-select-frame))
581 (setq buffers-menu (cons 'keymap buffers-menu)))
583 (setq frames-menu (cons 'keymap frames-menu)))
584 (define-key (current-global-map) [menu-bar buffer]
586 (if (and buffers-menu frames-menu)
587 (list 'keymap "Buffers and Frames"
588 (cons 'buffers (cons "Buffers" buffers-menu))
589 (cons 'frames (cons "Frames" frames-menu)))
590 (or buffers-menu frames-menu 'undefined)))))))
592 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
594 (menu-bar-update-buffers)
596 ;; this version is too slow
597 ;;;(defun format-buffers-menu-line (buffer)
598 ;;; "Returns a string to represent the given buffer in the Buffer menu.
599 ;;;nil means the buffer shouldn't be listed. You can redefine this."
600 ;;; (if (string-match "\\` " (buffer-name buffer))
603 ;;; (set-buffer buffer)
604 ;;; (let ((size (buffer-size)))
605 ;;; (format "%s%s %-19s %6s %-15s %s"
606 ;;; (if (buffer-modified-p) "*" " ")
607 ;;; (if buffer-read-only "%" " ")
611 ;;; (or (buffer-file-name) ""))))))
613 ;;; Set up a menu bar menu for the minibuffer.
618 (define-key map [menu-bar minibuf]
619 (cons "Minibuf" (make-sparse-keymap "Minibuf")))))
620 (list minibuffer-local-ns-map
621 minibuffer-local-must-match-map
622 minibuffer-local-isearch-map
624 minibuffer-local-completion-map))
629 (define-key map [menu-bar minibuf ?\?]
630 '("List Completions" . minibuffer-completion-help))
631 (define-key map [menu-bar minibuf space]
632 '("Complete Word" . minibuffer-complete-word))
633 (define-key map [menu-bar minibuf tab]
634 '("Complete" . minibuffer-complete))
636 (list minibuffer-local-must-match-map
637 minibuffer-local-completion-map))
642 (define-key map [menu-bar minibuf quit]
643 '("Quit" . keyboard-escape-quit))
644 (define-key map [menu-bar minibuf return]
645 '("Enter" . exit-minibuffer))
647 (list minibuffer-local-ns-map
648 minibuffer-local-must-match-map
649 minibuffer-local-isearch-map
651 minibuffer-local-completion-map))
653 (defvar menu-bar-mode nil)
655 (defun menu-bar-mode (flag)
656 "Toggle display of a menu bar on each frame.
657 This command applies to all frames that exist and frames to be
658 created in the future.
659 With a numeric argument, if the argument is negative,
660 turn off menu bars; otherwise, turn on menu bars."
663 ;; Make menu-bar-mode and default-frame-alist consistent.
664 (let ((default (assq 'menu-bar-lines default-frame-alist)))
666 (setq menu-bar-mode (not (eq (cdr default) 0)))
667 (setq default-frame-alist
668 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
669 default-frame-alist))))
671 ;; Toggle or set the mode, according to FLAG.
672 (setq menu-bar-mode (if (null flag) (not menu-bar-mode)
673 (> (prefix-numeric-value flag) 0)))
675 ;; Apply it to default-frame-alist.
676 (let ((parameter (assq 'menu-bar-lines default-frame-alist)))
677 (if (consp parameter)
678 (setcdr parameter (if menu-bar-mode 1 0))
679 (setq default-frame-alist
680 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
681 default-frame-alist))))
683 ;; Apply it to existing frames.
684 (let ((frames (frame-list)))
686 (let ((height (cdr (assq 'height (frame-parameters (car frames))))))
687 (modify-frame-parameters (car frames)
688 (list (cons 'menu-bar-lines
689 (if menu-bar-mode 1 0))))
690 (modify-frame-parameters (car frames)
691 (list (cons 'height height))))
692 (setq frames (cdr frames)))))
696 ;;; menu-bar.el ends here