Various menu changes.
[emacs.git] / lisp / menu-bar.el
blobaa9192b95269786b9f85a37aaf310add0797b502
1 ;;; menu-bar.el --- define a default menu bar.
3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
5 ;; Author: RMS
6 ;; Maintainer: FSF
7 ;; Keywords: internal
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;; Avishai Yacobi suggested some menu rearrangements.
28 ;;; Code:
30 ;;; User options:
32 (defcustom buffers-menu-max-size 10
33 "*Maximum number of entries which may appear on the Buffers menu.
34 If this is 10, then only the ten most-recently-selected buffers are shown.
35 If this is nil, then all buffers are shown.
36 A large number or nil slows down menu responsiveness."
37 :type '(choice integer
38 (const :tag "All" nil))
39 :group 'mouse)
41 ;; Don't clobber an existing menu-bar keymap, to preserve any menu-bar key
42 ;; definitions made in loaddefs.el.
43 (or (lookup-key global-map [menu-bar])
44 (define-key global-map [menu-bar] (make-sparse-keymap "menu-bar")))
45 (defvar menu-bar-help-menu (make-sparse-keymap "Help"))
47 ;; Force Help item to come last, after the major mode's own items.
48 ;; The symbol used to be called `help', but that gets confused with the
49 ;; help key.
50 (setq menu-bar-final-items '(help-menu))
52 (define-key global-map [menu-bar help-menu] (cons "Help" menu-bar-help-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 ;; This definition is just to show what this looks like.
56 ;; It gets overridden below when menu-bar-update-buffers is called.
57 (define-key global-map [menu-bar buffer]
58 (cons "Buffers" (make-sparse-keymap "Buffers")))
59 (defvar menu-bar-options-menu (make-sparse-keymap "Options"))
60 (define-key global-map [menu-bar options]
61 (cons "Options" menu-bar-options-menu))
62 (defvar menu-bar-edit-menu (make-sparse-keymap "Edit"))
63 (define-key global-map [menu-bar edit] (cons "Edit" menu-bar-edit-menu))
64 (defvar menu-bar-files-menu (make-sparse-keymap "File"))
65 (define-key global-map [menu-bar files] (cons "File" menu-bar-files-menu))
67 ;; This alias is for compatibility with 19.28 and before.
68 (defvar menu-bar-file-menu menu-bar-files-menu)
70 ;; The "File" menu items
71 (define-key menu-bar-files-menu [exit-emacs]
72 '(menu-item "Exit Emacs" save-buffers-kill-emacs
73 :help "Save unsaved buffers, then exit"))
75 (define-key menu-bar-files-menu [separator-exit]
76 '("--"))
78 ;; Don't use delete-frame as event name because that is a special
79 ;; event.
80 (define-key menu-bar-files-menu [delete-this-frame]
81 '(menu-item "Delete Frame" delete-frame
82 :visible (fboundp 'delete-frame)
83 :enable (delete-frame-enabled-p)
84 :help "Delete currently selected frame"))
85 (define-key menu-bar-files-menu [make-frame-on-display]
86 '(menu-item "New Frame on Display..." make-frame-on-display
87 :visible (fboundp 'make-frame-on-display)
88 :help "Open a new frame on another display"))
89 (define-key menu-bar-files-menu [make-frame]
90 '(menu-item "New Frame" make-frame-command
91 :visible (fboundp 'make-frame-command)
92 :help "Open a new frame"))
94 (define-key menu-bar-files-menu [one-window]
95 '(menu-item "Unsplit Windows" delete-other-windows
96 :enable (not (one-window-p t nil))
97 :help "Make selected window fill its frame"))
99 (define-key menu-bar-files-menu [split-window]
100 '(menu-item "Split Window" split-window-vertically
101 :help "Split selected window in two"))
103 (define-key menu-bar-files-menu [separator-window]
104 '(menu-item "--"))
106 (define-key menu-bar-files-menu [ps-print-region]
107 '(menu-item "Postscript Print Region" ps-print-region-with-faces
108 :enable mark-active
109 :help "Pretty-print marked region to PostScript printer"))
110 (define-key menu-bar-files-menu [ps-print-buffer]
111 '(menu-item "Postscript Print Buffer" ps-print-buffer-with-faces
112 :help "Pretty-print current buffer to PostScript printer"))
113 (define-key menu-bar-files-menu [print-region]
114 '(menu-item "Print Region" print-region
115 :enable mark-active
116 :help "Print region between mark and current position"))
117 (define-key menu-bar-files-menu [print-buffer]
118 '(menu-item "Print Buffer" print-buffer
119 :help "Print current buffer with page headings"))
121 (define-key menu-bar-files-menu [separator-print]
122 '(menu-item "--"))
124 (define-key menu-bar-files-menu [recover-session]
125 '(menu-item "Recover Crashed Session..." recover-session
126 :enable (and auto-save-list-file-prefix
127 (directory-files
128 (file-name-directory auto-save-list-file-prefix)
130 (concat "\\`"
131 (regexp-quote
132 (file-name-nondirectory
133 auto-save-list-file-prefix)))
135 :help "Recover edits from a crashed session"))
136 (define-key menu-bar-files-menu [revert-buffer]
137 '(menu-item "Revert Buffer" revert-buffer
138 :enable (or revert-buffer-function
139 revert-buffer-insert-file-contents-function
140 (and (buffer-file-name)
141 (or (buffer-modified-p)
142 (not (verify-visited-file-modtime
143 (current-buffer))))))
144 :help "Re-read current buffer from its file"))
145 (define-key menu-bar-files-menu [write-file]
146 '(menu-item "Save Buffer As..." write-file
147 :enable (not (window-minibuffer-p
148 (frame-selected-window menu-updating-frame)))
149 :help "Write current buffer to another file"))
150 (define-key menu-bar-files-menu [save-buffer]
151 '(menu-item "Save (current buffer)" save-buffer
152 :enable (and (buffer-modified-p)
153 (not (window-minibuffer-p
154 (frame-selected-window menu-updating-frame))))
155 :help "Save current buffer to its file"))
157 (define-key menu-bar-files-menu [separator-save]
158 '(menu-item "--"))
160 (define-key menu-bar-files-menu [kill-buffer]
161 '(menu-item "Close (current buffer)" kill-this-buffer
162 :enable (kill-this-buffer-enabled-p)
163 :help "Discard contents of current buffer"))
164 (define-key menu-bar-files-menu [insert-file]
165 '(menu-item "Insert File..." insert-file
166 :enable (not (window-minibuffer-p
167 (frame-selected-window menu-updating-frame)))
168 :help "Insert another file into current buffer"))
169 (define-key menu-bar-files-menu [dired]
170 '(menu-item "Open Directory..." dired
171 :help "Read a directory, operate on its files"))
172 (define-key menu-bar-files-menu [open-file]
173 '(menu-item "Open File..." find-file
174 :enable (not (window-minibuffer-p
175 (frame-selected-window menu-updating-frame)))
176 :help "Read a file into an Emacs buffer"))
179 ;; The "Edit" menu items
180 (defun nonincremental-search-forward (string)
181 "Read a string and search for it nonincrementally."
182 (interactive "sSearch for string: ")
183 (if (equal string "")
184 (search-forward (car search-ring))
185 (isearch-update-ring string nil)
186 (search-forward string)))
188 (defun nonincremental-search-backward (string)
189 "Read a string and search backward for it nonincrementally."
190 (interactive "sSearch for string: ")
191 (if (equal string "")
192 (search-backward (car search-ring))
193 (isearch-update-ring string nil)
194 (search-backward string)))
196 (defun nonincremental-re-search-forward (string)
197 "Read a regular expression and search for it nonincrementally."
198 (interactive "sSearch for regexp: ")
199 (if (equal string "")
200 (re-search-forward (car regexp-search-ring))
201 (isearch-update-ring string t)
202 (re-search-forward string)))
204 (defun nonincremental-re-search-backward (string)
205 "Read a regular expression and search backward for it nonincrementally."
206 (interactive "sSearch for regexp: ")
207 (if (equal string "")
208 (re-search-backward (car regexp-search-ring))
209 (isearch-update-ring string t)
210 (re-search-backward string)))
212 (defun nonincremental-repeat-search-forward ()
213 "Search forward for the previous search string."
214 (interactive)
215 (if (null search-ring)
216 (error "No previous search"))
217 (search-forward (car search-ring)))
219 (defun nonincremental-repeat-search-backward ()
220 "Search backward for the previous search string."
221 (interactive)
222 (if (null search-ring)
223 (error "No previous search"))
224 (search-backward (car search-ring)))
226 (defun nonincremental-repeat-re-search-forward ()
227 "Search forward for the previous regular expression."
228 (interactive)
229 (if (null regexp-search-ring)
230 (error "No previous search"))
231 (re-search-forward (car regexp-search-ring)))
233 (defun nonincremental-repeat-re-search-backward ()
234 "Search backward for the previous regular expression."
235 (interactive)
236 (if (null regexp-search-ring)
237 (error "No previous search"))
238 (re-search-backward (car regexp-search-ring)))
240 (defvar menu-bar-search-menu (make-sparse-keymap "Search"))
241 (defvar menu-bar-adv-search-menu
242 (make-sparse-keymap "Advanced Search/Replace"))
244 (define-key menu-bar-adv-search-menu [tags-continue]
245 '(menu-item "Continue Tags Search/Replace" tags-loop-continue
246 :help "Continue last tags search/replace operation"))
247 (define-key menu-bar-adv-search-menu [tags-repl]
248 '(menu-item "Replace in all tagged files" tags-query-replace
249 :help "Interactively replace a regexp in all tagged files"))
250 (define-key menu-bar-adv-search-menu [tags-srch]
251 '(menu-item "Search in all tagged files" tags-search
252 :help "Search for a regexp in all tagged files"))
254 (define-key menu-bar-adv-search-menu [separator-tag-search]
255 '(menu-item "--"))
257 (define-key menu-bar-adv-search-menu [query-replace-regexp]
258 '(menu-item "Replace Regexp..." query-replace-regexp
259 :enable (not buffer-read-only)
260 :help "Replace regular expression, ask about each occurrence"))
261 (define-key menu-bar-adv-search-menu [repeat-regexp-back]
262 '(menu-item "Repeat Regexp Backwards"
263 nonincremental-repeat-re-search-backward
264 :enable regexp-search-ring
265 :help "Repeat last regular expression search backwards"))
266 (define-key menu-bar-adv-search-menu [repeat-regexp-fwd]
267 '(menu-item "Repeat Regexp" nonincremental-repeat-re-search-forward
268 :enable regexp-search-ring
269 :help "Repeat last regular expression search forward"))
270 (define-key menu-bar-adv-search-menu [re-search-backward]
271 '(menu-item "Search Regexp Backwards..." nonincremental-re-search-backward
272 :help "Search backwards for a regular expression"))
273 (define-key menu-bar-adv-search-menu [re-search-forward]
274 '(menu-item "Search Regexp..." nonincremental-re-search-forward
275 :help "Search forward for a regular expression"))
276 (define-key menu-bar-search-menu [re-search]
277 (list 'menu-item "Advanced Search/Replace" menu-bar-adv-search-menu
278 :help "Regexp and Tags search and replace"))
280 (define-key menu-bar-search-menu [query-replace]
281 '(menu-item "Replace..." query-replace
282 :enable (not buffer-read-only)
283 :help "Replace string interactively, ask about each occurrence"))
284 (define-key menu-bar-search-menu [repeat-search-back]
285 '(menu-item "Repeat Backwards" nonincremental-repeat-search-backward
286 :enable search-ring
287 :help "Repeat last search backwards"))
288 (define-key menu-bar-search-menu [repeat-search-fwd]
289 '(menu-item "Repeat Search" nonincremental-repeat-search-forward
290 :enable search-ring
291 :help "Repeat last search forward"))
292 (define-key menu-bar-search-menu [search-backward]
293 '(menu-item "Search Backwards..." nonincremental-search-backward
294 :help "Search backwards for a string"))
295 (define-key menu-bar-search-menu [search-forward]
296 '(menu-item "Search..." nonincremental-search-forward
297 :help "Search forward for a string"))
299 ;;; Assemble the top-level Edit menu items.
300 (define-key menu-bar-edit-menu [props]
301 '(menu-item "Text Properties" facemenu-menu
302 :help "Change properties of text in region"))
304 (define-key menu-bar-search-menu [separator-search]
305 '(menu-item "--"))
307 (define-key menu-bar-edit-menu [bookmark]
308 '(menu-item "Bookmarks" menu-bar-bookmark-map
309 :help "Record positions and jump between them"))
311 (define-key menu-bar-edit-menu [separator-bookmark]
312 '(menu-item "--"))
314 (defvar menu-bar-goto-menu (make-sparse-keymap "Go To"))
316 (define-key menu-bar-goto-menu [set-tags-name]
317 '(menu-item "Set Tags File Name" visit-tags-table
318 :help "Tell Tags commands which tag table file to use"))
320 (define-key menu-bar-goto-menu [separator-tag-file]
321 '(menu-item "--"))
323 (define-key menu-bar-goto-menu [apropos-tags]
324 '(menu-item "Tags Apropos" tags-apropos
325 :help "Find function/variables whose names match regexp"))
326 (define-key menu-bar-goto-menu [next-tag-otherw]
327 '(menu-item "Next Tag in Other Window"
328 (function (lambda () (find-tag-other-window nil t)))
329 :enable (and (boundp 'tags-location-ring)
330 (not (ring-empty-p tags-location-ring)))
331 :help "Find next function/variable matching last tag name in another window"))
332 (define-key menu-bar-goto-menu [next-tag]
333 '(menu-item "Find Next Tag"
334 (function (lambda () (find-tag nil t)))
335 :enable (and (boundp 'tags-location-ring)
336 (not (ring-empty-p tags-location-ring)))
337 :help "Find next function/variable matching last tag name"))
338 (define-key menu-bar-goto-menu [find-tag-otherw]
339 '(menu-item "Find Tag in Other Window..." find-tag-other-window
340 :help "Find function/variable definition in another window"))
341 (define-key menu-bar-goto-menu [find-tag]
342 '(menu-item "Find Tag..." find-tag
343 :help "Find definition of function or variable"))
345 (define-key menu-bar-goto-menu [separator-tags]
346 '(menu-item "--"))
348 (define-key menu-bar-goto-menu [end-of-buf]
349 '(menu-item "Goto End of Buffer" end-of-buffer))
350 (define-key menu-bar-goto-menu [beg-of-buf]
351 '(menu-item "Goto Beginning of Buffer" beginning-of-buffer))
352 (define-key menu-bar-goto-menu [go-to-pos]
353 '(menu-item "Goto Buffer Position..." goto-char
354 :help "Read a number N and go to buffer position N"))
355 (define-key menu-bar-goto-menu [go-to-line]
356 '(menu-item "Goto Line..." goto-line
357 :help "Read a line number and go to that line"))
359 (define-key menu-bar-edit-menu [goto]
360 (list 'menu-item "Go To" menu-bar-goto-menu))
362 (define-key menu-bar-edit-menu [search]
363 (list 'menu-item "Search" menu-bar-search-menu))
365 (define-key menu-bar-edit-menu [fill]
366 '(menu-item "Fill" fill-region
367 :enable (and mark-active (not buffer-read-only))
368 :help
369 "Fill text in region to fit between left and right margin"))
370 (define-key menu-bar-edit-menu [clear]
371 '(menu-item "Clear" delete-region
372 :enable (and mark-active
373 (not buffer-read-only)
374 (not (mouse-region-match)))
375 :help
376 "Delete the text in region between mark and current pos"))
377 (defvar yank-menu (cons "Select Yank" nil))
378 (fset 'yank-menu (cons 'keymap yank-menu))
379 (define-key menu-bar-edit-menu [select-paste]
380 '(menu-item "Select and Paste" yank-menu
381 :enable (and (cdr yank-menu) (not buffer-read-only))
382 :help "Paste text cut/copied earlier"))
383 (define-key menu-bar-edit-menu [paste]
384 '(menu-item "Paste" yank
385 :enable (and (x-selection-exists-p) (not buffer-read-only))
386 :help "Paste text most recently cut/copied"))
387 (define-key menu-bar-edit-menu [copy]
388 '(menu-item "Copy" menu-bar-kill-ring-save
389 :enable mark-active
390 :help "Copy text in region between mark and current pos"))
391 (define-key menu-bar-edit-menu [cut]
392 '(menu-item "Cut" kill-region
393 :enable (and mark-active (not buffer-read-only))
394 :help "Cut (kill) text in region between mark and current pos"))
395 (define-key menu-bar-edit-menu [undo]
396 '(menu-item "Undo" undo
397 :enable (and (not buffer-read-only)
398 (not (eq t buffer-undo-list))
399 (if (eq last-command 'undo)
400 pending-undo-list
401 (consp buffer-undo-list)))
402 :help "Undo last operation"))
405 (defun menu-bar-kill-ring-save (beg end)
406 (interactive "r")
407 (if (mouse-region-match)
408 (message "Selecting a region with the mouse does `copy' automatically")
409 (kill-ring-save beg end)))
411 (autoload 'ispell-menu-map "ispell" nil t 'keymap)
413 ;; These are alternative definitions for the cut, paste and copy
414 ;; menu items. Use them if your system expects these to use the clipboard.
416 (put 'clipboard-kill-region 'menu-enable 'mark-active)
417 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
418 (put 'clipboard-yank 'menu-enable
419 '(or (x-selection-exists-p) (x-selection-exists-p 'CLIPBOARD)))
421 (defun clipboard-yank ()
422 "Insert the clipboard contents, or the last stretch of killed text."
423 (interactive)
424 (let ((x-select-enable-clipboard t))
425 (yank)))
427 (defun clipboard-kill-ring-save (beg end)
428 "Copy region to kill ring, and save in the X clipboard."
429 (interactive "r")
430 (let ((x-select-enable-clipboard t))
431 (kill-ring-save beg end)))
433 (defun clipboard-kill-region (beg end)
434 "Kill the region, and save it in the X clipboard."
435 (interactive "r")
436 (let ((x-select-enable-clipboard t))
437 (kill-region beg end)))
439 (defun menu-bar-enable-clipboard ()
440 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
441 Do the same for the keys of the same name."
442 (interactive)
443 ;; We can't use constant list structure here because it becomes pure,
444 ;; and because it gets modified with cache data.
445 (define-key menu-bar-edit-menu [paste]
446 (cons "Paste" (cons "Paste text from clipboard" 'clipboard-yank)))
447 (define-key menu-bar-edit-menu [copy]
448 (cons "Copy" (cons "Copy text in region to the clipboard"
449 'clipboard-kill-ring-save)))
450 (define-key menu-bar-edit-menu [cut]
451 (cons "Cut" (cons "Delete text in region and copy it to the clipboard"
452 'clipboard-kill-region)))
454 (define-key global-map [f20] 'clipboard-kill-region)
455 (define-key global-map [f16] 'clipboard-kill-ring-save)
456 (define-key global-map [f18] 'clipboard-yank)
457 ;; X11R6 versions
458 (define-key global-map [cut] 'clipboard-kill-region)
459 (define-key global-map [copy] 'clipboard-kill-ring-save)
460 (define-key global-map [paste] 'clipboard-yank))
462 ;; The "Options" menu items
464 (defvar menu-bar-custom-menu (make-sparse-keymap "Customize"))
466 (define-key menu-bar-custom-menu [customize-apropos-groups]
467 '(menu-item "Groups Matching Regexp..." customize-apropos-groups
468 :help "Browse groups whose names match regexp"))
469 (define-key menu-bar-custom-menu [customize-apropos-faces]
470 '(menu-item "Faces Matching Regexp..." customize-apropos-faces
471 :help "Browse faces whose names match regexp"))
472 (define-key menu-bar-custom-menu [customize-apropos-options]
473 '(menu-item "Options Matching Regexp..." customize-apropos-options
474 :help "Browse options whose names match regexp"))
475 (define-key menu-bar-custom-menu [customize-apropos]
476 '(menu-item "Settings Matching Regexp..." customize-apropos
477 :help "Browse customizable settings whose names match regexp"))
478 (define-key menu-bar-custom-menu [separator-2]
479 '("--"))
480 (define-key menu-bar-custom-menu [customize-group]
481 '(menu-item "Specific Group..." customize-group
482 :help "Customize settings of specific group"))
483 (define-key menu-bar-custom-menu [customize-face]
484 '(menu-item "Specific Face..." customize-face
485 :help "Customize attributes of specific face"))
486 (define-key menu-bar-custom-menu [customize-option]
487 '(menu-item "Specific Option..." customize-option
488 :help "Change value of specific option"))
489 (define-key menu-bar-custom-menu [customize-changed-options]
490 '(menu-item "Recently Changed Options..." customize-changed-options
491 :help "Customize options changed in recent versions"))
492 (define-key menu-bar-custom-menu [separator-3]
493 '("--"))
494 (define-key menu-bar-custom-menu [customize-browse]
495 '(menu-item "Browse Customization Groups" customize-browse
496 :help "Browse all customization groups"))
497 (define-key menu-bar-custom-menu [customize]
498 '(menu-item "Top-level Customization Group" customize
499 :help "The master group called `Emacs'"))
501 ;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
503 (defmacro menu-bar-make-toggle (name variable doc message help &rest body)
504 `(progn
505 (defun ,name ()
506 ,(concat doc ".")
507 (interactive)
508 (if ,(if body `(progn . ,body)
509 `(setq ,variable (not ,variable)))
510 (message ,message "enabled")
511 (message ,message "disabled")))
512 '(menu-item ,doc ,name
513 :help ,help
514 :button (:toggle . (and (boundp ',variable) ,variable)))))
516 ;;; Assemble all the top-level items of the "Options" menu
517 (define-key menu-bar-options-menu [customize]
518 (list 'menu-item "Customize Emacs" menu-bar-custom-menu
519 :help "Full customization of every Emacs feature"))
520 (define-key menu-bar-options-menu [mule]
521 ;; It is better not to use backquote here,
522 ;; because that makes a bootstrapping problem
523 ;; if you need to recompile all the Lisp files using interpreted code.
524 (list 'menu-item "Mule (Multilingual Environment)" mule-menu-keymap
525 ':visible 'default-enable-multibyte-characters
526 ':help "Default language, encodings, input method"))
527 ;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
528 ;(define-key menu-bar-options-menu [preferences]
529 ; (list 'menu-item "Preferences" menu-bar-preferences-menu
530 ; :help "Toggle important global options"))
532 (define-key menu-bar-options-menu [mule-separator]
533 '("------"))
535 (define-key menu-bar-options-menu [debug-on-quit]
536 (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
537 "Enter Debugger on Quit/C-g" "Debug on Quit %s"
538 "Enter Lisp debugger when C-g is pressed"))
539 (define-key menu-bar-options-menu [debug-on-error]
540 (menu-bar-make-toggle toggle-debug-on-error debug-on-error
541 "Enter Debugger on Error" "Debug on Error %s"
542 "Enter Lisp debugger when error is signaled"))
543 (define-key menu-bar-options-menu [debugger-separator]
544 '("--"))
545 (define-key menu-bar-options-menu [toggle-auto-compression]
546 '(menu-item "Automatic File De/compression"
547 auto-compression-mode
548 :help "Transparently decompress compressed files"
549 :button (:toggle . (rassq 'jka-compr-handler
550 file-name-handler-alist))))
551 (define-key menu-bar-options-menu [save-place]
552 (menu-bar-make-toggle toggle-save-place-globally save-place
553 "Save Place in Files between Sessions"
554 "Saving place in files %s"
555 "Save Emacs state for next session"
556 (require 'saveplace)
557 (setq-default save-place (not (default-value save-place)))))
558 (define-key menu-bar-options-menu [uniquify]
559 (menu-bar-make-toggle toggle-uniquify-buffer-names uniquify-buffer-name-style
560 "Use Directory Names in Buffer Names"
561 "Directory name in buffer names (uniquify) %s"
563 (require 'uniquify)
564 (setq uniquify-buffer-name-style
565 (if (not uniquify-buffer-name-style)
566 'forward))))
567 (define-key menu-bar-options-menu [edit-options-separator]
568 '("--"))
569 (define-key menu-bar-options-menu [case-fold-search]
570 (menu-bar-make-toggle toggle-case-fold-search case-fold-search
571 "Case-Insensitive Search"
572 "Case-Insensitive Search %s"
573 "If checked, search ignores letter-case"))
574 (define-key menu-bar-options-menu [auto-fill-mode]
575 '(menu-item "Word Wrap in Text Modes (Auto Fill)"
576 toggle-text-mode-auto-fill
577 :help "Automatically fill text between left and right margins"
578 :button (:toggle . (member 'turn-on-auto-fill text-mode-hook))))
579 (define-key menu-bar-options-menu [truncate-lines]
580 (menu-bar-make-toggle
581 toggle-truncate-lines truncate-lines
582 "Truncate Long Lines" "Long Line Truncation %s"
583 "If checked, long lines are truncated on the screen"
584 (prog1 (setq truncate-lines (not truncate-lines))
585 (set-buffer-modified-p (buffer-modified-p)))))
586 (define-key menu-bar-options-menu [highlight-separator]
587 '("--"))
588 (define-key menu-bar-options-menu [highlight-paren-mode]
589 (menu-bar-make-toggle toggle-highlight-paren-mode show-paren-mode
590 "Highlight Matching Parentheses"
591 "Show Paren mode %s"
592 "Highlight matching and mismatched parentheses"))
593 (define-key menu-bar-options-menu [transient-mark-mode]
594 (menu-bar-make-toggle toggle-transient-mark-mode transient-mark-mode
595 "Transient Mark Mode (highlights region)"
596 "Transient Mark mode %s"
597 "Highlight the marked region when it's active"))
598 (define-key menu-bar-options-menu [toggle-global-lazy-font-lock-mode]
599 (menu-bar-make-toggle toggle-global-lazy-font-lock-mode global-font-lock-mode
600 "Highlight Syntax (Global Font Lock)"
601 "Syntax Highlighting %s"
602 "Highlights text based on language syntax"
603 ;; Make sure a support mode is used;
604 ;; otherwise Font Lock will be too slow.
605 (require 'font-lock)
606 (if (not global-font-lock-mode)
607 (or font-lock-support-mode
608 (setq font-lock-support-mode 'lazy-lock-mode)))
609 (global-font-lock-mode)))
613 ;; The "Tools" menu items
615 (defvar menu-bar-games-menu (make-sparse-keymap "Games"))
617 (define-key menu-bar-tools-menu [games]
618 (list 'menu-item "Games" menu-bar-games-menu))
620 (define-key menu-bar-tools-menu [separator-games]
621 '("--"))
623 (define-key menu-bar-games-menu [yow]
624 '(menu-item "Random Quotation" yow
625 :help "Display a random Zippy quotation"))
626 (define-key menu-bar-games-menu [tetris]
627 '(menu-item "Tetris" tetris))
628 (define-key menu-bar-games-menu [solitaire]
629 '(menu-item "Solitaire" solitaire))
630 (define-key menu-bar-games-menu [snake]
631 '(menu-item "Snake" snake
632 :help "Move snake around avoiding collisions"))
633 (define-key menu-bar-games-menu [mult]
634 '(menu-item "Multiplication Puzzle" mpuz
635 :help "Excercise brain with multiplication"))
636 (define-key menu-bar-games-menu [life]
637 '(menu-item "Life" life
638 :help "Watch how John Conway's cellular automaton evolves"))
639 (define-key menu-bar-games-menu [hanoi]
640 '(menu-item "Towers of Hanoi" hanoi
641 :help "Watch Towers-of-Hanoi puzzle solved by Emacs"))
642 (define-key menu-bar-games-menu [gomoku]
643 '(menu-item "Gomoku" gomoku
644 :help "Mark 5 contiguous squares (like tic-tac-toe)"))
645 (define-key menu-bar-games-menu [black-box]
646 '(menu-item "Blackbox" blackbox
647 :help "Find balls in a black box by shooting rays"))
648 (define-key menu-bar-games-menu [adventure]
649 '(menu-item "Adventure" dunnet
650 :help "Dunnet, a text Adventure game for Emacs"))
651 (define-key menu-bar-games-menu [5x5]
652 '(menu-item "5x5" 5x5
653 :help "Fill in all the squares on a 5x5 board"))
655 (define-key menu-bar-tools-menu [calendar]
656 '(menu-item "Display Calendar" calendar))
657 (define-key menu-bar-tools-menu [speedbar]
658 '(menu-item "Display Speedbar" speedbar-frame-mode))
659 (define-key menu-bar-tools-menu [directory-search]
660 '(menu-item "Directory Search" eudc-tools-menu
661 :help "Query directory servers via LDAP, CCSO PH/QI or BBDB"))
662 (define-key menu-bar-tools-menu [compose-mail]
663 '(menu-item "Send Mail" compose-mail
664 :help "Send a mail message"))
665 (define-key menu-bar-tools-menu [rmail]
666 '(menu-item "Read Mail" read-mail-command
667 :help "Read your mail and reply to it"))
668 (define-key menu-bar-tools-menu [gnus]
669 '(menu-item "Read Net News" gnus
670 :help "Read network news groups"))
672 (define-key menu-bar-tools-menu [separator-vc]
673 '("--"))
675 (defvar vc-menu-map (make-sparse-keymap "Version Control"))
676 (define-key menu-bar-tools-menu [pcl-cvs]
677 `(menu-item "PCL-CVS" ,cvs-global-menu
678 :help "Module-level interface to CVS"))
679 (define-key menu-bar-tools-menu [vc]
680 (list 'menu-item "Version Control" vc-menu-map
681 :help "Interface to RCS, CVS, SCCS"))
683 (define-key menu-bar-tools-menu [separator-compare]
684 '("--"))
686 (define-key menu-bar-tools-menu [ediff-misc]
687 '(menu-item "Ediff Miscellanea" menu-bar-ediff-misc-menu
688 :help "Ediff manual, customization, sessions, etc."))
689 (define-key menu-bar-tools-menu [epatch]
690 '(menu-item "Apply Patch" menu-bar-epatch-menu))
691 (define-key menu-bar-tools-menu [ediff-merge]
692 '(menu-item "Merge" menu-bar-ediff-merge-menu
693 :help "Merge different revisions of files/directories"))
694 (define-key menu-bar-tools-menu [compare]
695 '(menu-item "Compare (Ediff)" menu-bar-ediff-menu
696 :help "Display differences between files/directories"))
699 (define-key menu-bar-tools-menu [separator-spell]
700 '("--"))
702 (define-key menu-bar-tools-menu [spell]
703 '(menu-item "Spell Checking" ispell-menu-map))
705 (define-key menu-bar-tools-menu [separator-prog]
706 '("--"))
708 (define-key menu-bar-tools-menu [gdb]
709 '(menu-item "Debugger (GUD)..." gdb
710 :help "Debug a program from withing Emacs"))
711 (define-key menu-bar-tools-menu [shell-on-region]
712 '(menu-item "Shell Command on Region..." shell-command-on-region
713 :enable mark-active
714 :help "Pass marked region to a shell command"))
715 (define-key menu-bar-tools-menu [shell]
716 '(menu-item "Shell Command..." shell-command
717 :help "Invoke a shell command and catch its output"))
718 (define-key menu-bar-tools-menu [compile]
719 '(menu-item "Compile..." compile
720 :help "Invoke compiler or Make, view compilation errors"))
721 (define-key menu-bar-tools-menu [grep]
722 '(menu-item "Search Files (Grep)..." grep
723 :help "Search files for strings or regexps (with Grep)"))
726 ;; The "Help" menu items
728 (defvar menu-bar-describe-menu (make-sparse-keymap "Describe"))
730 (define-key menu-bar-describe-menu [mule-diag]
731 '(menu-item "Show All of Mule Status" mule-diag
732 :visible default-enable-multibyte-characters
733 :help "Display multilingual environment settings"))
734 (define-key menu-bar-describe-menu [describe-coding-system]
735 '(menu-item "Describe Coding System..." describe-coding-system
736 :visible default-enable-multibyte-characters))
737 (define-key menu-bar-describe-menu [describe-input-method]
738 '(menu-item "Describe Input Method..." describe-input-method
739 :visible default-enable-multibyte-characters
740 :help "Keyboard layout for specific input method"))
741 (define-key menu-bar-describe-menu [describe-language-environment]
742 '(menu-item "Describe Language Environment" describe-language-environment-map
743 :visible default-enable-multibyte-characters))
745 (define-key menu-bar-describe-menu [separator-desc-mule]
746 '(menu-item "--" nil :visible default-enable-multibyte-characters))
748 (define-key menu-bar-describe-menu [list-keybindings]
749 '(menu-item "List Key Bindings" describe-bindings
750 :help "Display a list of all current keybindings"))
751 (define-key menu-bar-describe-menu [list-keybindings]
752 '(menu-item "List Key Bindings" describe-bindings
753 :help "Display a list of all current keybindings"))
754 (define-key menu-bar-describe-menu [describe-variable]
755 '(menu-item "Describe Variable..." describe-variable
756 :help "Display documentation of variable/option"))
757 (define-key menu-bar-describe-menu [describe-function]
758 '(menu-item "Describe Function..." describe-function
759 :help "Display documentation of function/command"))
760 (define-key menu-bar-describe-menu [describe-key]
761 '(menu-item "Describe Key..." describe-key
762 :help "Display documentation of command bound to key"))
763 (define-key menu-bar-describe-menu [apropos-variables]
764 '(menu-item "Apropos Variables..." apropos-variable
765 :help "List variables whose names match a regexp"))
766 (define-key menu-bar-describe-menu [apropos-commands]
767 '(menu-item "Apropos Commands..." apropos-command
768 :help "List commands whose names match a regexp"))
769 (define-key menu-bar-describe-menu [describe-mode]
770 '(menu-item "Describe Buffer Modes" describe-mode
771 :help "Describe this buffer's major and minor mode"))
773 (defvar menu-bar-manuals-menu (make-sparse-keymap "Manuals"))
775 (define-key menu-bar-manuals-menu [man]
776 '(menu-item "Read Man Page..." manual-entry
777 :help "Man-page docs for external commands and libraries"))
778 (define-key menu-bar-manuals-menu [sep2]
779 '("--"))
780 (define-key menu-bar-manuals-menu [info]
781 '(menu-item "Browse Manuals with Info" info
782 :help "Read any of the installed manuals"))
783 (define-key menu-bar-manuals-menu [command]
784 '(menu-item "Find Command in Manual" Info-goto-emacs-command-node
785 :help "Display manual section that describes a command"))
786 (define-key menu-bar-manuals-menu [key]
787 '(menu-item "Find Key in Manual" Info-goto-emacs-key-command-node
788 :help "Display manual section that describes a key"))
790 (define-key menu-bar-help-menu [eliza]
791 '(menu-item "Emacs Psychiatrist" doctor
792 :help "Our doctor will help you feel better"))
793 (define-key menu-bar-help-menu [sep3]
794 '("--"))
795 (define-key menu-bar-help-menu [describe-no-warranty]
796 '(menu-item "(Non)Warranty" describe-no-warranty
797 :help "Explain that Emacs has NO WARRANTY"))
798 (define-key menu-bar-help-menu [describe-copying]
799 '(menu-item "Copying Conditions" describe-copying
800 :help "Show the Emacs license (GPL)"))
801 (define-key menu-bar-help-menu [describe-distribution]
802 '(menu-item "Getting New Versions" describe-distribution
803 :help "How to get latest versions of Emacs"))
804 (define-key menu-bar-help-menu [emacs-version]
805 '(menu-item "Show Emacs Version" emacs-version))
806 (define-key menu-bar-help-menu [sep2]
807 '("--"))
808 (define-key menu-bar-help-menu [finder-by-keyword]
809 '(menu-item "Find Emacs Packages..." finder-by-keyword
810 :help "Find packages and features by keyword"))
811 (define-key menu-bar-help-menu [describe]
812 (list 'menu-item "Describe" menu-bar-describe-menu
813 :help "Describe commands, variables, keys"))
814 (define-key menu-bar-help-menu [manuals]
815 (list 'menu-item "Manuals" menu-bar-manuals-menu))
816 (define-key menu-bar-help-menu [sep1]
817 '("--"))
818 (define-key menu-bar-help-menu [report-emacs-bug]
819 '(menu-item "Send Bug Report..." report-emacs-bug
820 :help "Send e-mail to Emacs maintainers"))
821 (define-key menu-bar-help-menu [emacs-problems]
822 '(menu-item "Emacs Known Problems" view-emacs-problems))
823 (define-key menu-bar-help-menu [emacs-news]
824 '(menu-item "Emacs News" view-emacs-news
825 :help "New features of this version"))
826 (define-key menu-bar-help-menu [emacs-faq]
827 '(menu-item "Emacs FAQ" view-emacs-FAQ))
828 (define-key menu-bar-help-menu [emacs-tutorial]
829 '(menu-item "Emacs Tutorial" help-with-tutorial
830 :help "Learn how to use Emacs"))
832 (defun kill-this-buffer () ; for the menubar
833 "Kills the current buffer."
834 (interactive)
835 (kill-buffer (current-buffer)))
837 (defun kill-this-buffer-enabled-p ()
838 (let ((count 0)
839 (buffers (buffer-list)))
840 (while buffers
841 (or (string-match "^ " (buffer-name (car buffers)))
842 (setq count (1+ count)))
843 (setq buffers (cdr buffers)))
844 (and (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
845 (> count 1))))
847 (put 'dired 'menu-enable
848 '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
850 ;; Permit deleting frame if it would leave a visible or iconified frame.
851 (defun delete-frame-enabled-p ()
852 "Return non-nil if `delete-frame' should be enabled in the menu bar."
853 (let ((frames (frame-list))
854 (count 0))
855 (while frames
856 (if (frame-visible-p (car frames))
857 (setq count (1+ count)))
858 (setq frames (cdr frames)))
859 (> count 1)))
861 (defcustom yank-menu-length 20
862 "*Maximum length to display in the yank-menu."
863 :type 'integer
864 :group 'mouse)
866 (defun menu-bar-update-yank-menu (string old)
867 (let ((front (car (cdr yank-menu)))
868 (menu-string (if (<= (length string) yank-menu-length)
869 string
870 (concat
871 (substring string 0 (/ yank-menu-length 2))
872 "..."
873 (substring string (- (/ yank-menu-length 2)))))))
874 ;; Don't let the menu string be all dashes
875 ;; because that has a special meaning in a menu.
876 (if (string-match "\\`-+\\'" menu-string)
877 (setq menu-string (concat menu-string " ")))
878 ;; If we're supposed to be extending an existing string, and that
879 ;; string really is at the front of the menu, then update it in place.
880 (if (and old (or (eq old (car front))
881 (string= old (car front))))
882 (progn
883 (setcar front string)
884 (setcar (cdr front) menu-string))
885 (setcdr yank-menu
886 (cons
887 (cons string (cons menu-string 'menu-bar-select-yank))
888 (cdr yank-menu)))))
889 (if (> (length (cdr yank-menu)) kill-ring-max)
890 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
892 (put 'menu-bar-select-yank 'apropos-inhibit t)
893 (defun menu-bar-select-yank ()
894 (interactive "*")
895 (push-mark (point))
896 (insert last-command-event))
898 (defvar list-buffers-directory nil)
900 (defvar menu-bar-update-buffers-maxbuf)
902 (defun menu-bar-select-buffer ()
903 (interactive)
904 (switch-to-buffer last-command-event))
906 (defun menu-bar-select-frame ()
907 (interactive)
908 (make-frame-visible last-command-event)
909 (raise-frame last-command-event)
910 (select-frame last-command-event))
912 (defun menu-bar-update-buffers-1 (elt)
913 (cons (format
914 (format "%%%ds %%s%%s %%s" menu-bar-update-buffers-maxbuf)
915 (cdr elt)
916 (if (buffer-modified-p (car elt))
917 "*" " ")
918 (save-excursion
919 (set-buffer (car elt))
920 (if buffer-read-only "%" " "))
921 (let ((file
922 (or (buffer-file-name (car elt))
923 (save-excursion
924 (set-buffer (car elt))
925 list-buffers-directory)
926 "")))
927 (setq file (or (file-name-directory file)
928 ""))
929 (if (> (length file) 20)
930 (setq file (concat "..." (substring file -17))))
931 file))
932 (car elt)))
934 (defvar menu-bar-buffers-menu-list-buffers-entry nil)
936 (defun menu-bar-update-buffers ()
937 ;; If user discards the Buffers item, play along.
938 (and (lookup-key (current-global-map) [menu-bar buffer])
939 (frame-or-buffer-changed-p)
940 (let ((buffers (buffer-list))
941 (frames (frame-list))
942 (maxlen 0)
943 buffers-menu frames-menu)
944 ;; If requested, list only the N most recently selected buffers.
945 (if (and (integerp buffers-menu-max-size)
946 (> buffers-menu-max-size 1))
947 (if (> (length buffers) buffers-menu-max-size)
948 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
950 ;; Make the menu of buffers proper.
951 (setq buffers-menu
952 (cons "Select Buffer"
953 (let* ((buffer-list
954 (mapcar 'list buffers))
955 tail
956 (menu-bar-update-buffers-maxbuf 0)
957 alist
958 head)
959 ;; Put into each element of buffer-list
960 ;; the name for actual display,
961 ;; perhaps truncated in the middle.
962 (setq tail buffer-list)
963 (while tail
964 (let ((name (buffer-name (car (car tail)))))
965 (setcdr (car tail)
966 (if (> (length name) 27)
967 (concat (substring name 0 12)
968 "..."
969 (substring name -12))
970 name)))
971 (setq tail (cdr tail)))
972 ;; Compute the maximum length of any name.
973 (setq tail buffer-list)
974 (while tail
975 (or (eq ?\ (aref (cdr (car tail)) 0))
976 (setq menu-bar-update-buffers-maxbuf
977 (max menu-bar-update-buffers-maxbuf
978 (length (cdr (car tail))))))
979 (setq tail (cdr tail)))
980 ;; Set ALIST to an alist of the form
981 ;; ITEM-STRING . BUFFER
982 (setq tail buffer-list)
983 (while tail
984 (let ((elt (car tail)))
985 (or (eq ?\ (aref (cdr elt) 0))
986 (setq alist (cons
987 (menu-bar-update-buffers-1 elt)
988 alist)))
989 (and alist (> (length (car (car alist))) maxlen)
990 (setq maxlen (length (car (car alist))))))
991 (setq tail (cdr tail)))
992 (setq alist (nreverse alist))
993 ;; Make the menu item for list-buffers
994 ;; or reuse the one we already have.
995 ;; The advantage in reusing one
996 ;; is that it already has the keyboard equivalent
997 ;; cached, so we save the time to look that up again.
998 (or menu-bar-buffers-menu-list-buffers-entry
999 (setq menu-bar-buffers-menu-list-buffers-entry
1000 (cons
1001 'list-buffers
1002 (cons
1004 'list-buffers))))
1005 ;; Update the item string for menu's new width.
1006 (setcar (cdr menu-bar-buffers-menu-list-buffers-entry)
1007 (concat (make-string (max (- (/ maxlen 2) 8) 0)
1008 ?\ )
1009 "List All Buffers"))
1010 ;; Now make the actual list of items,
1011 ;; ending with the list-buffers item.
1012 (nconc (mapcar '(lambda (pair)
1013 ;; This is somewhat risque, to use
1014 ;; the buffer name itself as the event
1015 ;; type to define, but it works.
1016 ;; It would not work to use the buffer
1017 ;; since a buffer as an event has its
1018 ;; own meaning.
1019 (nconc (list (buffer-name (cdr pair))
1020 (car pair)
1021 (cons nil nil))
1022 'menu-bar-select-buffer))
1023 alist)
1024 (list menu-bar-buffers-menu-list-buffers-entry)))))
1027 ;; Make a Frames menu if we have more than one frame.
1028 (if (cdr frames)
1029 (let ((name (concat (make-string (max (- (/ maxlen 2) 3) 0)
1030 ?\ )
1031 "Frames"))
1032 (frames-menu
1033 (cons 'keymap
1034 (cons "Select Frame"
1035 (mapcar '(lambda (frame)
1036 (nconc (list frame
1037 (cdr (assq 'name
1038 (frame-parameters frame)))
1039 (cons nil nil))
1040 'menu-bar-select-frame))
1041 frames)))))
1042 ;; Put it underneath the Buffers menu.
1043 (setq buffers-menu (cons (cons 'frames (cons name frames-menu))
1044 buffers-menu))))
1045 (if buffers-menu
1046 (setq buffers-menu (cons 'keymap buffers-menu)))
1047 (define-key (current-global-map) [menu-bar buffer]
1048 (cons "Buffers" buffers-menu)))))
1050 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
1052 (menu-bar-update-buffers)
1054 ;; this version is too slow
1055 ;;;(defun format-buffers-menu-line (buffer)
1056 ;;; "Returns a string to represent the given buffer in the Buffer menu.
1057 ;;;nil means the buffer shouldn't be listed. You can redefine this."
1058 ;;; (if (string-match "\\` " (buffer-name buffer))
1059 ;;; nil
1060 ;;; (save-excursion
1061 ;;; (set-buffer buffer)
1062 ;;; (let ((size (buffer-size)))
1063 ;;; (format "%s%s %-19s %6s %-15s %s"
1064 ;;; (if (buffer-modified-p) "*" " ")
1065 ;;; (if buffer-read-only "%" " ")
1066 ;;; (buffer-name)
1067 ;;; size
1068 ;;; mode-name
1069 ;;; (or (buffer-file-name) ""))))))
1071 ;;; Set up a menu bar menu for the minibuffer.
1073 (mapcar
1074 (function
1075 (lambda (map)
1076 (define-key map [menu-bar minibuf]
1077 (cons "Minibuf" (make-sparse-keymap "Minibuf")))))
1078 (list minibuffer-local-ns-map
1079 minibuffer-local-must-match-map
1080 minibuffer-local-isearch-map
1081 minibuffer-local-map
1082 minibuffer-local-completion-map))
1084 (mapcar
1085 (function
1086 (lambda (map)
1087 (define-key map [menu-bar minibuf ?\?]
1088 (list 'menu-item "List Completions" 'minibuffer-completion-help
1089 :help "Display all possible completions"))
1090 (define-key map [menu-bar minibuf space]
1091 (list 'menu-item "Complete Word" 'minibuffer-complete-word
1092 :help "Complete at most one word"))
1093 (define-key map [menu-bar minibuf tab]
1094 (list 'menu-item "Complete" 'minibuffer-complete
1095 :help "Complete as far as possible"))
1097 (list minibuffer-local-must-match-map
1098 minibuffer-local-completion-map))
1100 (mapcar
1101 (function
1102 (lambda (map)
1103 (define-key map [menu-bar minibuf quit]
1104 (list 'menu-item "Quit" 'keyboard-escape-quit
1105 :help "Abort input and exit minibuffer"))
1106 (define-key map [menu-bar minibuf return]
1107 (list 'menu-item "Enter" 'exit-minibuffer
1108 :help "Terminate input and exit minibuffer"))
1110 (list minibuffer-local-ns-map
1111 minibuffer-local-must-match-map
1112 minibuffer-local-isearch-map
1113 minibuffer-local-map
1114 minibuffer-local-completion-map))
1116 (defcustom menu-bar-mode nil
1117 "Toggle display of a menu bar on each frame.
1118 Setting this variable directly does not take effect;
1119 use either \\[customize] or the function `menu-bar-mode'."
1120 :set (lambda (symbol value)
1121 (menu-bar-mode (or value 0)))
1122 :initialize 'custom-initialize-default
1123 :type 'boolean
1124 :group 'frames)
1126 (defun menu-bar-mode (flag)
1127 "Toggle display of a menu bar on each frame.
1128 This command applies to all frames that exist and frames to be
1129 created in the future.
1130 With a numeric argument, if the argument is positive,
1131 turn on menu bars; otherwise, turn off menu bars."
1132 (interactive "P")
1134 ;; Make menu-bar-mode and default-frame-alist consistent.
1135 (let ((default (assq 'menu-bar-lines default-frame-alist)))
1136 (if default
1137 (setq menu-bar-mode (not (eq (cdr default) 0)))
1138 (setq default-frame-alist
1139 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
1140 default-frame-alist))))
1142 ;; Toggle or set the mode, according to FLAG.
1143 (setq menu-bar-mode (if (null flag) (not menu-bar-mode)
1144 (> (prefix-numeric-value flag) 0)))
1146 ;; Apply it to default-frame-alist.
1147 (let ((parameter (assq 'menu-bar-lines default-frame-alist)))
1148 (if (consp parameter)
1149 (setcdr parameter (if menu-bar-mode 1 0))
1150 (setq default-frame-alist
1151 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
1152 default-frame-alist))))
1154 ;; Apply it to existing frames.
1155 (let ((frames (frame-list)))
1156 (while frames
1157 (let ((height (cdr (assq 'height (frame-parameters (car frames))))))
1158 (modify-frame-parameters (car frames)
1159 (list (cons 'menu-bar-lines
1160 (if menu-bar-mode 1 0))))
1161 (modify-frame-parameters (car frames)
1162 (list (cons 'height height))))
1163 (setq frames (cdr frames)))))
1165 (provide 'menu-bar)
1167 ;;; menu-bar.el ends here