[!HAVE_TERMCAP_H]: Declare tputs, tgetent, tgetflag, tgetnum.
[emacs.git] / lisp / menu-bar.el
blobe3adc6f4f65159127525216b0f16e0b4cad2a878
1 ;;; menu-bar.el --- define a default menu bar.
3 ;; Copyright (C) 1993, 1994, 1995, 2000 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 [mark-whole-buffer]
396 '(menu-item "Mark Buffer" mark-whole-buffer
397 :help "Mark the whole buffer for a subsequent cut/copy."))
398 (define-key menu-bar-edit-menu [undo]
399 '(menu-item "Undo" undo
400 :enable (and (not buffer-read-only)
401 (not (eq t buffer-undo-list))
402 (if (eq last-command 'undo)
403 pending-undo-list
404 (consp buffer-undo-list)))
405 :help "Undo last operation"))
408 (defun menu-bar-kill-ring-save (beg end)
409 (interactive "r")
410 (if (mouse-region-match)
411 (message "Selecting a region with the mouse does `copy' automatically")
412 (kill-ring-save beg end)))
414 (autoload 'ispell-menu-map "ispell" nil t 'keymap)
416 ;; These are alternative definitions for the cut, paste and copy
417 ;; menu items. Use them if your system expects these to use the clipboard.
419 (put 'clipboard-kill-region 'menu-enable 'mark-active)
420 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
421 (put 'clipboard-yank 'menu-enable
422 '(or (x-selection-exists-p) (x-selection-exists-p 'CLIPBOARD)))
424 (defun clipboard-yank ()
425 "Insert the clipboard contents, or the last stretch of killed text."
426 (interactive)
427 (let ((x-select-enable-clipboard t))
428 (yank)))
430 (defun clipboard-kill-ring-save (beg end)
431 "Copy region to kill ring, and save in the X clipboard."
432 (interactive "r")
433 (let ((x-select-enable-clipboard t))
434 (kill-ring-save beg end)))
436 (defun clipboard-kill-region (beg end)
437 "Kill the region, and save it in the X clipboard."
438 (interactive "r")
439 (let ((x-select-enable-clipboard t))
440 (kill-region beg end)))
442 (defun menu-bar-enable-clipboard ()
443 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
444 Do the same for the keys of the same name."
445 (interactive)
446 ;; We can't use constant list structure here because it becomes pure,
447 ;; and because it gets modified with cache data.
448 (define-key menu-bar-edit-menu [paste]
449 (cons "Paste" (cons "Paste text from clipboard" 'clipboard-yank)))
450 (define-key menu-bar-edit-menu [copy]
451 (cons "Copy" (cons "Copy text in region to the clipboard"
452 'clipboard-kill-ring-save)))
453 (define-key menu-bar-edit-menu [cut]
454 (cons "Cut" (cons "Delete text in region and copy it to the clipboard"
455 'clipboard-kill-region)))
457 (define-key global-map [f20] 'clipboard-kill-region)
458 (define-key global-map [f16] 'clipboard-kill-ring-save)
459 (define-key global-map [f18] 'clipboard-yank)
460 ;; X11R6 versions
461 (define-key global-map [cut] 'clipboard-kill-region)
462 (define-key global-map [copy] 'clipboard-kill-ring-save)
463 (define-key global-map [paste] 'clipboard-yank))
465 ;; The "Options" menu items
467 (defvar menu-bar-custom-menu (make-sparse-keymap "Customize"))
469 (define-key menu-bar-custom-menu [customize-apropos-groups]
470 '(menu-item "Groups Matching Regexp..." customize-apropos-groups
471 :help "Browse groups whose names match regexp"))
472 (define-key menu-bar-custom-menu [customize-apropos-faces]
473 '(menu-item "Faces Matching Regexp..." customize-apropos-faces
474 :help "Browse faces whose names match regexp"))
475 (define-key menu-bar-custom-menu [customize-apropos-options]
476 '(menu-item "Options Matching Regexp..." customize-apropos-options
477 :help "Browse options whose names match regexp"))
478 (define-key menu-bar-custom-menu [customize-apropos]
479 '(menu-item "Settings Matching Regexp..." customize-apropos
480 :help "Browse customizable settings whose names match regexp"))
481 (define-key menu-bar-custom-menu [separator-2]
482 '("--"))
483 (define-key menu-bar-custom-menu [customize-group]
484 '(menu-item "Specific Group..." customize-group
485 :help "Customize settings of specific group"))
486 (define-key menu-bar-custom-menu [customize-face]
487 '(menu-item "Specific Face..." customize-face
488 :help "Customize attributes of specific face"))
489 (define-key menu-bar-custom-menu [customize-option]
490 '(menu-item "Specific Option..." customize-option
491 :help "Change value of specific option"))
492 (define-key menu-bar-custom-menu [customize-changed-options]
493 '(menu-item "Recently Changed Options..." customize-changed-options
494 :help "Customize options changed in recent versions"))
495 (define-key menu-bar-custom-menu [separator-3]
496 '("--"))
497 (define-key menu-bar-custom-menu [customize-browse]
498 '(menu-item "Browse Customization Groups" customize-browse
499 :help "Browse all customization groups"))
500 (define-key menu-bar-custom-menu [customize]
501 '(menu-item "Top-level Customization Group" customize
502 :help "The master group called `Emacs'"))
504 ;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
506 (defmacro menu-bar-make-toggle (name variable doc message help &rest body)
507 `(progn
508 (defun ,name ()
509 ,(concat doc ".")
510 (interactive)
511 (if ,(if body `(progn . ,body)
512 `(setq ,variable (not ,variable)))
513 (message ,message "enabled")
514 (message ,message "disabled")))
515 '(menu-item ,doc ,name
516 :help ,help
517 :button (:toggle . (and (boundp ',variable) ,variable)))))
519 ;;; Assemble all the top-level items of the "Options" menu
520 (define-key menu-bar-options-menu [customize]
521 (list 'menu-item "Customize Emacs" menu-bar-custom-menu
522 :help "Full customization of every Emacs feature"))
524 (defun menu-bar-options-save ()
525 "Save current values of Options menu items using Custom."
526 (interactive)
527 (dolist (elt '(debug-on-quit debug-on-error auto-compression-mode
528 case-fold-search truncate-lines show-paren-mode
529 transient-mark-mode global-font-lock-mode
530 current-language-environment default-input-method))
531 (if (default-value elt)
532 (customize-save-variable elt (default-value elt))))
533 (if (memq 'turn-on-auto-fill text-mode-hook)
534 (customize-save-variable 'text-mode-hook
535 (default-value 'text-mode-hook)))
536 (if (featurep 'saveplace)
537 (customize-save-variable 'save-place (default-value 'save-place)))
538 (if (featurep 'uniquify)
539 (customize-save-variable 'uniquify-buffer-name-style
540 (default-value 'uniquify-buffer-name-style))))
542 (define-key menu-bar-options-menu [save]
543 '(menu-item "Save Options" menu-bar-options-save
544 :help "Save options set from the menu above"))
546 (define-key menu-bar-options-menu [custom-separator]
547 '("--"))
549 (define-key menu-bar-options-menu [mule]
550 ;; It is better not to use backquote here,
551 ;; because that makes a bootstrapping problem
552 ;; if you need to recompile all the Lisp files using interpreted code.
553 (list 'menu-item "Mule (Multilingual Environment)" mule-menu-keymap
554 ;; Most of the MULE menu actually does make sense in unibyte mode,
555 ;; e.g. language selection.
556 ;;; ':visible 'default-enable-multibyte-characters
557 ':help "Default language, encodings, input method"))
558 ;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
559 ;(define-key menu-bar-options-menu [preferences]
560 ; (list 'menu-item "Preferences" menu-bar-preferences-menu
561 ; :help "Toggle important global options"))
563 (define-key menu-bar-options-menu [mule-separator]
564 '("--"))
566 (define-key menu-bar-options-menu [debug-on-quit]
567 (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
568 "Enter Debugger on Quit/C-g" "Debug on Quit %s"
569 "Enter Lisp debugger when C-g is pressed"))
570 (define-key menu-bar-options-menu [debug-on-error]
571 (menu-bar-make-toggle toggle-debug-on-error debug-on-error
572 "Enter Debugger on Error" "Debug on Error %s"
573 "Enter Lisp debugger when error is signaled"))
574 (define-key menu-bar-options-menu [debugger-separator]
575 '("--"))
576 (define-key menu-bar-options-menu [toggle-auto-compression]
577 '(menu-item "Automatic File De/compression"
578 auto-compression-mode
579 :help "Transparently decompress compressed files"
580 :button (:toggle . (rassq 'jka-compr-handler
581 file-name-handler-alist))))
582 (define-key menu-bar-options-menu [save-place]
583 (menu-bar-make-toggle toggle-save-place-globally save-place
584 "Save Place in Files between Sessions"
585 "Saving place in files %s"
586 "Save Emacs state for next session"
587 (require 'saveplace)
588 (setq-default save-place
589 (not (default-value save-place)))))
590 (define-key menu-bar-options-menu [uniquify]
591 (menu-bar-make-toggle toggle-uniquify-buffer-names uniquify-buffer-name-style
592 "Use Directory Names in Buffer Names"
593 "Directory name in buffer names (uniquify) %s"
595 (require 'uniquify)
596 (setq uniquify-buffer-name-style
597 (if (not uniquify-buffer-name-style)
598 'forward))))
599 (define-key menu-bar-options-menu [edit-options-separator]
600 '("--"))
601 (define-key menu-bar-options-menu [case-fold-search]
602 (menu-bar-make-toggle toggle-case-fold-search case-fold-search
603 "Case-Insensitive Search"
604 "Case-Insensitive Search %s"
605 "If checked, search ignores letter-case"))
606 (define-key menu-bar-options-menu [auto-fill-mode]
607 '(menu-item "Word Wrap in Text Modes (Auto Fill)"
608 toggle-text-mode-auto-fill
609 :help "Automatically fill text between left and right margins"
610 :button (:toggle . (member 'turn-on-auto-fill text-mode-hook))))
611 (define-key menu-bar-options-menu [truncate-lines]
612 (menu-bar-make-toggle
613 toggle-truncate-lines truncate-lines
614 "Truncate Long Lines in this Buffer" "Long Line Truncation %s"
615 "If checked, long lines are truncated on the screen"
616 (prog1 (setq truncate-lines (not truncate-lines))
617 (set-buffer-modified-p (buffer-modified-p)))))
618 (define-key menu-bar-options-menu [highlight-separator]
619 '("--"))
620 (define-key menu-bar-options-menu [highlight-paren-mode]
621 (menu-bar-make-toggle toggle-highlight-paren-mode show-paren-mode
622 "Highlight Matching Parentheses"
623 "Show Paren mode %s"
624 "Highlight matching and mismatched parentheses"))
625 (define-key menu-bar-options-menu [transient-mark-mode]
626 (menu-bar-make-toggle toggle-transient-mark-mode transient-mark-mode
627 "Transient Mark Mode (highlights region)"
628 "Transient Mark mode %s"
629 "Highlight the marked region when it's active"))
630 (define-key menu-bar-options-menu [toggle-global-lazy-font-lock-mode]
631 (menu-bar-make-toggle toggle-global-lazy-font-lock-mode global-font-lock-mode
632 "Highlight Syntax (Global Font Lock)"
633 "Syntax Highlighting %s"
634 "Highlights text based on language syntax"
635 global-font-lock-mode))
638 ;; The "Tools" menu items
640 (defvar menu-bar-games-menu (make-sparse-keymap "Games"))
642 (define-key menu-bar-tools-menu [games]
643 (list 'menu-item "Games" menu-bar-games-menu))
645 (define-key menu-bar-tools-menu [separator-games]
646 '("--"))
648 (define-key menu-bar-games-menu [yow]
649 '(menu-item "Random Quotation" yow
650 :help "Display a random Zippy quotation"))
651 (define-key menu-bar-games-menu [tetris]
652 '(menu-item "Tetris" tetris))
653 (define-key menu-bar-games-menu [solitaire]
654 '(menu-item "Solitaire" solitaire))
655 (define-key menu-bar-games-menu [snake]
656 '(menu-item "Snake" snake
657 :help "Move snake around avoiding collisions"))
658 (define-key menu-bar-games-menu [mult]
659 '(menu-item "Multiplication Puzzle" mpuz
660 :help "Excercise brain with multiplication"))
661 (define-key menu-bar-games-menu [life]
662 '(menu-item "Life" life
663 :help "Watch how John Conway's cellular automaton evolves"))
664 (define-key menu-bar-games-menu [hanoi]
665 '(menu-item "Towers of Hanoi" hanoi
666 :help "Watch Towers-of-Hanoi puzzle solved by Emacs"))
667 (define-key menu-bar-games-menu [gomoku]
668 '(menu-item "Gomoku" gomoku
669 :help "Mark 5 contiguous squares (like tic-tac-toe)"))
670 (define-key menu-bar-games-menu [black-box]
671 '(menu-item "Blackbox" blackbox
672 :help "Find balls in a black box by shooting rays"))
673 (define-key menu-bar-games-menu [adventure]
674 '(menu-item "Adventure" dunnet
675 :help "Dunnet, a text Adventure game for Emacs"))
676 (define-key menu-bar-games-menu [5x5]
677 '(menu-item "5x5" 5x5
678 :help "Fill in all the squares on a 5x5 board"))
680 (define-key menu-bar-tools-menu [calendar]
681 '(menu-item "Display Calendar" calendar))
682 (define-key menu-bar-tools-menu [speedbar]
683 '(menu-item "Display Speedbar" speedbar-frame-mode))
684 (define-key menu-bar-tools-menu [directory-search]
685 '(menu-item "Directory Search" eudc-tools-menu
686 :help "Query directory servers via LDAP, CCSO PH/QI or BBDB"))
687 (define-key menu-bar-tools-menu [compose-mail]
688 '(menu-item "Send Mail" compose-mail
689 :help "Send a mail message"))
690 (define-key menu-bar-tools-menu [rmail]
691 '(menu-item "Read Mail" read-mail-command
692 :help "Read your mail and reply to it"))
693 (define-key menu-bar-tools-menu [gnus]
694 '(menu-item "Read Net News" gnus
695 :help "Read network news groups"))
697 (define-key menu-bar-tools-menu [separator-vc]
698 '("--"))
700 (defvar vc-menu-map (make-sparse-keymap "Version Control"))
701 (define-key menu-bar-tools-menu [pcl-cvs]
702 `(menu-item "PCL-CVS" ,cvs-global-menu
703 :help "Module-level interface to CVS"))
704 (define-key menu-bar-tools-menu [vc]
705 (list 'menu-item "Version Control" vc-menu-map
706 :help "Interface to RCS, CVS, SCCS"))
708 (define-key menu-bar-tools-menu [separator-compare]
709 '("--"))
711 (define-key menu-bar-tools-menu [ediff-misc]
712 '(menu-item "Ediff Miscellanea" menu-bar-ediff-misc-menu
713 :help "Ediff manual, customization, sessions, etc."))
714 (define-key menu-bar-tools-menu [epatch]
715 '(menu-item "Apply Patch" menu-bar-epatch-menu))
716 (define-key menu-bar-tools-menu [ediff-merge]
717 '(menu-item "Merge" menu-bar-ediff-merge-menu
718 :help "Merge different revisions of files/directories"))
719 (define-key menu-bar-tools-menu [compare]
720 '(menu-item "Compare (Ediff)" menu-bar-ediff-menu
721 :help "Display differences between files/directories"))
724 (define-key menu-bar-tools-menu [separator-spell]
725 '("--"))
727 (define-key menu-bar-tools-menu [spell]
728 '(menu-item "Spell Checking" ispell-menu-map))
730 (define-key menu-bar-tools-menu [separator-prog]
731 '("--"))
733 (define-key menu-bar-tools-menu [gdb]
734 '(menu-item "Debugger (GUD)..." gdb
735 :help "Debug a program from withing Emacs"))
736 (define-key menu-bar-tools-menu [shell-on-region]
737 '(menu-item "Shell Command on Region..." shell-command-on-region
738 :enable mark-active
739 :help "Pass marked region to a shell command"))
740 (define-key menu-bar-tools-menu [shell]
741 '(menu-item "Shell Command..." shell-command
742 :help "Invoke a shell command and catch its output"))
743 (define-key menu-bar-tools-menu [compile]
744 '(menu-item "Compile..." compile
745 :help "Invoke compiler or Make, view compilation errors"))
746 (define-key menu-bar-tools-menu [grep]
747 '(menu-item "Search Files (Grep)..." grep
748 :help "Search files for strings or regexps (with Grep)"))
751 ;; The "Help" menu items
753 (defvar menu-bar-describe-menu (make-sparse-keymap "Describe"))
755 (define-key menu-bar-describe-menu [mule-diag]
756 '(menu-item "Show All of Mule Status" mule-diag
757 :visible default-enable-multibyte-characters
758 :help "Display multilingual environment settings"))
759 (define-key menu-bar-describe-menu [describe-coding-system]
760 '(menu-item "Describe Coding System..." describe-coding-system
761 :visible default-enable-multibyte-characters))
762 (define-key menu-bar-describe-menu [describe-input-method]
763 '(menu-item "Describe Input Method..." describe-input-method
764 :visible default-enable-multibyte-characters
765 :help "Keyboard layout for specific input method"))
766 (define-key menu-bar-describe-menu [describe-language-environment]
767 (list 'menu-item "Describe Language Environment"
768 describe-language-environment-map
769 :help "Show multilingual settings for a specific language"))
771 (define-key menu-bar-describe-menu [separator-desc-mule]
772 '("--"))
774 (define-key menu-bar-describe-menu [list-keybindings]
775 '(menu-item "List Key Bindings" describe-bindings
776 :help "Display a list of all current keybindings"))
777 (define-key menu-bar-describe-menu [list-keybindings]
778 '(menu-item "List Key Bindings" describe-bindings
779 :help "Display a list of all current keybindings"))
780 (define-key menu-bar-describe-menu [describe-variable]
781 '(menu-item "Describe Variable..." describe-variable
782 :help "Display documentation of variable/option"))
783 (define-key menu-bar-describe-menu [describe-function]
784 '(menu-item "Describe Function..." describe-function
785 :help "Display documentation of function/command"))
786 (define-key menu-bar-describe-menu [describe-key]
787 '(menu-item "Describe Key..." describe-key
788 ;; Users typically don't identify keys and menu items...
789 :help "Display documentation of command bound to a \
790 key (or menu-item)"))
791 (define-key menu-bar-describe-menu [apropos-variables]
792 '(menu-item "Apropos Variables..." apropos-variable
793 :help "List variables whose names match a regexp"))
794 (define-key menu-bar-describe-menu [apropos-commands]
795 '(menu-item "Apropos Commands..." apropos-command
796 :help "List commands whose names match a regexp"))
797 (define-key menu-bar-describe-menu [describe-mode]
798 '(menu-item "Describe Buffer Modes" describe-mode
799 :help "Describe this buffer's major and minor mode"))
801 (defvar menu-bar-manuals-menu (make-sparse-keymap "Manuals"))
803 (define-key menu-bar-manuals-menu [man]
804 '(menu-item "Read Man Page..." manual-entry
805 :help "Man-page docs for external commands and libraries"))
806 (define-key menu-bar-manuals-menu [sep2]
807 '("--"))
808 (define-key menu-bar-manuals-menu [info]
809 '(menu-item "Browse Manuals with Info" Info-directory
810 :help "Read any of the installed manuals"))
811 (define-key menu-bar-manuals-menu [command]
812 '(menu-item "Find Command in Manual" Info-goto-emacs-command-node
813 :help "Display manual section that describes a command"))
814 (define-key menu-bar-manuals-menu [key]
815 '(menu-item "Find Key in Manual" Info-goto-emacs-key-command-node
816 :help "Display manual section that describes a key"))
818 (define-key menu-bar-help-menu [eliza]
819 '(menu-item "Emacs Psychiatrist" doctor
820 :help "Our doctor will help you feel better"))
821 (define-key menu-bar-help-menu [sep3]
822 '("--"))
823 (define-key menu-bar-help-menu [describe-no-warranty]
824 '(menu-item "(Non)Warranty" describe-no-warranty
825 :help "Explain that Emacs has NO WARRANTY"))
826 (define-key menu-bar-help-menu [describe-copying]
827 '(menu-item "Copying Conditions" describe-copying
828 :help "Show the Emacs license (GPL)"))
829 (define-key menu-bar-help-menu [describe-distribution]
830 '(menu-item "Getting New Versions" describe-distribution
831 :help "How to get latest versions of Emacs"))
832 (define-key menu-bar-help-menu [emacs-version]
833 '(menu-item "Show Emacs Version" emacs-version))
834 (define-key menu-bar-help-menu [sep2]
835 '("--"))
836 (define-key menu-bar-help-menu [finder-by-keyword]
837 '(menu-item "Find Emacs Packages..." finder-by-keyword
838 :help "Find packages and features by keyword"))
839 (define-key menu-bar-help-menu [describe]
840 (list 'menu-item "Describe" menu-bar-describe-menu
841 :help "Describe commands, variables, keys"))
842 (define-key menu-bar-help-menu [manuals]
843 (list 'menu-item "Manuals" menu-bar-manuals-menu))
844 (define-key menu-bar-help-menu [sep1]
845 '("--"))
846 (define-key menu-bar-help-menu [report-emacs-bug]
847 '(menu-item "Send Bug Report..." report-emacs-bug
848 :help "Send e-mail to Emacs maintainers"))
849 (define-key menu-bar-help-menu [emacs-manual]
850 '(menu-item "Read the Emacs manual"
851 (lambda () (interactive) (info "emacs"))))
852 (define-key menu-bar-help-menu [emacs-problems]
853 '(menu-item "Emacs Known Problems" view-emacs-problems))
854 (define-key menu-bar-help-menu [emacs-news]
855 '(menu-item "Emacs News" view-emacs-news
856 :help "New features of this version"))
857 (define-key menu-bar-help-menu [emacs-faq]
858 '(menu-item "Emacs FAQ" view-emacs-FAQ))
859 (define-key menu-bar-help-menu [emacs-tutorial-language-specific]
860 '(menu-item "Emacs Tutorial (choose language)..."
861 (lambda () (interactive) (help-with-tutorial t))
862 :help "Learn how to use Emacs (choose a language)"))
863 (define-key menu-bar-help-menu [emacs-tutorial]
864 '(menu-item "Emacs Tutorial" help-with-tutorial
865 :help "Learn how to use Emacs"))
867 (defun kill-this-buffer () ; for the menubar
868 "Kill the current buffer."
869 (interactive)
870 (kill-buffer (current-buffer)))
872 (defun kill-this-buffer-enabled-p ()
873 (let ((count 0)
874 (buffers (buffer-list)))
875 (while buffers
876 (or (string-match "^ " (buffer-name (car buffers)))
877 (setq count (1+ count)))
878 (setq buffers (cdr buffers)))
879 (and (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
880 (> count 1))))
882 (put 'dired 'menu-enable
883 '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
885 ;; Permit deleting frame if it would leave a visible or iconified frame.
886 (defun delete-frame-enabled-p ()
887 "Return non-nil if `delete-frame' should be enabled in the menu bar."
888 (let ((frames (frame-list))
889 (count 0))
890 (while frames
891 (if (frame-visible-p (car frames))
892 (setq count (1+ count)))
893 (setq frames (cdr frames)))
894 (> count 1)))
896 (defcustom yank-menu-length 20
897 "*Maximum length to display in the yank-menu."
898 :type 'integer
899 :group 'mouse)
901 (defun menu-bar-update-yank-menu (string old)
902 (let ((front (car (cdr yank-menu)))
903 (menu-string (if (<= (length string) yank-menu-length)
904 string
905 (concat
906 (substring string 0 (/ yank-menu-length 2))
907 "..."
908 (substring string (- (/ yank-menu-length 2)))))))
909 ;; Don't let the menu string be all dashes
910 ;; because that has a special meaning in a menu.
911 (if (string-match "\\`-+\\'" menu-string)
912 (setq menu-string (concat menu-string " ")))
913 ;; If we're supposed to be extending an existing string, and that
914 ;; string really is at the front of the menu, then update it in place.
915 (if (and old (or (eq old (car front))
916 (string= old (car front))))
917 (progn
918 (setcar front string)
919 (setcar (cdr front) menu-string))
920 (setcdr yank-menu
921 (cons
922 (cons string (cons menu-string 'menu-bar-select-yank))
923 (cdr yank-menu)))))
924 (if (> (length (cdr yank-menu)) kill-ring-max)
925 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
927 (put 'menu-bar-select-yank 'apropos-inhibit t)
928 (defun menu-bar-select-yank ()
929 (interactive "*")
930 (push-mark (point))
931 (insert last-command-event))
933 (defvar list-buffers-directory nil)
935 (defvar menu-bar-update-buffers-maxbuf)
937 (defun menu-bar-select-buffer ()
938 (interactive)
939 (switch-to-buffer last-command-event))
941 (defun menu-bar-select-frame ()
942 (interactive)
943 (make-frame-visible last-command-event)
944 (raise-frame last-command-event)
945 (select-frame last-command-event))
947 (defun menu-bar-update-buffers-1 (elt)
948 (cons (format
949 (format "%%%ds %%s%%s %%s" menu-bar-update-buffers-maxbuf)
950 (cdr elt)
951 (if (buffer-modified-p (car elt))
952 "*" " ")
953 (save-excursion
954 (set-buffer (car elt))
955 (if buffer-read-only "%" " "))
956 (let ((file
957 (or (buffer-file-name (car elt))
958 (save-excursion
959 (set-buffer (car elt))
960 list-buffers-directory)
961 "")))
962 (setq file (or (file-name-directory file)
963 ""))
964 (if (> (length file) 20)
965 (setq file (concat "..." (substring file -17))))
966 file))
967 (car elt)))
969 (defvar menu-bar-buffers-menu-list-buffers-entry nil)
971 (defun menu-bar-update-buffers ()
972 ;; If user discards the Buffers item, play along.
973 (and (lookup-key (current-global-map) [menu-bar buffer])
974 (frame-or-buffer-changed-p)
975 (let ((buffers (buffer-list))
976 (frames (frame-list))
977 (maxlen 0)
978 buffers-menu frames-menu)
979 ;; If requested, list only the N most recently selected buffers.
980 (if (and (integerp buffers-menu-max-size)
981 (> buffers-menu-max-size 1))
982 (if (> (length buffers) buffers-menu-max-size)
983 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
985 ;; Make the menu of buffers proper.
986 (setq buffers-menu
987 (cons "Select Buffer"
988 (let* ((buffer-list
989 (mapcar 'list buffers))
990 tail
991 (menu-bar-update-buffers-maxbuf 0)
992 alist
993 head)
994 ;; Put into each element of buffer-list
995 ;; the name for actual display,
996 ;; perhaps truncated in the middle.
997 (setq tail buffer-list)
998 (while tail
999 (let ((name (buffer-name (car (car tail)))))
1000 (setcdr (car tail)
1001 (if (> (length name) 27)
1002 (concat (substring name 0 12)
1003 "..."
1004 (substring name -12))
1005 name)))
1006 (setq tail (cdr tail)))
1007 ;; Compute the maximum length of any name.
1008 (setq tail buffer-list)
1009 (while tail
1010 (or (eq ?\ (aref (cdr (car tail)) 0))
1011 (setq menu-bar-update-buffers-maxbuf
1012 (max menu-bar-update-buffers-maxbuf
1013 (length (cdr (car tail))))))
1014 (setq tail (cdr tail)))
1015 ;; Set ALIST to an alist of the form
1016 ;; ITEM-STRING . BUFFER
1017 (setq tail buffer-list)
1018 (while tail
1019 (let ((elt (car tail)))
1020 (or (eq ?\ (aref (cdr elt) 0))
1021 (setq alist (cons
1022 (menu-bar-update-buffers-1 elt)
1023 alist)))
1024 (and alist (> (length (car (car alist))) maxlen)
1025 (setq maxlen (length (car (car alist))))))
1026 (setq tail (cdr tail)))
1027 (setq alist (nreverse alist))
1028 ;; Make the menu item for list-buffers
1029 ;; or reuse the one we already have.
1030 ;; The advantage in reusing one
1031 ;; is that it already has the keyboard equivalent
1032 ;; cached, so we save the time to look that up again.
1033 (or menu-bar-buffers-menu-list-buffers-entry
1034 (setq menu-bar-buffers-menu-list-buffers-entry
1035 (cons
1036 'list-buffers
1037 (cons
1039 'list-buffers))))
1040 ;; Update the item string for menu's new width.
1041 (setcar (cdr menu-bar-buffers-menu-list-buffers-entry)
1042 (concat (make-string (max (- (/ maxlen 2) 8) 0)
1043 ?\ )
1044 "List All Buffers"))
1045 ;; Now make the actual list of items,
1046 ;; ending with the list-buffers item.
1047 (nconc (mapcar (lambda (pair)
1048 ;; This is somewhat risque, to use
1049 ;; the buffer name itself as the event
1050 ;; type to define, but it works.
1051 ;; It would not work to use the buffer
1052 ;; since a buffer as an event has its
1053 ;; own meaning.
1054 (nconc (list (buffer-name (cdr pair))
1055 (car pair)
1056 (cons nil nil))
1057 'menu-bar-select-buffer))
1058 alist)
1059 (list menu-bar-buffers-menu-list-buffers-entry)))))
1062 ;; Make a Frames menu if we have more than one frame.
1063 (if (cdr frames)
1064 (let ((name (concat (make-string (max (- (/ maxlen 2) 3) 0)
1065 ?\ )
1066 "Frames"))
1067 (frames-menu
1068 (cons 'keymap
1069 (cons "Select Frame"
1070 (mapcar
1071 (lambda (frame)
1072 (nconc
1073 (list frame
1074 (cdr (assq 'name
1075 (frame-parameters frame)))
1076 (cons nil nil))
1077 'menu-bar-select-frame))
1078 frames)))))
1079 ;; Put it underneath the Buffers menu.
1080 (setq buffers-menu (cons (cons 'frames (cons name frames-menu))
1081 buffers-menu))))
1082 (if buffers-menu
1083 (setq buffers-menu (cons 'keymap buffers-menu)))
1084 (define-key (current-global-map) [menu-bar buffer]
1085 (cons "Buffers" buffers-menu)))))
1087 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
1089 (menu-bar-update-buffers)
1091 ;; this version is too slow
1092 ;;;(defun format-buffers-menu-line (buffer)
1093 ;;; "Returns a string to represent the given buffer in the Buffer menu.
1094 ;;;nil means the buffer shouldn't be listed. You can redefine this."
1095 ;;; (if (string-match "\\` " (buffer-name buffer))
1096 ;;; nil
1097 ;;; (save-excursion
1098 ;;; (set-buffer buffer)
1099 ;;; (let ((size (buffer-size)))
1100 ;;; (format "%s%s %-19s %6s %-15s %s"
1101 ;;; (if (buffer-modified-p) "*" " ")
1102 ;;; (if buffer-read-only "%" " ")
1103 ;;; (buffer-name)
1104 ;;; size
1105 ;;; mode-name
1106 ;;; (or (buffer-file-name) ""))))))
1108 ;;; Set up a menu bar menu for the minibuffer.
1110 (mapcar
1111 (function
1112 (lambda (map)
1113 (define-key map [menu-bar minibuf]
1114 (cons "Minibuf" (make-sparse-keymap "Minibuf")))))
1115 (list minibuffer-local-ns-map
1116 minibuffer-local-must-match-map
1117 minibuffer-local-isearch-map
1118 minibuffer-local-map
1119 minibuffer-local-completion-map))
1121 (mapcar
1122 (function
1123 (lambda (map)
1124 (define-key map [menu-bar minibuf ?\?]
1125 (list 'menu-item "List Completions" 'minibuffer-completion-help
1126 :help "Display all possible completions"))
1127 (define-key map [menu-bar minibuf space]
1128 (list 'menu-item "Complete Word" 'minibuffer-complete-word
1129 :help "Complete at most one word"))
1130 (define-key map [menu-bar minibuf tab]
1131 (list 'menu-item "Complete" 'minibuffer-complete
1132 :help "Complete as far as possible"))
1134 (list minibuffer-local-must-match-map
1135 minibuffer-local-completion-map))
1137 (mapcar
1138 (function
1139 (lambda (map)
1140 (define-key map [menu-bar minibuf quit]
1141 (list 'menu-item "Quit" 'keyboard-escape-quit
1142 :help "Abort input and exit minibuffer"))
1143 (define-key map [menu-bar minibuf return]
1144 (list 'menu-item "Enter" 'exit-minibuffer
1145 :help "Terminate input and exit minibuffer"))
1147 (list minibuffer-local-ns-map
1148 minibuffer-local-must-match-map
1149 minibuffer-local-isearch-map
1150 minibuffer-local-map
1151 minibuffer-local-completion-map))
1153 (defcustom menu-bar-mode nil
1154 "Toggle display of a menu bar on each frame.
1155 Setting this variable directly does not take effect;
1156 use either \\[customize] or the function `menu-bar-mode'."
1157 :set (lambda (symbol value)
1158 (menu-bar-mode (or value 0)))
1159 :initialize 'custom-initialize-default
1160 :type 'boolean
1161 :group 'frames)
1163 (defun menu-bar-mode (flag)
1164 "Toggle display of a menu bar on each frame.
1165 This command applies to all frames that exist and frames to be
1166 created in the future.
1167 With a numeric argument, if the argument is positive,
1168 turn on menu bars; otherwise, turn off menu bars."
1169 (interactive "P")
1171 ;; Make menu-bar-mode and default-frame-alist consistent.
1172 (let ((default (assq 'menu-bar-lines default-frame-alist)))
1173 (if default
1174 (setq menu-bar-mode (not (eq (cdr default) 0)))
1175 (setq default-frame-alist
1176 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
1177 default-frame-alist))))
1179 ;; Toggle or set the mode, according to FLAG.
1180 (setq menu-bar-mode (if (null flag) (not menu-bar-mode)
1181 (> (prefix-numeric-value flag) 0)))
1183 ;; Apply it to default-frame-alist.
1184 (let ((parameter (assq 'menu-bar-lines default-frame-alist)))
1185 (if (consp parameter)
1186 (setcdr parameter (if menu-bar-mode 1 0))
1187 (setq default-frame-alist
1188 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
1189 default-frame-alist))))
1191 ;; Apply it to existing frames.
1192 (let ((frames (frame-list)))
1193 (while frames
1194 (let ((height (cdr (assq 'height (frame-parameters (car frames))))))
1195 (modify-frame-parameters (car frames)
1196 (list (cons 'menu-bar-lines
1197 (if menu-bar-mode 1 0))))
1198 (modify-frame-parameters (car frames)
1199 (list (cons 'height height))))
1200 (setq frames (cdr frames)))))
1202 (provide 'menu-bar)
1204 ;;; menu-bar.el ends here