Renamed sb-file.xpm to sb-pg.xpm
[bpt/emacs.git] / lisp / menu-bar.el
1 ;;; menu-bar.el --- define a default menu bar.
2
3 ;; Copyright (C) 1993, 1994, 1995, 2000 Free Software Foundation, Inc.
4
5 ;; Author: RMS
6 ;; Maintainer: FSF
7 ;; Keywords: internal
8
9 ;; This file is part of GNU Emacs.
10
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.
15
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.
20
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.
25
26 ;; Avishai Yacobi suggested some menu rearrangements.
27
28 ;;; Code:
29
30 ;;; User options:
31
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)
40
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"))
46
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))
51
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))
66
67 ;; This alias is for compatibility with 19.28 and before.
68 (defvar menu-bar-file-menu menu-bar-files-menu)
69 \f
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"))
74
75 (define-key menu-bar-files-menu [separator-exit]
76 '("--"))
77
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"))
93
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"))
98
99 (define-key menu-bar-files-menu [split-window]
100 '(menu-item "Split Window" split-window-vertically
101 :help "Split selected window in two"))
102
103 (define-key menu-bar-files-menu [separator-window]
104 '(menu-item "--"))
105
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"))
120
121 (define-key menu-bar-files-menu [separator-print]
122 '(menu-item "--"))
123
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)
129 nil
130 (concat "\\`"
131 (regexp-quote
132 (file-name-nondirectory
133 auto-save-list-file-prefix)))
134 t))
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"))
156
157 (define-key menu-bar-files-menu [separator-save]
158 '(menu-item "--"))
159
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"))
177
178 \f
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)))
187
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)))
195
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)))
203
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)))
211
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)))
218
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)))
225
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)))
232
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)))
239
240 (defvar menu-bar-search-menu (make-sparse-keymap "Search"))
241 (defvar menu-bar-adv-search-menu
242 (make-sparse-keymap "Advanced Search/Replace"))
243
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"))
253
254 (define-key menu-bar-adv-search-menu [separator-tag-search]
255 '(menu-item "--"))
256
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"))
279
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"))
298
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"))
303
304 (define-key menu-bar-search-menu [separator-search]
305 '(menu-item "--"))
306
307 (define-key menu-bar-edit-menu [bookmark]
308 '(menu-item "Bookmarks" menu-bar-bookmark-map
309 :help "Record positions and jump between them"))
310
311 (define-key menu-bar-edit-menu [separator-bookmark]
312 '(menu-item "--"))
313
314 (defvar menu-bar-goto-menu (make-sparse-keymap "Go To"))
315
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"))
319
320 (define-key menu-bar-goto-menu [separator-tag-file]
321 '(menu-item "--"))
322
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"))
344
345 (define-key menu-bar-goto-menu [separator-tags]
346 '(menu-item "--"))
347
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"))
358
359 (define-key menu-bar-edit-menu [goto]
360 (list 'menu-item "Go To" menu-bar-goto-menu))
361
362 (define-key menu-bar-edit-menu [search]
363 (list 'menu-item "Search" menu-bar-search-menu))
364
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"))
403
404
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)))
410
411 (autoload 'ispell-menu-map "ispell" nil t 'keymap)
412
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.
415
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)))
420
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)))
426
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)))
432
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)))
438
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)))
453
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))
461 \f
462 ;; The "Options" menu items
463
464 (defvar menu-bar-custom-menu (make-sparse-keymap "Customize"))
465
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'"))
500
501 ;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
502
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)))))
515
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 ;; Most of the MULE menu actually does make sense in unibyte mode,
526 ;; e.g. language selection.
527 ;;; ':visible 'default-enable-multibyte-characters
528 ':help "Default language, encodings, input method"))
529 ;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
530 ;(define-key menu-bar-options-menu [preferences]
531 ; (list 'menu-item "Preferences" menu-bar-preferences-menu
532 ; :help "Toggle important global options"))
533
534 (define-key menu-bar-options-menu [mule-separator]
535 '("--"))
536
537 (define-key menu-bar-options-menu [debug-on-quit]
538 (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
539 "Enter Debugger on Quit/C-g" "Debug on Quit %s"
540 "Enter Lisp debugger when C-g is pressed"))
541 (define-key menu-bar-options-menu [debug-on-error]
542 (menu-bar-make-toggle toggle-debug-on-error debug-on-error
543 "Enter Debugger on Error" "Debug on Error %s"
544 "Enter Lisp debugger when error is signaled"))
545 (define-key menu-bar-options-menu [debugger-separator]
546 '("--"))
547 (define-key menu-bar-options-menu [toggle-auto-compression]
548 '(menu-item "Automatic File De/compression"
549 auto-compression-mode
550 :help "Transparently decompress compressed files"
551 :button (:toggle . (rassq 'jka-compr-handler
552 file-name-handler-alist))))
553 (define-key menu-bar-options-menu [save-place]
554 (menu-bar-make-toggle toggle-save-place-globally save-place
555 "Save Place in Files between Sessions"
556 "Saving place in files %s"
557 "Save Emacs state for next session"
558 (require 'saveplace)
559 (setq-default save-place (not (default-value save-place)))))
560 (define-key menu-bar-options-menu [uniquify]
561 (menu-bar-make-toggle toggle-uniquify-buffer-names uniquify-buffer-name-style
562 "Use Directory Names in Buffer Names"
563 "Directory name in buffer names (uniquify) %s"
564 nil
565 (require 'uniquify)
566 (setq uniquify-buffer-name-style
567 (if (not uniquify-buffer-name-style)
568 'forward))))
569 (define-key menu-bar-options-menu [edit-options-separator]
570 '("--"))
571 (define-key menu-bar-options-menu [case-fold-search]
572 (menu-bar-make-toggle toggle-case-fold-search case-fold-search
573 "Case-Insensitive Search"
574 "Case-Insensitive Search %s"
575 "If checked, search ignores letter-case"))
576 (define-key menu-bar-options-menu [auto-fill-mode]
577 '(menu-item "Word Wrap in Text Modes (Auto Fill)"
578 toggle-text-mode-auto-fill
579 :help "Automatically fill text between left and right margins"
580 :button (:toggle . (member 'turn-on-auto-fill text-mode-hook))))
581 (define-key menu-bar-options-menu [truncate-lines]
582 (menu-bar-make-toggle
583 toggle-truncate-lines truncate-lines
584 "Truncate Long Lines in this Buffer" "Long Line Truncation %s"
585 "If checked, long lines are truncated on the screen"
586 (prog1 (setq truncate-lines (not truncate-lines))
587 (set-buffer-modified-p (buffer-modified-p)))))
588 (define-key menu-bar-options-menu [highlight-separator]
589 '("--"))
590 (define-key menu-bar-options-menu [highlight-paren-mode]
591 (menu-bar-make-toggle toggle-highlight-paren-mode show-paren-mode
592 "Highlight Matching Parentheses"
593 "Show Paren mode %s"
594 "Highlight matching and mismatched parentheses"))
595 (define-key menu-bar-options-menu [transient-mark-mode]
596 (menu-bar-make-toggle toggle-transient-mark-mode transient-mark-mode
597 "Transient Mark Mode (highlights region)"
598 "Transient Mark mode %s"
599 "Highlight the marked region when it's active"))
600 (define-key menu-bar-options-menu [toggle-global-lazy-font-lock-mode]
601 (menu-bar-make-toggle toggle-global-lazy-font-lock-mode global-font-lock-mode
602 "Highlight Syntax (Global Font Lock)"
603 "Syntax Highlighting %s"
604 "Highlights text based on language syntax"
605 ;; Make sure a support mode is used;
606 ;; otherwise Font Lock will be too slow.
607 (require 'font-lock)
608 (if (not global-font-lock-mode)
609 (or font-lock-support-mode
610 (setq font-lock-support-mode 'lazy-lock-mode)))
611 (global-font-lock-mode)))
612
613
614 \f
615 ;; The "Tools" menu items
616
617 (defvar menu-bar-games-menu (make-sparse-keymap "Games"))
618
619 (define-key menu-bar-tools-menu [games]
620 (list 'menu-item "Games" menu-bar-games-menu))
621
622 (define-key menu-bar-tools-menu [separator-games]
623 '("--"))
624
625 (define-key menu-bar-games-menu [yow]
626 '(menu-item "Random Quotation" yow
627 :help "Display a random Zippy quotation"))
628 (define-key menu-bar-games-menu [tetris]
629 '(menu-item "Tetris" tetris))
630 (define-key menu-bar-games-menu [solitaire]
631 '(menu-item "Solitaire" solitaire))
632 (define-key menu-bar-games-menu [snake]
633 '(menu-item "Snake" snake
634 :help "Move snake around avoiding collisions"))
635 (define-key menu-bar-games-menu [mult]
636 '(menu-item "Multiplication Puzzle" mpuz
637 :help "Excercise brain with multiplication"))
638 (define-key menu-bar-games-menu [life]
639 '(menu-item "Life" life
640 :help "Watch how John Conway's cellular automaton evolves"))
641 (define-key menu-bar-games-menu [hanoi]
642 '(menu-item "Towers of Hanoi" hanoi
643 :help "Watch Towers-of-Hanoi puzzle solved by Emacs"))
644 (define-key menu-bar-games-menu [gomoku]
645 '(menu-item "Gomoku" gomoku
646 :help "Mark 5 contiguous squares (like tic-tac-toe)"))
647 (define-key menu-bar-games-menu [black-box]
648 '(menu-item "Blackbox" blackbox
649 :help "Find balls in a black box by shooting rays"))
650 (define-key menu-bar-games-menu [adventure]
651 '(menu-item "Adventure" dunnet
652 :help "Dunnet, a text Adventure game for Emacs"))
653 (define-key menu-bar-games-menu [5x5]
654 '(menu-item "5x5" 5x5
655 :help "Fill in all the squares on a 5x5 board"))
656
657 (define-key menu-bar-tools-menu [calendar]
658 '(menu-item "Display Calendar" calendar))
659 (define-key menu-bar-tools-menu [speedbar]
660 '(menu-item "Display Speedbar" speedbar-frame-mode))
661 (define-key menu-bar-tools-menu [directory-search]
662 '(menu-item "Directory Search" eudc-tools-menu
663 :help "Query directory servers via LDAP, CCSO PH/QI or BBDB"))
664 (define-key menu-bar-tools-menu [compose-mail]
665 '(menu-item "Send Mail" compose-mail
666 :help "Send a mail message"))
667 (define-key menu-bar-tools-menu [rmail]
668 '(menu-item "Read Mail" read-mail-command
669 :help "Read your mail and reply to it"))
670 (define-key menu-bar-tools-menu [gnus]
671 '(menu-item "Read Net News" gnus
672 :help "Read network news groups"))
673
674 (define-key menu-bar-tools-menu [separator-vc]
675 '("--"))
676
677 (defvar vc-menu-map (make-sparse-keymap "Version Control"))
678 (define-key menu-bar-tools-menu [pcl-cvs]
679 `(menu-item "PCL-CVS" ,cvs-global-menu
680 :help "Module-level interface to CVS"))
681 (define-key menu-bar-tools-menu [vc]
682 (list 'menu-item "Version Control" vc-menu-map
683 :help "Interface to RCS, CVS, SCCS"))
684
685 (define-key menu-bar-tools-menu [separator-compare]
686 '("--"))
687
688 (define-key menu-bar-tools-menu [ediff-misc]
689 '(menu-item "Ediff Miscellanea" menu-bar-ediff-misc-menu
690 :help "Ediff manual, customization, sessions, etc."))
691 (define-key menu-bar-tools-menu [epatch]
692 '(menu-item "Apply Patch" menu-bar-epatch-menu))
693 (define-key menu-bar-tools-menu [ediff-merge]
694 '(menu-item "Merge" menu-bar-ediff-merge-menu
695 :help "Merge different revisions of files/directories"))
696 (define-key menu-bar-tools-menu [compare]
697 '(menu-item "Compare (Ediff)" menu-bar-ediff-menu
698 :help "Display differences between files/directories"))
699
700
701 (define-key menu-bar-tools-menu [separator-spell]
702 '("--"))
703
704 (define-key menu-bar-tools-menu [spell]
705 '(menu-item "Spell Checking" ispell-menu-map))
706
707 (define-key menu-bar-tools-menu [separator-prog]
708 '("--"))
709
710 (define-key menu-bar-tools-menu [gdb]
711 '(menu-item "Debugger (GUD)..." gdb
712 :help "Debug a program from withing Emacs"))
713 (define-key menu-bar-tools-menu [shell-on-region]
714 '(menu-item "Shell Command on Region..." shell-command-on-region
715 :enable mark-active
716 :help "Pass marked region to a shell command"))
717 (define-key menu-bar-tools-menu [shell]
718 '(menu-item "Shell Command..." shell-command
719 :help "Invoke a shell command and catch its output"))
720 (define-key menu-bar-tools-menu [compile]
721 '(menu-item "Compile..." compile
722 :help "Invoke compiler or Make, view compilation errors"))
723 (define-key menu-bar-tools-menu [grep]
724 '(menu-item "Search Files (Grep)..." grep
725 :help "Search files for strings or regexps (with Grep)"))
726
727 \f
728 ;; The "Help" menu items
729
730 (defvar menu-bar-describe-menu (make-sparse-keymap "Describe"))
731
732 (define-key menu-bar-describe-menu [mule-diag]
733 '(menu-item "Show All of Mule Status" mule-diag
734 :visible default-enable-multibyte-characters
735 :help "Display multilingual environment settings"))
736 (define-key menu-bar-describe-menu [describe-coding-system]
737 '(menu-item "Describe Coding System..." describe-coding-system
738 :visible default-enable-multibyte-characters))
739 (define-key menu-bar-describe-menu [describe-input-method]
740 '(menu-item "Describe Input Method..." describe-input-method
741 :visible default-enable-multibyte-characters
742 :help "Keyboard layout for specific input method"))
743 (define-key menu-bar-describe-menu [describe-language-environment]
744 (list 'menu-item "Describe Language Environment"
745 describe-language-environment-map
746 :help "Show multilingual settings for a specific language"))
747
748 (define-key menu-bar-describe-menu [separator-desc-mule]
749 '("--"))
750
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 [list-keybindings]
755 '(menu-item "List Key Bindings" describe-bindings
756 :help "Display a list of all current keybindings"))
757 (define-key menu-bar-describe-menu [describe-variable]
758 '(menu-item "Describe Variable..." describe-variable
759 :help "Display documentation of variable/option"))
760 (define-key menu-bar-describe-menu [describe-function]
761 '(menu-item "Describe Function..." describe-function
762 :help "Display documentation of function/command"))
763 (define-key menu-bar-describe-menu [describe-key]
764 '(menu-item "Describe Key..." describe-key
765 ;; Users typically don't identify keys and menu items...
766 :help "Display documentation of command bound to a \
767 key (or menu-item)"))
768 (define-key menu-bar-describe-menu [apropos-variables]
769 '(menu-item "Apropos Variables..." apropos-variable
770 :help "List variables whose names match a regexp"))
771 (define-key menu-bar-describe-menu [apropos-commands]
772 '(menu-item "Apropos Commands..." apropos-command
773 :help "List commands whose names match a regexp"))
774 (define-key menu-bar-describe-menu [describe-mode]
775 '(menu-item "Describe Buffer Modes" describe-mode
776 :help "Describe this buffer's major and minor mode"))
777
778 (defvar menu-bar-manuals-menu (make-sparse-keymap "Manuals"))
779
780 (define-key menu-bar-manuals-menu [man]
781 '(menu-item "Read Man Page..." manual-entry
782 :help "Man-page docs for external commands and libraries"))
783 (define-key menu-bar-manuals-menu [sep2]
784 '("--"))
785 (define-key menu-bar-manuals-menu [info]
786 '(menu-item "Browse Manuals with Info" Info-directory
787 :help "Read any of the installed manuals"))
788 (define-key menu-bar-manuals-menu [command]
789 '(menu-item "Find Command in Manual" Info-goto-emacs-command-node
790 :help "Display manual section that describes a command"))
791 (define-key menu-bar-manuals-menu [key]
792 '(menu-item "Find Key in Manual" Info-goto-emacs-key-command-node
793 :help "Display manual section that describes a key"))
794
795 (define-key menu-bar-help-menu [eliza]
796 '(menu-item "Emacs Psychiatrist" doctor
797 :help "Our doctor will help you feel better"))
798 (define-key menu-bar-help-menu [sep3]
799 '("--"))
800 (define-key menu-bar-help-menu [describe-no-warranty]
801 '(menu-item "(Non)Warranty" describe-no-warranty
802 :help "Explain that Emacs has NO WARRANTY"))
803 (define-key menu-bar-help-menu [describe-copying]
804 '(menu-item "Copying Conditions" describe-copying
805 :help "Show the Emacs license (GPL)"))
806 (define-key menu-bar-help-menu [describe-distribution]
807 '(menu-item "Getting New Versions" describe-distribution
808 :help "How to get latest versions of Emacs"))
809 (define-key menu-bar-help-menu [emacs-version]
810 '(menu-item "Show Emacs Version" emacs-version))
811 (define-key menu-bar-help-menu [sep2]
812 '("--"))
813 (define-key menu-bar-help-menu [finder-by-keyword]
814 '(menu-item "Find Emacs Packages..." finder-by-keyword
815 :help "Find packages and features by keyword"))
816 (define-key menu-bar-help-menu [describe]
817 (list 'menu-item "Describe" menu-bar-describe-menu
818 :help "Describe commands, variables, keys"))
819 (define-key menu-bar-help-menu [manuals]
820 (list 'menu-item "Manuals" menu-bar-manuals-menu))
821 (define-key menu-bar-help-menu [sep1]
822 '("--"))
823 (define-key menu-bar-help-menu [report-emacs-bug]
824 '(menu-item "Send Bug Report..." report-emacs-bug
825 :help "Send e-mail to Emacs maintainers"))
826 (define-key menu-bar-help-menu [emacs-manual]
827 '(menu-item "Read the Emacs manual"
828 (lambda () (interactive) (info "emacs"))))
829 (define-key menu-bar-help-menu [emacs-problems]
830 '(menu-item "Emacs Known Problems" view-emacs-problems))
831 (define-key menu-bar-help-menu [emacs-news]
832 '(menu-item "Emacs News" view-emacs-news
833 :help "New features of this version"))
834 (define-key menu-bar-help-menu [emacs-faq]
835 '(menu-item "Emacs FAQ" view-emacs-FAQ))
836 (define-key menu-bar-help-menu [emacs-tutorial]
837 '(menu-item "Emacs Tutorial" help-with-tutorial
838 :help "Learn how to use Emacs"))
839
840 (defun kill-this-buffer () ; for the menubar
841 "Kill the current buffer."
842 (interactive)
843 (kill-buffer (current-buffer)))
844
845 (defun kill-this-buffer-enabled-p ()
846 (let ((count 0)
847 (buffers (buffer-list)))
848 (while buffers
849 (or (string-match "^ " (buffer-name (car buffers)))
850 (setq count (1+ count)))
851 (setq buffers (cdr buffers)))
852 (and (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
853 (> count 1))))
854
855 (put 'dired 'menu-enable
856 '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
857
858 ;; Permit deleting frame if it would leave a visible or iconified frame.
859 (defun delete-frame-enabled-p ()
860 "Return non-nil if `delete-frame' should be enabled in the menu bar."
861 (let ((frames (frame-list))
862 (count 0))
863 (while frames
864 (if (frame-visible-p (car frames))
865 (setq count (1+ count)))
866 (setq frames (cdr frames)))
867 (> count 1)))
868
869 (defcustom yank-menu-length 20
870 "*Maximum length to display in the yank-menu."
871 :type 'integer
872 :group 'mouse)
873
874 (defun menu-bar-update-yank-menu (string old)
875 (let ((front (car (cdr yank-menu)))
876 (menu-string (if (<= (length string) yank-menu-length)
877 string
878 (concat
879 (substring string 0 (/ yank-menu-length 2))
880 "..."
881 (substring string (- (/ yank-menu-length 2)))))))
882 ;; Don't let the menu string be all dashes
883 ;; because that has a special meaning in a menu.
884 (if (string-match "\\`-+\\'" menu-string)
885 (setq menu-string (concat menu-string " ")))
886 ;; If we're supposed to be extending an existing string, and that
887 ;; string really is at the front of the menu, then update it in place.
888 (if (and old (or (eq old (car front))
889 (string= old (car front))))
890 (progn
891 (setcar front string)
892 (setcar (cdr front) menu-string))
893 (setcdr yank-menu
894 (cons
895 (cons string (cons menu-string 'menu-bar-select-yank))
896 (cdr yank-menu)))))
897 (if (> (length (cdr yank-menu)) kill-ring-max)
898 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
899
900 (put 'menu-bar-select-yank 'apropos-inhibit t)
901 (defun menu-bar-select-yank ()
902 (interactive "*")
903 (push-mark (point))
904 (insert last-command-event))
905 \f
906 (defvar list-buffers-directory nil)
907
908 (defvar menu-bar-update-buffers-maxbuf)
909
910 (defun menu-bar-select-buffer ()
911 (interactive)
912 (switch-to-buffer last-command-event))
913
914 (defun menu-bar-select-frame ()
915 (interactive)
916 (make-frame-visible last-command-event)
917 (raise-frame last-command-event)
918 (select-frame last-command-event))
919
920 (defun menu-bar-update-buffers-1 (elt)
921 (cons (format
922 (format "%%%ds %%s%%s %%s" menu-bar-update-buffers-maxbuf)
923 (cdr elt)
924 (if (buffer-modified-p (car elt))
925 "*" " ")
926 (save-excursion
927 (set-buffer (car elt))
928 (if buffer-read-only "%" " "))
929 (let ((file
930 (or (buffer-file-name (car elt))
931 (save-excursion
932 (set-buffer (car elt))
933 list-buffers-directory)
934 "")))
935 (setq file (or (file-name-directory file)
936 ""))
937 (if (> (length file) 20)
938 (setq file (concat "..." (substring file -17))))
939 file))
940 (car elt)))
941
942 (defvar menu-bar-buffers-menu-list-buffers-entry nil)
943
944 (defun menu-bar-update-buffers ()
945 ;; If user discards the Buffers item, play along.
946 (and (lookup-key (current-global-map) [menu-bar buffer])
947 (frame-or-buffer-changed-p)
948 (let ((buffers (buffer-list))
949 (frames (frame-list))
950 (maxlen 0)
951 buffers-menu frames-menu)
952 ;; If requested, list only the N most recently selected buffers.
953 (if (and (integerp buffers-menu-max-size)
954 (> buffers-menu-max-size 1))
955 (if (> (length buffers) buffers-menu-max-size)
956 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
957
958 ;; Make the menu of buffers proper.
959 (setq buffers-menu
960 (cons "Select Buffer"
961 (let* ((buffer-list
962 (mapcar 'list buffers))
963 tail
964 (menu-bar-update-buffers-maxbuf 0)
965 alist
966 head)
967 ;; Put into each element of buffer-list
968 ;; the name for actual display,
969 ;; perhaps truncated in the middle.
970 (setq tail buffer-list)
971 (while tail
972 (let ((name (buffer-name (car (car tail)))))
973 (setcdr (car tail)
974 (if (> (length name) 27)
975 (concat (substring name 0 12)
976 "..."
977 (substring name -12))
978 name)))
979 (setq tail (cdr tail)))
980 ;; Compute the maximum length of any name.
981 (setq tail buffer-list)
982 (while tail
983 (or (eq ?\ (aref (cdr (car tail)) 0))
984 (setq menu-bar-update-buffers-maxbuf
985 (max menu-bar-update-buffers-maxbuf
986 (length (cdr (car tail))))))
987 (setq tail (cdr tail)))
988 ;; Set ALIST to an alist of the form
989 ;; ITEM-STRING . BUFFER
990 (setq tail buffer-list)
991 (while tail
992 (let ((elt (car tail)))
993 (or (eq ?\ (aref (cdr elt) 0))
994 (setq alist (cons
995 (menu-bar-update-buffers-1 elt)
996 alist)))
997 (and alist (> (length (car (car alist))) maxlen)
998 (setq maxlen (length (car (car alist))))))
999 (setq tail (cdr tail)))
1000 (setq alist (nreverse alist))
1001 ;; Make the menu item for list-buffers
1002 ;; or reuse the one we already have.
1003 ;; The advantage in reusing one
1004 ;; is that it already has the keyboard equivalent
1005 ;; cached, so we save the time to look that up again.
1006 (or menu-bar-buffers-menu-list-buffers-entry
1007 (setq menu-bar-buffers-menu-list-buffers-entry
1008 (cons
1009 'list-buffers
1010 (cons
1011 ""
1012 'list-buffers))))
1013 ;; Update the item string for menu's new width.
1014 (setcar (cdr menu-bar-buffers-menu-list-buffers-entry)
1015 (concat (make-string (max (- (/ maxlen 2) 8) 0)
1016 ?\ )
1017 "List All Buffers"))
1018 ;; Now make the actual list of items,
1019 ;; ending with the list-buffers item.
1020 (nconc (mapcar '(lambda (pair)
1021 ;; This is somewhat risque, to use
1022 ;; the buffer name itself as the event
1023 ;; type to define, but it works.
1024 ;; It would not work to use the buffer
1025 ;; since a buffer as an event has its
1026 ;; own meaning.
1027 (nconc (list (buffer-name (cdr pair))
1028 (car pair)
1029 (cons nil nil))
1030 'menu-bar-select-buffer))
1031 alist)
1032 (list menu-bar-buffers-menu-list-buffers-entry)))))
1033
1034
1035 ;; Make a Frames menu if we have more than one frame.
1036 (if (cdr frames)
1037 (let ((name (concat (make-string (max (- (/ maxlen 2) 3) 0)
1038 ?\ )
1039 "Frames"))
1040 (frames-menu
1041 (cons 'keymap
1042 (cons "Select Frame"
1043 (mapcar '(lambda (frame)
1044 (nconc (list frame
1045 (cdr (assq 'name
1046 (frame-parameters frame)))
1047 (cons nil nil))
1048 'menu-bar-select-frame))
1049 frames)))))
1050 ;; Put it underneath the Buffers menu.
1051 (setq buffers-menu (cons (cons 'frames (cons name frames-menu))
1052 buffers-menu))))
1053 (if buffers-menu
1054 (setq buffers-menu (cons 'keymap buffers-menu)))
1055 (define-key (current-global-map) [menu-bar buffer]
1056 (cons "Buffers" buffers-menu)))))
1057
1058 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
1059
1060 (menu-bar-update-buffers)
1061
1062 ;; this version is too slow
1063 ;;;(defun format-buffers-menu-line (buffer)
1064 ;;; "Returns a string to represent the given buffer in the Buffer menu.
1065 ;;;nil means the buffer shouldn't be listed. You can redefine this."
1066 ;;; (if (string-match "\\` " (buffer-name buffer))
1067 ;;; nil
1068 ;;; (save-excursion
1069 ;;; (set-buffer buffer)
1070 ;;; (let ((size (buffer-size)))
1071 ;;; (format "%s%s %-19s %6s %-15s %s"
1072 ;;; (if (buffer-modified-p) "*" " ")
1073 ;;; (if buffer-read-only "%" " ")
1074 ;;; (buffer-name)
1075 ;;; size
1076 ;;; mode-name
1077 ;;; (or (buffer-file-name) ""))))))
1078 \f
1079 ;;; Set up a menu bar menu for the minibuffer.
1080
1081 (mapcar
1082 (function
1083 (lambda (map)
1084 (define-key map [menu-bar minibuf]
1085 (cons "Minibuf" (make-sparse-keymap "Minibuf")))))
1086 (list minibuffer-local-ns-map
1087 minibuffer-local-must-match-map
1088 minibuffer-local-isearch-map
1089 minibuffer-local-map
1090 minibuffer-local-completion-map))
1091
1092 (mapcar
1093 (function
1094 (lambda (map)
1095 (define-key map [menu-bar minibuf ?\?]
1096 (list 'menu-item "List Completions" 'minibuffer-completion-help
1097 :help "Display all possible completions"))
1098 (define-key map [menu-bar minibuf space]
1099 (list 'menu-item "Complete Word" 'minibuffer-complete-word
1100 :help "Complete at most one word"))
1101 (define-key map [menu-bar minibuf tab]
1102 (list 'menu-item "Complete" 'minibuffer-complete
1103 :help "Complete as far as possible"))
1104 ))
1105 (list minibuffer-local-must-match-map
1106 minibuffer-local-completion-map))
1107
1108 (mapcar
1109 (function
1110 (lambda (map)
1111 (define-key map [menu-bar minibuf quit]
1112 (list 'menu-item "Quit" 'keyboard-escape-quit
1113 :help "Abort input and exit minibuffer"))
1114 (define-key map [menu-bar minibuf return]
1115 (list 'menu-item "Enter" 'exit-minibuffer
1116 :help "Terminate input and exit minibuffer"))
1117 ))
1118 (list minibuffer-local-ns-map
1119 minibuffer-local-must-match-map
1120 minibuffer-local-isearch-map
1121 minibuffer-local-map
1122 minibuffer-local-completion-map))
1123 \f
1124 (defcustom menu-bar-mode nil
1125 "Toggle display of a menu bar on each frame.
1126 Setting this variable directly does not take effect;
1127 use either \\[customize] or the function `menu-bar-mode'."
1128 :set (lambda (symbol value)
1129 (menu-bar-mode (or value 0)))
1130 :initialize 'custom-initialize-default
1131 :type 'boolean
1132 :group 'frames)
1133
1134 (defun menu-bar-mode (flag)
1135 "Toggle display of a menu bar on each frame.
1136 This command applies to all frames that exist and frames to be
1137 created in the future.
1138 With a numeric argument, if the argument is positive,
1139 turn on menu bars; otherwise, turn off menu bars."
1140 (interactive "P")
1141
1142 ;; Make menu-bar-mode and default-frame-alist consistent.
1143 (let ((default (assq 'menu-bar-lines default-frame-alist)))
1144 (if default
1145 (setq menu-bar-mode (not (eq (cdr default) 0)))
1146 (setq default-frame-alist
1147 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
1148 default-frame-alist))))
1149
1150 ;; Toggle or set the mode, according to FLAG.
1151 (setq menu-bar-mode (if (null flag) (not menu-bar-mode)
1152 (> (prefix-numeric-value flag) 0)))
1153
1154 ;; Apply it to default-frame-alist.
1155 (let ((parameter (assq 'menu-bar-lines default-frame-alist)))
1156 (if (consp parameter)
1157 (setcdr parameter (if menu-bar-mode 1 0))
1158 (setq default-frame-alist
1159 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
1160 default-frame-alist))))
1161
1162 ;; Apply it to existing frames.
1163 (let ((frames (frame-list)))
1164 (while frames
1165 (let ((height (cdr (assq 'height (frame-parameters (car frames))))))
1166 (modify-frame-parameters (car frames)
1167 (list (cons 'menu-bar-lines
1168 (if menu-bar-mode 1 0))))
1169 (modify-frame-parameters (car frames)
1170 (list (cons 'height height))))
1171 (setq frames (cdr frames)))))
1172
1173 (provide 'menu-bar)
1174
1175 ;;; menu-bar.el ends here