Update the copyright.
[emacs.git] / lisp / menu-bar.el
blobc9595f6ab3de8ec195ed4518bd2fe8c486f30a1d
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 [vc]
677 (list 'menu-item "Version Control" vc-menu-map
678 :help "Interface to RCS, CVS, SCCS"))
680 (define-key menu-bar-tools-menu [separator-compare]
681 '("--"))
683 (define-key menu-bar-tools-menu [ediff-misc]
684 '(menu-item "Ediff Miscellanea" menu-bar-ediff-misc-menu
685 :help "Ediff manual, customization, sessions, etc."))
686 (define-key menu-bar-tools-menu [epatch]
687 '(menu-item "Apply Patch" menu-bar-epatch-menu))
688 (define-key menu-bar-tools-menu [ediff-merge]
689 '(menu-item "Merge" menu-bar-ediff-merge-menu
690 :help "Merge different revisions of files/directories"))
691 (define-key menu-bar-tools-menu [compare]
692 '(menu-item "Compare (Ediff)" menu-bar-ediff-menu
693 :help "Display differences between files/directories"))
696 (define-key menu-bar-tools-menu [separator-spell]
697 '("--"))
699 (define-key menu-bar-tools-menu [spell]
700 '(menu-item "Spell Checking" ispell-menu-map))
702 (define-key menu-bar-tools-menu [separator-prog]
703 '("--"))
705 (define-key menu-bar-tools-menu [gdb]
706 '(menu-item "Debugger (GUD)..." gdb
707 :help "Debug a program from withing Emacs"))
708 (define-key menu-bar-tools-menu [shell-on-region]
709 '(menu-item "Shell Command on Region..." shell-command-on-region
710 :enable mark-active
711 :help "Pass marked region to a shell command"))
712 (define-key menu-bar-tools-menu [shell]
713 '(menu-item "Shell Command..." shell-command
714 :help "Invoke a shell command and catch its output"))
715 (define-key menu-bar-tools-menu [compile]
716 '(menu-item "Compile..." compile
717 :help "Invoke compiler or Make, view compilation errors"))
718 (define-key menu-bar-tools-menu [grep]
719 '(menu-item "Search Files (Grep)..." grep
720 :help "Search files for strings or regexps (with Grep)"))
723 ;; The "Help" menu items
725 (defvar menu-bar-describe-menu (make-sparse-keymap "Describe"))
727 (define-key menu-bar-describe-menu [mule-diag]
728 '(menu-item "Show All of Mule Status" mule-diag
729 :visible default-enable-multibyte-characters
730 :help "Display multilingual environment settings"))
731 (define-key menu-bar-describe-menu [describe-coding-system]
732 '(menu-item "Describe Coding System..." describe-coding-system
733 :visible default-enable-multibyte-characters))
734 (define-key menu-bar-describe-menu [describe-input-method]
735 '(menu-item "Describe Input Method..." describe-input-method
736 :visible default-enable-multibyte-characters
737 :help "Keyboard layout for specific input method"))
738 (define-key menu-bar-describe-menu [describe-language-environment]
739 '(menu-item "Describe Language Environment" describe-language-environment-map
740 :visible default-enable-multibyte-characters))
742 (define-key menu-bar-describe-menu [separator-desc-mule]
743 '(menu-item "--" nil :visible default-enable-multibyte-characters))
745 (define-key menu-bar-describe-menu [list-keybindings]
746 '(menu-item "List Key Bindings" describe-bindings
747 :help "Display a list of all current keybindings"))
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 [describe-variable]
752 '(menu-item "Describe Variable..." describe-variable
753 :help "Display documentation of variable/option"))
754 (define-key menu-bar-describe-menu [describe-function]
755 '(menu-item "Describe Function..." describe-function
756 :help "Display documentation of function/command"))
757 (define-key menu-bar-describe-menu [describe-key]
758 '(menu-item "Describe Key..." describe-key
759 :help "Display documentation of command bound to key"))
760 (define-key menu-bar-describe-menu [apropos-variables]
761 '(menu-item "Apropos Variables..." apropos-variable
762 :help "List variables whose names match a regexp"))
763 (define-key menu-bar-describe-menu [apropos-commands]
764 '(menu-item "Apropos Commands..." apropos-command
765 :help "List commands whose names match a regexp"))
766 (define-key menu-bar-describe-menu [describe-mode]
767 '(menu-item "Describe Buffer Modes" describe-mode
768 :help "Describe this buffer's major and minor mode"))
770 (defvar menu-bar-manuals-menu (make-sparse-keymap "Manuals"))
772 (define-key menu-bar-manuals-menu [man]
773 '(menu-item "Read Man Page..." manual-entry
774 :help "Man-page docs for external commands and libraries"))
775 (define-key menu-bar-manuals-menu [sep2]
776 '("--"))
777 (define-key menu-bar-manuals-menu [info]
778 '(menu-item "Browse Manuals with Info" info
779 :help "Read any of the installed manuals"))
780 (define-key menu-bar-manuals-menu [command]
781 '(menu-item "Find Command in Manual" Info-goto-emacs-command-node
782 :help "Display manual section that describes a command"))
783 (define-key menu-bar-manuals-menu [key]
784 '(menu-item "Find Key in Manual" Info-goto-emacs-key-command-node
785 :help "Display manual section that describes a key"))
787 (define-key menu-bar-help-menu [eliza]
788 '(menu-item "Emacs Psychiatrist" doctor
789 :help "Our doctor will help you feel better"))
790 (define-key menu-bar-help-menu [sep3]
791 '("--"))
792 (define-key menu-bar-help-menu [describe-no-warranty]
793 '(menu-item "(Non)Warranty" describe-no-warranty
794 :help "Explain that Emacs has NO WARRANTY"))
795 (define-key menu-bar-help-menu [describe-copying]
796 '(menu-item "Copying Conditions" describe-copying
797 :help "Show the Emacs license (GPL)"))
798 (define-key menu-bar-help-menu [describe-distribution]
799 '(menu-item "Getting New Versions" describe-distribution
800 :help "How to get latest versions of Emacs"))
801 (define-key menu-bar-help-menu [emacs-version]
802 '(menu-item "Show Emacs Version" emacs-version))
803 (define-key menu-bar-help-menu [sep2]
804 '("--"))
805 (define-key menu-bar-help-menu [finder-by-keyword]
806 '(menu-item "Find Emacs Packages..." finder-by-keyword
807 :help "Find packages and features by keyword"))
808 (define-key menu-bar-help-menu [describe]
809 (list 'menu-item "Describe" menu-bar-describe-menu
810 :help "Describe commands, variables, keys"))
811 (define-key menu-bar-help-menu [manuals]
812 (list 'menu-item "Manuals" menu-bar-manuals-menu))
813 (define-key menu-bar-help-menu [sep1]
814 '("--"))
815 (define-key menu-bar-help-menu [report-emacs-bug]
816 '(menu-item "Send Bug Report..." report-emacs-bug
817 :help "Send e-mail to Emacs maintainers"))
818 (define-key menu-bar-help-menu [emacs-problems]
819 '(menu-item "Emacs Known Problems" view-emacs-problems))
820 (define-key menu-bar-help-menu [emacs-news]
821 '(menu-item "Emacs News" view-emacs-news
822 :help "New features of this version"))
823 (define-key menu-bar-help-menu [emacs-faq]
824 '(menu-item "Emacs FAQ" view-emacs-FAQ))
825 (define-key menu-bar-help-menu [emacs-tutorial]
826 '(menu-item "Emacs Tutorial" help-with-tutorial
827 :help "Learn how to use Emacs"))
829 (defun kill-this-buffer () ; for the menubar
830 "Kills the current buffer."
831 (interactive)
832 (kill-buffer (current-buffer)))
834 (defun kill-this-buffer-enabled-p ()
835 (let ((count 0)
836 (buffers (buffer-list)))
837 (while buffers
838 (or (string-match "^ " (buffer-name (car buffers)))
839 (setq count (1+ count)))
840 (setq buffers (cdr buffers)))
841 (and (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
842 (> count 1))))
844 (put 'dired 'menu-enable
845 '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
847 ;; Permit deleting frame if it would leave a visible or iconified frame.
848 (defun delete-frame-enabled-p ()
849 "Return non-nil if `delete-frame' should be enabled in the menu bar."
850 (let ((frames (frame-list))
851 (count 0))
852 (while frames
853 (if (frame-visible-p (car frames))
854 (setq count (1+ count)))
855 (setq frames (cdr frames)))
856 (> count 1)))
858 (defcustom yank-menu-length 20
859 "*Maximum length to display in the yank-menu."
860 :type 'integer
861 :group 'mouse)
863 (defun menu-bar-update-yank-menu (string old)
864 (let ((front (car (cdr yank-menu)))
865 (menu-string (if (<= (length string) yank-menu-length)
866 string
867 (concat
868 (substring string 0 (/ yank-menu-length 2))
869 "..."
870 (substring string (- (/ yank-menu-length 2)))))))
871 ;; Don't let the menu string be all dashes
872 ;; because that has a special meaning in a menu.
873 (if (string-match "\\`-+\\'" menu-string)
874 (setq menu-string (concat menu-string " ")))
875 ;; If we're supposed to be extending an existing string, and that
876 ;; string really is at the front of the menu, then update it in place.
877 (if (and old (or (eq old (car front))
878 (string= old (car front))))
879 (progn
880 (setcar front string)
881 (setcar (cdr front) menu-string))
882 (setcdr yank-menu
883 (cons
884 (cons string (cons menu-string 'menu-bar-select-yank))
885 (cdr yank-menu)))))
886 (if (> (length (cdr yank-menu)) kill-ring-max)
887 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
889 (put 'menu-bar-select-yank 'apropos-inhibit t)
890 (defun menu-bar-select-yank ()
891 (interactive "*")
892 (push-mark (point))
893 (insert last-command-event))
895 (defvar list-buffers-directory nil)
897 (defvar menu-bar-update-buffers-maxbuf)
899 (defun menu-bar-select-buffer ()
900 (interactive)
901 (switch-to-buffer last-command-event))
903 (defun menu-bar-select-frame ()
904 (interactive)
905 (make-frame-visible last-command-event)
906 (raise-frame last-command-event)
907 (select-frame last-command-event))
909 (defun menu-bar-update-buffers-1 (elt)
910 (cons (format
911 (format "%%%ds %%s%%s %%s" menu-bar-update-buffers-maxbuf)
912 (cdr elt)
913 (if (buffer-modified-p (car elt))
914 "*" " ")
915 (save-excursion
916 (set-buffer (car elt))
917 (if buffer-read-only "%" " "))
918 (let ((file
919 (or (buffer-file-name (car elt))
920 (save-excursion
921 (set-buffer (car elt))
922 list-buffers-directory)
923 "")))
924 (setq file (or (file-name-directory file)
925 ""))
926 (if (> (length file) 20)
927 (setq file (concat "..." (substring file -17))))
928 file))
929 (car elt)))
931 (defvar menu-bar-buffers-menu-list-buffers-entry nil)
933 (defun menu-bar-update-buffers ()
934 ;; If user discards the Buffers item, play along.
935 (and (lookup-key (current-global-map) [menu-bar buffer])
936 (frame-or-buffer-changed-p)
937 (let ((buffers (buffer-list))
938 (frames (frame-list))
939 (maxlen 0)
940 buffers-menu frames-menu)
941 ;; If requested, list only the N most recently selected buffers.
942 (if (and (integerp buffers-menu-max-size)
943 (> buffers-menu-max-size 1))
944 (if (> (length buffers) buffers-menu-max-size)
945 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
947 ;; Make the menu of buffers proper.
948 (setq buffers-menu
949 (cons "Select Buffer"
950 (let* ((buffer-list
951 (mapcar 'list buffers))
952 tail
953 (menu-bar-update-buffers-maxbuf 0)
954 alist
955 head)
956 ;; Put into each element of buffer-list
957 ;; the name for actual display,
958 ;; perhaps truncated in the middle.
959 (setq tail buffer-list)
960 (while tail
961 (let ((name (buffer-name (car (car tail)))))
962 (setcdr (car tail)
963 (if (> (length name) 27)
964 (concat (substring name 0 12)
965 "..."
966 (substring name -12))
967 name)))
968 (setq tail (cdr tail)))
969 ;; Compute the maximum length of any name.
970 (setq tail buffer-list)
971 (while tail
972 (or (eq ?\ (aref (cdr (car tail)) 0))
973 (setq menu-bar-update-buffers-maxbuf
974 (max menu-bar-update-buffers-maxbuf
975 (length (cdr (car tail))))))
976 (setq tail (cdr tail)))
977 ;; Set ALIST to an alist of the form
978 ;; ITEM-STRING . BUFFER
979 (setq tail buffer-list)
980 (while tail
981 (let ((elt (car tail)))
982 (or (eq ?\ (aref (cdr elt) 0))
983 (setq alist (cons
984 (menu-bar-update-buffers-1 elt)
985 alist)))
986 (and alist (> (length (car (car alist))) maxlen)
987 (setq maxlen (length (car (car alist))))))
988 (setq tail (cdr tail)))
989 (setq alist (nreverse alist))
990 ;; Make the menu item for list-buffers
991 ;; or reuse the one we already have.
992 ;; The advantage in reusing one
993 ;; is that it already has the keyboard equivalent
994 ;; cached, so we save the time to look that up again.
995 (or menu-bar-buffers-menu-list-buffers-entry
996 (setq menu-bar-buffers-menu-list-buffers-entry
997 (cons
998 'list-buffers
999 (cons
1001 'list-buffers))))
1002 ;; Update the item string for menu's new width.
1003 (setcar (cdr menu-bar-buffers-menu-list-buffers-entry)
1004 (concat (make-string (max (- (/ maxlen 2) 8) 0)
1005 ?\ )
1006 "List All Buffers"))
1007 ;; Now make the actual list of items,
1008 ;; ending with the list-buffers item.
1009 (nconc (mapcar '(lambda (pair)
1010 ;; This is somewhat risque, to use
1011 ;; the buffer name itself as the event
1012 ;; type to define, but it works.
1013 ;; It would not work to use the buffer
1014 ;; since a buffer as an event has its
1015 ;; own meaning.
1016 (nconc (list (buffer-name (cdr pair))
1017 (car pair)
1018 (cons nil nil))
1019 'menu-bar-select-buffer))
1020 alist)
1021 (list menu-bar-buffers-menu-list-buffers-entry)))))
1024 ;; Make a Frames menu if we have more than one frame.
1025 (if (cdr frames)
1026 (let ((name (concat (make-string (max (- (/ maxlen 2) 3) 0)
1027 ?\ )
1028 "Frames"))
1029 (frames-menu
1030 (cons 'keymap
1031 (cons "Select Frame"
1032 (mapcar '(lambda (frame)
1033 (nconc (list frame
1034 (cdr (assq 'name
1035 (frame-parameters frame)))
1036 (cons nil nil))
1037 'menu-bar-select-frame))
1038 frames)))))
1039 ;; Put it underneath the Buffers menu.
1040 (setq buffers-menu (cons (cons 'frames (cons name frames-menu))
1041 buffers-menu))))
1042 (if buffers-menu
1043 (setq buffers-menu (cons 'keymap buffers-menu)))
1044 (define-key (current-global-map) [menu-bar buffer]
1045 (cons "Buffers" buffers-menu)))))
1047 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
1049 (menu-bar-update-buffers)
1051 ;; this version is too slow
1052 ;;;(defun format-buffers-menu-line (buffer)
1053 ;;; "Returns a string to represent the given buffer in the Buffer menu.
1054 ;;;nil means the buffer shouldn't be listed. You can redefine this."
1055 ;;; (if (string-match "\\` " (buffer-name buffer))
1056 ;;; nil
1057 ;;; (save-excursion
1058 ;;; (set-buffer buffer)
1059 ;;; (let ((size (buffer-size)))
1060 ;;; (format "%s%s %-19s %6s %-15s %s"
1061 ;;; (if (buffer-modified-p) "*" " ")
1062 ;;; (if buffer-read-only "%" " ")
1063 ;;; (buffer-name)
1064 ;;; size
1065 ;;; mode-name
1066 ;;; (or (buffer-file-name) ""))))))
1068 ;;; Set up a menu bar menu for the minibuffer.
1070 (mapcar
1071 (function
1072 (lambda (map)
1073 (define-key map [menu-bar minibuf]
1074 (cons "Minibuf" (make-sparse-keymap "Minibuf")))))
1075 (list minibuffer-local-ns-map
1076 minibuffer-local-must-match-map
1077 minibuffer-local-isearch-map
1078 minibuffer-local-map
1079 minibuffer-local-completion-map))
1081 (mapcar
1082 (function
1083 (lambda (map)
1084 (define-key map [menu-bar minibuf ?\?]
1085 (list 'menu-item "List Completions" 'minibuffer-completion-help
1086 :help "Display all possible completions"))
1087 (define-key map [menu-bar minibuf space]
1088 (list 'menu-item "Complete Word" 'minibuffer-complete-word
1089 :help "Complete at most one word"))
1090 (define-key map [menu-bar minibuf tab]
1091 (list 'menu-item "Complete" 'minibuffer-complete
1092 :help "Complete as far as possible"))
1094 (list minibuffer-local-must-match-map
1095 minibuffer-local-completion-map))
1097 (mapcar
1098 (function
1099 (lambda (map)
1100 (define-key map [menu-bar minibuf quit]
1101 (list 'menu-item "Quit" 'keyboard-escape-quit
1102 :help "Abort input and exit minibuffer"))
1103 (define-key map [menu-bar minibuf return]
1104 (list 'menu-item "Enter" 'exit-minibuffer
1105 :help "Terminate input and exit minibuffer"))
1107 (list minibuffer-local-ns-map
1108 minibuffer-local-must-match-map
1109 minibuffer-local-isearch-map
1110 minibuffer-local-map
1111 minibuffer-local-completion-map))
1113 (defcustom menu-bar-mode nil
1114 "Toggle display of a menu bar on each frame.
1115 Setting this variable directly does not take effect;
1116 use either \\[customize] or the function `menu-bar-mode'."
1117 :set (lambda (symbol value)
1118 (menu-bar-mode (or value 0)))
1119 :initialize 'custom-initialize-default
1120 :type 'boolean
1121 :group 'frames)
1123 (defun menu-bar-mode (flag)
1124 "Toggle display of a menu bar on each frame.
1125 This command applies to all frames that exist and frames to be
1126 created in the future.
1127 With a numeric argument, if the argument is positive,
1128 turn on menu bars; otherwise, turn off menu bars."
1129 (interactive "P")
1131 ;; Make menu-bar-mode and default-frame-alist consistent.
1132 (let ((default (assq 'menu-bar-lines default-frame-alist)))
1133 (if default
1134 (setq menu-bar-mode (not (eq (cdr default) 0)))
1135 (setq default-frame-alist
1136 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
1137 default-frame-alist))))
1139 ;; Toggle or set the mode, according to FLAG.
1140 (setq menu-bar-mode (if (null flag) (not menu-bar-mode)
1141 (> (prefix-numeric-value flag) 0)))
1143 ;; Apply it to default-frame-alist.
1144 (let ((parameter (assq 'menu-bar-lines default-frame-alist)))
1145 (if (consp parameter)
1146 (setcdr parameter (if menu-bar-mode 1 0))
1147 (setq default-frame-alist
1148 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
1149 default-frame-alist))))
1151 ;; Apply it to existing frames.
1152 (let ((frames (frame-list)))
1153 (while frames
1154 (let ((height (cdr (assq 'height (frame-parameters (car frames))))))
1155 (modify-frame-parameters (car frames)
1156 (list (cons 'menu-bar-lines
1157 (if menu-bar-mode 1 0))))
1158 (modify-frame-parameters (car frames)
1159 (list (cons 'height height))))
1160 (setq frames (cdr frames)))))
1162 (provide 'menu-bar)
1164 ;;; menu-bar.el ends here