1 ;;; menu-bar.el --- define a default menu bar.
6 ;; 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
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 ;; Avishai Yacobi suggested some menu rearrangements.
28 ;; Don't clobber an existing menu-bar keymap, to preserve any menu-bar key
29 ;; definitions made in loaddefs.el.
30 (or (lookup-key global-map
[menu-bar
])
31 (define-key global-map
[menu-bar
] (make-sparse-keymap "menu-bar")))
32 (defvar menu-bar-help-menu
(make-sparse-keymap "Help"))
34 ;; Force Help item to come last, after the major mode's own items.
35 ;; The symbol used to be called `help', but that gets confused with the
37 (setq menu-bar-final-items
'(help-menu))
39 (define-key global-map
[menu-bar help-menu
] (cons "Help" menu-bar-help-menu
))
40 (defvar menu-bar-search-menu
(make-sparse-keymap "Search"))
41 (define-key global-map
[menu-bar search
] (cons "Search" menu-bar-search-menu
))
42 (defvar menu-bar-edit-menu
(make-sparse-keymap "Edit"))
43 (define-key global-map
[menu-bar edit
] (cons "Edit" menu-bar-edit-menu
))
44 (defvar menu-bar-tools-menu
(make-sparse-keymap "Tools"))
45 (define-key global-map
[menu-bar tools
] (cons "Tools" menu-bar-tools-menu
))
46 (defvar menu-bar-files-menu
(make-sparse-keymap "Files"))
47 (define-key global-map
[menu-bar files
] (cons "Files" menu-bar-files-menu
))
49 ;; This alias is for compatibility with 19.28 and before.
50 (defvar menu-bar-file-menu menu-bar-files-menu
)
52 (defvar vc-menu-map
(make-sparse-keymap "Version Control"))
54 (define-key menu-bar-tools-menu
[calendar] '("Display Calendar" . calendar))
55 (define-key menu-bar-tools-menu [rmail] '("Read Mail" . rmail))
56 (if (fboundp 'open-network-stream)
57 (define-key menu-bar-tools-menu [gnus] '("Read Net News" . gnus)))
59 (define-key menu-bar-tools-menu [separator-vc]
62 (define-key menu-bar-tools-menu [vc-menu]
63 (cons "Version Control" vc-menu-map))
65 (define-key menu-bar-tools-menu [separator-compare]
68 (define-key menu-bar-tools-menu [epatch]
69 '("Apply Patch" . menu-bar-epatch-menu))
70 (define-key menu-bar-tools-menu [ediff-merge]
71 '("Merge" . menu-bar-ediff-merge-menu))
72 (define-key menu-bar-tools-menu [compare]
73 '("Compare" . menu-bar-ediff-menu))
75 (define-key menu-bar-tools-menu [separator-print]
78 (put 'print-region 'menu-enable 'mark-active)
79 (put 'ps-print-region-with-faces 'menu-enable 'mark-active)
81 (define-key menu-bar-tools-menu [ps-print-region]
82 '("Postscript Print Region" . ps-print-region-with-faces))
83 (define-key menu-bar-tools-menu [ps-print-buffer]
84 '("Postscript Print Buffer" . ps-print-buffer-with-faces))
85 (define-key menu-bar-tools-menu [print-region]
86 '("Print Region" . print-region))
87 (define-key menu-bar-tools-menu [print-buffer]
88 '("Print Buffer" . print-buffer))
90 (define-key menu-bar-files-menu [exit-emacs]
91 '("Exit Emacs" . save-buffers-kill-emacs))
93 (define-key menu-bar-files-menu [separator-exit]
96 (define-key menu-bar-files-menu [one-window]
97 '("One Window" . delete-other-windows))
99 (define-key menu-bar-files-menu [split-window]
100 '("Split Window" . split-window-vertically))
102 (if (fboundp 'delete-frame)
104 (define-key menu-bar-files-menu [delete-frame]
105 '("Delete Frame" . delete-frame))
106 (define-key menu-bar-files-menu [make-frame-on-display]
107 '("Open New Display..." . make-frame-on-display))
108 (define-key menu-bar-files-menu [make-frame]
109 '("Make New Frame" . make-frame))))
111 (define-key menu-bar-files-menu [separator-buffers]
114 (define-key menu-bar-files-menu [kill-buffer]
115 '("Kill Current Buffer" . kill-this-buffer))
116 (define-key menu-bar-files-menu [insert-file]
117 '("Insert File..." . insert-file))
118 (define-key menu-bar-files-menu [revert-buffer]
119 '("Revert Buffer" . revert-buffer))
120 (define-key menu-bar-files-menu [write-file]
121 '("Save Buffer As..." . write-file))
122 (define-key menu-bar-files-menu [save-buffer] '("Save Buffer" . save-buffer))
123 (define-key menu-bar-files-menu [dired] '("Open Directory..." . dired))
124 (define-key menu-bar-files-menu [open-file] '("Open File..." . find-file))
126 ;; This is just one element of the ediff menu--the first.
127 (define-key menu-bar-ediff-menu [window]
128 '("This Window And Next Window" . compare-windows))
130 (defun nonincremental-search-forward (string)
131 "Read a string and search for it nonincrementally."
132 (interactive "sSearch for string: ")
133 (if (equal string "")
134 (search-forward (car search-ring))
135 (isearch-update-ring string nil)
136 (search-forward string)))
138 (defun nonincremental-search-backward (string)
139 "Read a string and search backward for it nonincrementally."
140 (interactive "sSearch for string: ")
141 (if (equal string "")
142 (search-backward (car search-ring))
143 (isearch-update-ring string nil)
144 (search-backward string)))
146 (defun nonincremental-re-search-forward (string)
147 "Read a regular expression and search for it nonincrementally."
148 (interactive "sSearch for regexp: ")
149 (if (equal string "")
150 (re-search-forward (car regexp-search-ring))
151 (isearch-update-ring string t)
152 (re-search-forward string)))
154 (defun nonincremental-re-search-backward (string)
155 "Read a regular expression and search backward for it nonincrementally."
156 (interactive "sSearch for regexp: ")
157 (if (equal string "")
158 (re-search-backward (car regexp-search-ring))
159 (isearch-update-ring string t)
160 (re-search-backward string)))
162 (defun nonincremental-repeat-search-forward ()
163 "Search forward for the previous search string."
165 (search-forward (car search-ring)))
167 (defun nonincremental-repeat-search-backward ()
168 "Search backward for the previous search string."
170 (search-backward (car search-ring)))
172 (defun nonincremental-repeat-re-search-forward ()
173 "Search forward for the previous regular expression."
175 (re-search-forward (car regexp-search-ring)))
177 (defun nonincremental-repeat-re-search-backward ()
178 "Search backward for the previous regular expression."
180 (re-search-backward (car regexp-search-ring)))
182 (define-key menu-bar-search-menu [query-replace-regexp]
183 '("Query Replace Regexp..." . query-replace-regexp))
184 (define-key menu-bar-search-menu [query-replace]
185 '("Query Replace..." . query-replace))
186 (define-key menu-bar-search-menu [find-tag]
187 '("Find Tag..." . find-tag))
188 (define-key menu-bar-search-menu [bookmark]
189 '("Bookmarks" . menu-bar-bookmark-map))
191 (define-key menu-bar-search-menu [separator-search]
194 (define-key menu-bar-search-menu [nonincremental-repeat-re-search-back]
195 '("Repeat Regexp Backwards" . nonincremental-repeat-re-search-backward))
196 (define-key menu-bar-search-menu [nonincremental-repeat-search-back]
197 '("Repeat Backwards" . nonincremental-repeat-search-backward))
198 (define-key menu-bar-search-menu [nonincremental-repeat-re-search-fwd]
199 '("Repeat Regexp" . nonincremental-repeat-re-search-forward))
200 (define-key menu-bar-search-menu [nonincremental-repeat-search-fwd]
201 '("Repeat Search" . nonincremental-repeat-search-forward))
203 (define-key menu-bar-search-menu [separator-repeat]
206 (define-key menu-bar-search-menu [re-search-back]
207 '("Regexp Search Backwards..." . nonincremental-re-search-backward))
208 (define-key menu-bar-search-menu [search-back]
209 '("Search Backwards..." . nonincremental-search-backward))
210 (define-key menu-bar-search-menu [re-search-fwd]
211 '("Regexp Search..." . nonincremental-re-search-forward))
212 (define-key menu-bar-search-menu [search-fwd]
213 '("Search..." . nonincremental-search-forward))
215 (if (fboundp 'start-process)
216 (define-key menu-bar-edit-menu [spell] '("Spell" . ispell-menu-map)))
217 (define-key menu-bar-edit-menu [fill] '("Fill" . fill-region))
218 (define-key menu-bar-edit-menu [props] '("Text Properties" . facemenu-menu))
220 (define-key menu-bar-edit-menu [separator-edit]
223 (define-key menu-bar-edit-menu [clear] '("Clear" . delete-region))
225 (define-key menu-bar-edit-menu [paste] '("Paste Most Recent" . yank))
227 (defvar yank-menu (cons "Select Yank" nil))
228 (fset 'yank-menu (cons 'keymap yank-menu))
229 (define-key menu-bar-edit-menu [select-paste] '("Select and Paste" . yank-menu))
230 (define-key menu-bar-edit-menu [copy] '("Copy" . menu-bar-kill-ring-save))
231 (define-key menu-bar-edit-menu [cut] '("Cut" . kill-region))
232 (define-key menu-bar-edit-menu [undo] '("Undo" . undo))
234 (defun menu-bar-kill-ring-save (beg end)
236 (if (mouse-region-match)
237 (message "Select a region with the mouse does `copy' automatically")
238 (kill-ring-save beg end)))
240 (put 'fill-region 'menu-enable '(and mark-active (not buffer-read-only)))
241 (put 'kill-region 'menu-enable '(and mark-active (not buffer-read-only)))
242 (put 'menu-bar-kill-ring-save 'menu-enable 'mark-active)
243 (put 'yank 'menu-enable '(and (x-selection-exists-p) (not buffer-read-only)))
244 (put 'yank-menu 'menu-enable '(and (cdr yank-menu) (not buffer-read-only)))
245 (put 'delete-region 'menu-enable '(and mark-active
246 (not buffer-read-only)
247 (not (mouse-region-match))))
248 (put 'undo 'menu-enable '(and (not buffer-read-only)
249 (if (eq last-command 'undo)
251 (consp buffer-undo-list))))
252 (put 'query-replace 'menu-enable '(not buffer-read-only))
253 (put 'query-replace-regexp 'menu-enable '(not buffer-read-only))
255 (autoload 'ispell-menu-map "ispell" nil t 'keymap)
257 ;; These are alternative definitions for the cut, paste and copy
258 ;; menu items. Use them if your system expects these to use the clipboard.
260 (put 'clipboard-kill-region 'menu-enable 'mark-active)
261 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
262 (put 'clipboard-yank 'menu-enable
263 '(or (x-selection-exists-p) (x-selection-exists-p 'CLIPBOARD)))
265 (defun clipboard-yank ()
266 "Reinsert the last stretch of killed text, or the clipboard contents."
268 (let ((x-select-enable-clipboard t))
271 (defun clipboard-kill-ring-save (beg end)
272 "Copy region to kill ring, and save in the X clipboard."
274 (let ((x-select-enable-clipboard t))
275 (kill-ring-save beg end)))
277 (defun clipboard-kill-region (beg end)
278 "Kill the region, and save it in the X clipboard."
280 (let ((x-select-enable-clipboard t))
281 (kill-region beg end)))
283 (defun menu-bar-enable-clipboard ()
284 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
285 Do the same for the keys of the same name."
287 ;; We can't use constant list structure here because it becomes pure,
288 ;; and because it gets modified with cache data.
289 (define-key menu-bar-edit-menu [paste]
290 (cons "Paste" 'clipboard-yank))
291 (define-key menu-bar-edit-menu [copy]
292 (cons "Copy" 'clipboard-kill-ring-save))
293 (define-key menu-bar-edit-menu [cut]
294 (cons "Cut" 'clipboard-kill-region))
296 (define-key global-map [f20] 'clipboard-kill-region)
297 (define-key global-map [f16] 'clipboard-kill-ring-save)
298 (define-key global-map [f18] 'clipboard-yank)
300 (define-key global-map [cut] 'clipboard-kill-region)
301 (define-key global-map [copy] 'clipboard-kill-ring-save)
302 (define-key global-map [paste] 'clipboard-yank))
304 (define-key menu-bar-help-menu [emacs-version]
305 '("Show Version" . emacs-version))
306 (define-key menu-bar-help-menu [report-emacs-bug]
307 '("Send Bug Report..." . report-emacs-bug))
308 (define-key menu-bar-help-menu [finder-by-keyword]
309 '("Find Lisp Packages..." . finder-by-keyword))
310 (define-key menu-bar-help-menu [emacs-tutorial]
311 '("Emacs Tutorial" . help-with-tutorial))
312 (define-key menu-bar-help-menu [man]
313 '("Man..." . manual-entry))
314 (define-key menu-bar-help-menu [describe-variable]
315 '("Describe Variable..." . describe-variable))
316 (define-key menu-bar-help-menu [describe-function]
317 '("Describe Function..." . describe-function))
318 (define-key menu-bar-help-menu [describe-key]
319 '("Describe Key..." . describe-key))
320 (define-key menu-bar-help-menu [list-keybindings]
321 '("List Keybindings" . describe-bindings))
322 (define-key menu-bar-help-menu [command-apropos]
323 '("Command Apropos..." . command-apropos))
324 (define-key menu-bar-help-menu [describe-mode]
325 '("Describe Mode" . describe-mode))
326 (define-key menu-bar-help-menu [info] '("Browse Manuals" . info))
327 (define-key menu-bar-help-menu [emacs-faq] '("Emacs FAQ" . view-emacs-FAQ))
328 (define-key menu-bar-help-menu [emacs-news] '("Emacs News" . view-emacs-news))
330 (defun kill-this-buffer () ; for the menubar
331 "Kills the current buffer."
333 (kill-buffer (current-buffer)))
335 (defun kill-this-buffer-enabled-p ()
337 (buffers (buffer-list)))
339 (or (string-match "^ " (buffer-name (car buffers)))
340 (setq count (1+ count)))
341 (setq buffers (cdr buffers)))
342 (and (not (window-minibuffer-p (selected-window)))
345 (put 'kill-this-buffer 'menu-enable '(kill-this-buffer-enabled-p))
347 (put 'save-buffer 'menu-enable
348 '(and (buffer-modified-p)
349 (not (window-minibuffer-p (selected-window)))))
351 (put 'write-file 'menu-enable
352 '(not (window-minibuffer-p (selected-window))))
354 (put 'find-file 'menu-enable
355 '(not (window-minibuffer-p (selected-window))))
357 (put 'dired 'menu-enable
358 '(not (window-minibuffer-p (selected-window))))
360 (put 'insert-file 'menu-enable
361 '(not (window-minibuffer-p (selected-window))))
363 (put 'revert-buffer 'menu-enable
364 '(or revert-buffer-function revert-buffer-insert-file-contents-function
365 (and (buffer-file-name)
366 (or (buffer-modified-p)
367 (not (verify-visited-file-modtime (current-buffer)))))))
369 ;; Permit deleting frame if it would leave a visible or iconified frame.
370 (put 'delete-frame 'menu-enable
371 '(delete-frame-enabled-p))
373 (defun delete-frame-enabled-p ()
374 "Return non-nil if `delete-frame' should be enabled in the menu bar."
375 (let ((frames (frame-list))
378 (if (frame-visible-p (car frames))
379 (setq count (1+ count)))
380 (setq frames (cdr frames)))
383 (put 'advertised-undo 'menu-enable
384 '(and (not (eq t buffer-undo-list))
385 (if (eq last-command 'undo)
386 (and (boundp 'pending-undo-list)
390 (defvar yank-menu-length 20
391 "*Maximum length to display in the yank-menu.")
393 (defun menu-bar-update-yank-menu (string old)
394 (let ((front (car (cdr yank-menu)))
395 (menu-string (if (<= (length string) yank-menu-length)
398 (substring string 0 (/ yank-menu-length 2))
400 (substring string (- (/ yank-menu-length 2)))))))
401 ;; Don't let the menu string be all dashes
402 ;; because that has a special meaning in a menu.
403 (if (string-match "\\`-+\\'" menu-string)
404 (setq menu-string (concat menu-string " ")))
405 ;; If we're supposed to be extending an existing string, and that
406 ;; string really is at the front of the menu, then update it in place.
407 (if (and old (or (eq old (car front))
408 (string= old (car front))))
410 (setcar front string)
411 (setcar (cdr front) menu-string))
414 (cons string (cons menu-string 'menu-bar-select-yank))
416 (if (> (length (cdr yank-menu)) kill-ring-max)
417 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
419 (defun menu-bar-select-yank ()
422 (insert last-command-event))
424 ;; This definition is just to show what this looks like.
425 ;; It gets overridden below when menu-bar-update-buffers is called.
426 (define-key global-map [menu-bar buffer]
427 (cons "Buffers" (make-sparse-keymap "Buffers")))
429 (defvar buffers-menu-max-size 10
430 "*Maximum number of entries which may appear on the Buffers menu.
431 If this is 10, then only the ten most-recently-selected buffers are shown.
432 If this is nil, then all buffers are shown.
433 A large number or nil slows down menu responsiveness.")
435 (defvar list-buffers-directory nil)
437 (defvar menu-bar-update-buffers-maxbuf)
439 (defun menu-bar-select-buffer ()
441 (switch-to-buffer last-command-event))
443 (defun menu-bar-select-frame ()
445 (make-frame-visible last-command-event)
446 (raise-frame last-command-event)
447 (select-frame last-command-event))
449 (defun menu-bar-update-buffers-1 (elt)
451 (format "%%%ds %%s%%s %%s" menu-bar-update-buffers-maxbuf)
453 (if (buffer-modified-p (car elt))
456 (set-buffer (car elt))
457 (if buffer-read-only "%" " "))
459 (or (buffer-file-name (car elt))
461 (set-buffer (car elt))
462 list-buffers-directory)
464 (setq file (or (file-name-directory file)
466 (if (> (length file) 20)
467 (setq file (concat "..." (substring file -17))))
471 (defvar menu-bar-buffers-menu-list-buffers-entry nil)
473 (defun menu-bar-update-buffers ()
474 ;; If user discards the Buffers item, play along.
475 (and (lookup-key (current-global-map) [menu-bar buffer])
476 (frame-or-buffer-changed-p)
477 (let ((buffers (buffer-list))
478 (frames (frame-list))
479 buffers-menu frames-menu)
480 ;; If requested, list only the N most recently selected buffers.
481 (if (and (integerp buffers-menu-max-size)
482 (> buffers-menu-max-size 1))
483 (if (> (length buffers) buffers-menu-max-size)
484 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
486 ;; Make the menu of buffers proper.
488 (cons "Select Buffer"
490 (mapcar 'list buffers))
492 (menu-bar-update-buffers-maxbuf 0)
496 ;; Put into each element of buffer-list
497 ;; the name for actual display,
498 ;; perhaps truncated in the middle.
499 (setq tail buffer-list)
501 (let ((name (buffer-name (car (car tail)))))
503 (if (> (length name) 27)
504 (concat (substring name 0 12)
506 (substring name -12))
508 (setq tail (cdr tail)))
509 ;; Compute the maximum length of any name.
510 (setq tail buffer-list)
512 (or (eq ?\ (aref (cdr (car tail)) 0))
513 (setq menu-bar-update-buffers-maxbuf
514 (max menu-bar-update-buffers-maxbuf
515 (length (cdr (car tail))))))
516 (setq tail (cdr tail)))
517 ;; Set ALIST to an alist of the form
518 ;; ITEM-STRING . BUFFER
519 (setq tail buffer-list)
521 (let ((elt (car tail)))
522 (or (eq ?\ (aref (cdr elt) 0))
524 (menu-bar-update-buffers-1 elt)
526 (and alist (> (length (car (car alist))) maxlen)
527 (setq maxlen (length (car (car alist))))))
528 (setq tail (cdr tail)))
529 (setq alist (nreverse alist))
530 ;; Make the menu item for list-buffers
531 ;; or reuse the one we already have.
532 ;; The advantage in reusing one
533 ;; is that it already has the keyboard equivalent
534 ;; cached, so we save the time to look that up again.
535 (or menu-bar-buffers-menu-list-buffers-entry
536 (setq menu-bar-buffers-menu-list-buffers-entry
542 ;; Update the item string for menu's new width.
543 (setcar (cdr menu-bar-buffers-menu-list-buffers-entry)
544 (concat (make-string (max (- (/ maxlen 2) 8) 0)
547 ;; Now make the actual list of items,
548 ;; ending with the list-buffers item.
549 (nconc (mapcar '(lambda (pair)
550 ;; This is somewhat risque, to use
551 ;; the buffer name itself as the event
552 ;; type to define, but it works.
553 ;; It would not work to use the buffer
554 ;; since a buffer as an event has its
556 (nconc (list (buffer-name (cdr pair))
559 'menu-bar-select-buffer))
561 (list menu-bar-buffers-menu-list-buffers-entry)))))
564 ;; Make a Frames menu if we have more than one frame.
568 (mapcar '(lambda (frame)
571 (frame-parameters frame)))
573 'menu-bar-select-frame))
576 (setq buffers-menu (cons 'keymap buffers-menu)))
578 (setq frames-menu (cons 'keymap frames-menu)))
579 (define-key (current-global-map) [menu-bar buffer]
581 (if (and buffers-menu frames-menu)
582 (list 'keymap "Buffers and Frames"
583 (cons 'buffers (cons "Buffers" buffers-menu))
584 (cons 'frames (cons "Frames" frames-menu)))
585 (or buffers-menu frames-menu 'undefined)))))))
587 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
589 (menu-bar-update-buffers)
591 ;; this version is too slow
592 ;;;(defun format-buffers-menu-line (buffer)
593 ;;; "Returns a string to represent the given buffer in the Buffer menu.
594 ;;;nil means the buffer shouldn't be listed. You can redefine this."
595 ;;; (if (string-match "\\` " (buffer-name buffer))
598 ;;; (set-buffer buffer)
599 ;;; (let ((size (buffer-size)))
600 ;;; (format "%s%s %-19s %6s %-15s %s"
601 ;;; (if (buffer-modified-p) "*" " ")
602 ;;; (if buffer-read-only "%" " ")
606 ;;; (or (buffer-file-name) ""))))))
608 ;;; Set up a menu bar menu for the minibuffer.
613 (define-key map [menu-bar minibuf]
614 (cons "Minibuf" (make-sparse-keymap "Minibuf")))))
615 (list minibuffer-local-ns-map
616 minibuffer-local-must-match-map
617 minibuffer-local-isearch-map
619 minibuffer-local-completion-map))
624 (define-key map [menu-bar minibuf ?\?]
625 '("List Completions" . minibuffer-completion-help))
626 (define-key map [menu-bar minibuf space]
627 '("Complete Word" . minibuffer-complete-word))
628 (define-key map [menu-bar minibuf tab]
629 '("Complete" . 'minibuffer-complete))
631 (list minibuffer-local-must-match-map
632 minibuffer-local-completion-map))
637 (define-key map [menu-bar minibuf quit]
638 '("Quit" . keyboard-escape-quit))
639 (define-key map [menu-bar minibuf return]
640 '("Enter" . exit-minibuffer))
642 (list minibuffer-local-ns-map
643 minibuffer-local-must-match-map
644 minibuffer-local-isearch-map
646 minibuffer-local-completion-map))
648 (defvar menu-bar-mode nil)
650 (defun menu-bar-mode (flag)
651 "Toggle display of a menu bar on each frame.
652 This command applies to all frames that exist and frames to be
653 created in the future.
654 With a numeric argument, if the argument is negative,
655 turn off menu bars; otherwise, turn on menu bars."
658 ;; Make menu-bar-mode and default-frame-alist consistent.
659 (let ((default (assq 'menu-bar-lines default-frame-alist)))
661 (setq menu-bar-mode (not (eq (cdr default) 0)))
662 (setq default-frame-alist
663 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
664 default-frame-alist))))
666 ;; Toggle or set the mode, according to FLAG.
667 (setq menu-bar-mode (if (null flag) (not menu-bar-mode)
668 (> (prefix-numeric-value flag) 0)))
670 ;; Apply it to default-frame-alist.
671 (let ((parameter (assq 'menu-bar-lines default-frame-alist)))
672 (if (consp parameter)
673 (setcdr parameter (if menu-bar-mode 1 0))
674 (setq default-frame-alist
675 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
676 default-frame-alist))))
678 ;; Apply it to existing frames.
679 (let ((frames (frame-list)))
681 (let ((height (cdr (assq 'height (frame-parameters (car frames))))))
682 (modify-frame-parameters (car frames)
683 (list (cons 'menu-bar-lines
684 (if menu-bar-mode 1 0))))
685 (modify-frame-parameters (car frames)
686 (list (cons 'height height))))
687 (setq frames (cdr frames)))))
691 ;;; menu-bar.el ends here