1 ;;; menu-bar.el --- define a default menu bar
3 ;; Copyright (C) 1993-1995, 2000-2014 Free Software Foundation, Inc.
5 ;; Author: Richard M. Stallman
6 ;; Maintainer: emacs-devel@gnu.org
7 ;; Keywords: internal, mouse
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; Avishai Yacobi suggested some menu rearrangements.
31 ;; This is referenced by some code below; it is defined in uniquify.el
32 (defvar uniquify-buffer-name-style
)
34 ;; From emulation/cua-base.el; used below
35 (defvar cua-enable-cua-keys
)
38 ;; Don't clobber an existing menu-bar keymap, to preserve any menu-bar key
39 ;; definitions made in loaddefs.el.
40 (or (lookup-key global-map
[menu-bar
])
41 (define-key global-map
[menu-bar
] (make-sparse-keymap "menu-bar")))
43 ;; Force Help item to come last, after the major mode's own items.
44 ;; The symbol used to be called `help', but that gets confused with the
46 (setq menu-bar-final-items
'(help-menu))
48 ;; This definition is just to show what this looks like.
49 ;; It gets modified in place when menu-bar-update-buffers is called.
50 (defvar global-buffers-menu-map
(make-sparse-keymap "Buffers"))
52 ;; Only declared obsolete (and only made a proper alias) in 23.3.
53 (define-obsolete-variable-alias
54 'menu-bar-files-menu
'menu-bar-file-menu
"22.1")
55 (defvar menu-bar-file-menu
56 (let ((menu (make-sparse-keymap "File")))
58 ;; The "File" menu items
59 (bindings--define-key menu
[exit-emacs
]
60 '(menu-item "Quit" save-buffers-kill-terminal
61 :help
"Save unsaved buffers, then exit"))
63 (bindings--define-key menu
[separator-exit
]
66 ;; Don't use delete-frame as event name because that is a special
68 (bindings--define-key menu
[delete-this-frame
]
69 '(menu-item "Delete Frame" delete-frame
70 :visible
(fboundp 'delete-frame
)
71 :enable
(delete-frame-enabled-p)
72 :help
"Delete currently selected frame"))
73 (bindings--define-key menu
[make-frame-on-display
]
74 '(menu-item "New Frame on Display..." make-frame-on-display
75 :visible
(fboundp 'make-frame-on-display
)
76 :help
"Open a new frame on another display"))
77 (bindings--define-key menu
[make-frame
]
78 '(menu-item "New Frame" make-frame-command
79 :visible
(fboundp 'make-frame-command
)
80 :help
"Open a new frame"))
82 (bindings--define-key menu
[separator-frame
]
85 (bindings--define-key menu
[one-window
]
86 '(menu-item "Remove Other Windows" delete-other-windows
87 :enable
(not (one-window-p t nil
))
88 :help
"Make selected window fill whole frame"))
90 (bindings--define-key menu
[new-window-on-right
]
91 '(menu-item "New Window on Right" split-window-right
92 :enable
(and (menu-bar-menu-frame-live-and-visible-p)
93 (menu-bar-non-minibuffer-window-p))
94 :help
"Make new window on right of selected one"))
96 (bindings--define-key menu
[new-window-below
]
97 '(menu-item "New Window Below" split-window-below
98 :enable
(and (menu-bar-menu-frame-live-and-visible-p)
99 (menu-bar-non-minibuffer-window-p))
100 :help
"Make new window below selected one"))
102 (bindings--define-key menu
[separator-window
]
105 (bindings--define-key menu
[ps-print-region
]
106 '(menu-item "PostScript Print Region (B+W)" ps-print-region
108 :help
"Pretty-print marked region in black and white to PostScript printer"))
109 (bindings--define-key menu
[ps-print-buffer
]
110 '(menu-item "PostScript Print Buffer (B+W)" ps-print-buffer
111 :enable
(menu-bar-menu-frame-live-and-visible-p)
112 :help
"Pretty-print current buffer in black and white to PostScript printer"))
113 (bindings--define-key menu
[ps-print-region-faces
]
114 '(menu-item "PostScript Print Region"
115 ps-print-region-with-faces
117 :help
"Pretty-print marked region to PostScript printer"))
118 (bindings--define-key menu
[ps-print-buffer-faces
]
119 '(menu-item "PostScript Print Buffer"
120 ps-print-buffer-with-faces
121 :enable
(menu-bar-menu-frame-live-and-visible-p)
122 :help
"Pretty-print current buffer to PostScript printer"))
123 (bindings--define-key menu
[print-region
]
124 '(menu-item "Print Region" print-region
126 :help
"Print region between mark and current position"))
127 (bindings--define-key menu
[print-buffer
]
128 '(menu-item "Print Buffer" print-buffer
129 :enable
(menu-bar-menu-frame-live-and-visible-p)
130 :help
"Print current buffer with page headings"))
132 (bindings--define-key menu
[separator-print
]
135 (bindings--define-key menu
[recover-session
]
136 '(menu-item "Recover Crashed Session" recover-session
138 (and auto-save-list-file-prefix
140 (file-name-directory auto-save-list-file-prefix
))
142 (file-name-directory auto-save-list-file-prefix
)
146 (file-name-nondirectory
147 auto-save-list-file-prefix
)))
149 :help
"Recover edits from a crashed session"))
150 (bindings--define-key menu
[revert-buffer
]
151 '(menu-item "Revert Buffer" revert-buffer
152 :enable
(or (not (eq revert-buffer-function
153 'revert-buffer--default
))
155 revert-buffer-insert-file-contents-function
156 'revert-buffer-insert-file-contents--default-function
))
157 (and buffer-file-number
158 (or (buffer-modified-p)
159 (not (verify-visited-file-modtime
160 (current-buffer))))))
161 :help
"Re-read current buffer from its file"))
162 (bindings--define-key menu
[write-file
]
163 '(menu-item "Save As..." write-file
164 :enable
(and (menu-bar-menu-frame-live-and-visible-p)
165 (menu-bar-non-minibuffer-window-p))
166 :help
"Write current buffer to another file"))
167 (bindings--define-key menu
[save-buffer
]
168 '(menu-item "Save" save-buffer
169 :enable
(and (buffer-modified-p)
171 (menu-bar-non-minibuffer-window-p))
172 :help
"Save current buffer to its file"))
174 (bindings--define-key menu
[separator-save
]
178 (bindings--define-key menu
[kill-buffer
]
179 '(menu-item "Close" kill-this-buffer
180 :enable
(kill-this-buffer-enabled-p)
181 :help
"Discard (kill) current buffer"))
182 (bindings--define-key menu
[insert-file
]
183 '(menu-item "Insert File..." insert-file
184 :enable
(menu-bar-non-minibuffer-window-p)
185 :help
"Insert another file into current buffer"))
186 (bindings--define-key menu
[dired]
187 '(menu-item "Open Directory..." dired
188 :enable (menu-bar-non-minibuffer-window-p)
189 :help "Read a directory, to operate on its files"))
190 (bindings--define-key menu [open-file]
191 '(menu-item "Open File..." menu-find-file-existing
192 :enable (menu-bar-non-minibuffer-window-p)
193 :help "Read an existing file into an Emacs buffer"))
194 (bindings--define-key menu [new-file]
195 '(menu-item "Visit New File..." find-file
196 :enable (menu-bar-non-minibuffer-window-p)
197 :help "Specify a new file's name, to edit the file"))
201 (defun menu-find-file-existing ()
202 "Edit the existing file FILENAME."
204 (let* ((mustmatch (not (and (fboundp 'x-uses-old-gtk-dialog)
205 (x-uses-old-gtk-dialog))))
206 (filename (car (find-file-read-args "Find file: " mustmatch))))
208 (find-file-existing filename)
209 (find-file filename))))
211 ;; The "Edit->Search" submenu
212 (defvar menu-bar-last-search-type nil
213 "Type of last non-incremental search command called from the menu.")
215 (defun nonincremental-repeat-search-forward ()
216 "Search forward for the previous search string or regexp."
219 ((and (eq menu-bar-last-search-type 'string)
221 (search-forward (car search-ring)))
222 ((and (eq menu-bar-last-search-type 'regexp)
224 (re-search-forward (car regexp-search-ring)))
226 (error "No previous search"))))
228 (defun nonincremental-repeat-search-backward ()
229 "Search backward for the previous search string or regexp."
232 ((and (eq menu-bar-last-search-type 'string)
234 (search-backward (car search-ring)))
235 ((and (eq menu-bar-last-search-type 'regexp)
237 (re-search-backward (car regexp-search-ring)))
239 (error "No previous search"))))
241 (defun nonincremental-search-forward (string)
242 "Read a string and search for it nonincrementally."
243 (interactive "sSearch for string: ")
244 (setq menu-bar-last-search-type 'string)
245 (if (equal string "")
246 (search-forward (car search-ring))
247 (isearch-update-ring string nil)
248 (search-forward string)))
250 (defun nonincremental-search-backward (string)
251 "Read a string and search backward for it nonincrementally."
252 (interactive "sSearch for string: ")
253 (setq menu-bar-last-search-type 'string)
254 (if (equal string "")
255 (search-backward (car search-ring))
256 (isearch-update-ring string nil)
257 (search-backward string)))
259 (defun nonincremental-re-search-forward (string)
260 "Read a regular expression and search for it nonincrementally."
261 (interactive "sSearch for regexp: ")
262 (setq menu-bar-last-search-type 'regexp)
263 (if (equal string "")
264 (re-search-forward (car regexp-search-ring))
265 (isearch-update-ring string t)
266 (re-search-forward string)))
268 (defun nonincremental-re-search-backward (string)
269 "Read a regular expression and search backward for it nonincrementally."
270 (interactive "sSearch for regexp: ")
271 (setq menu-bar-last-search-type 'regexp)
272 (if (equal string "")
273 (re-search-backward (car regexp-search-ring))
274 (isearch-update-ring string t)
275 (re-search-backward string)))
277 ;; The Edit->Search->Incremental Search menu
278 (defvar menu-bar-i-search-menu
279 (let ((menu (make-sparse-keymap "Incremental Search")))
280 (bindings--define-key menu [isearch-backward-regexp]
281 '(menu-item "Backward Regexp..." isearch-backward-regexp
282 :help "Search backwards for a regular expression as you type it"))
283 (bindings--define-key menu [isearch-forward-regexp]
284 '(menu-item "Forward Regexp..." isearch-forward-regexp
285 :help "Search forward for a regular expression as you type it"))
286 (bindings--define-key menu [isearch-backward]
287 '(menu-item "Backward String..." isearch-backward
288 :help "Search backwards for a string as you type it"))
289 (bindings--define-key menu [isearch-forward]
290 '(menu-item "Forward String..." isearch-forward
291 :help "Search forward for a string as you type it"))
294 (defvar menu-bar-search-menu
295 (let ((menu (make-sparse-keymap "Search")))
297 (bindings--define-key menu [i-search]
298 `(menu-item "Incremental Search" ,menu-bar-i-search-menu))
299 (bindings--define-key menu [separator-tag-isearch]
302 (bindings--define-key menu [tags-continue]
303 '(menu-item "Continue Tags Search" tags-loop-continue
304 :help "Continue last tags search operation"))
305 (bindings--define-key menu [tags-srch]
306 '(menu-item "Search Tagged Files..." tags-search
307 :help "Search for a regexp in all tagged files"))
308 (bindings--define-key menu [separator-tag-search] menu-bar-separator)
310 (bindings--define-key menu [repeat-search-back]
311 '(menu-item "Repeat Backwards"
312 nonincremental-repeat-search-backward
313 :enable (or (and (eq menu-bar-last-search-type 'string)
315 (and (eq menu-bar-last-search-type 'regexp)
317 :help "Repeat last search backwards"))
318 (bindings--define-key menu [repeat-search-fwd]
319 '(menu-item "Repeat Forward"
320 nonincremental-repeat-search-forward
321 :enable (or (and (eq menu-bar-last-search-type 'string)
323 (and (eq menu-bar-last-search-type 'regexp)
325 :help "Repeat last search forward"))
326 (bindings--define-key menu [separator-repeat-search]
329 (bindings--define-key menu [re-search-backward]
330 '(menu-item "Regexp Backwards..."
331 nonincremental-re-search-backward
332 :help "Search backwards for a regular expression"))
333 (bindings--define-key menu [re-search-forward]
334 '(menu-item "Regexp Forward..."
335 nonincremental-re-search-forward
336 :help "Search forward for a regular expression"))
338 (bindings--define-key menu [search-backward]
339 '(menu-item "String Backwards..."
340 nonincremental-search-backward
341 :help "Search backwards for a string"))
342 (bindings--define-key menu [search-forward]
343 '(menu-item "String Forward..." nonincremental-search-forward
344 :help "Search forward for a string"))
347 ;; The Edit->Replace submenu
349 (defvar menu-bar-replace-menu
350 (let ((menu (make-sparse-keymap "Replace")))
351 (bindings--define-key menu [tags-repl-continue]
352 '(menu-item "Continue Replace" tags-loop-continue
353 :help "Continue last tags replace operation"))
354 (bindings--define-key menu [tags-repl]
355 '(menu-item "Replace in Tagged Files..." tags-query-replace
356 :help "Interactively replace a regexp in all tagged files"))
357 (bindings--define-key menu [separator-replace-tags]
360 (bindings--define-key menu [query-replace-regexp]
361 '(menu-item "Replace Regexp..." query-replace-regexp
362 :enable (not buffer-read-only)
363 :help "Replace regular expression interactively, ask about each occurrence"))
364 (bindings--define-key menu [query-replace]
365 '(menu-item "Replace String..." query-replace
366 :enable (not buffer-read-only)
367 :help "Replace string interactively, ask about each occurrence"))
370 ;;; Assemble the top-level Edit menu items.
371 (defvar menu-bar-goto-menu
372 (let ((menu (make-sparse-keymap "Go To")))
374 (bindings--define-key menu [set-tags-name]
375 '(menu-item "Set Tags File Name..." visit-tags-table
376 :help "Tell Tags commands which tag table file to use"))
378 (bindings--define-key menu [separator-tag-file]
381 (bindings--define-key menu [apropos-tags]
382 '(menu-item "Tags Apropos..." tags-apropos
383 :help "Find function/variables whose names match regexp"))
384 (bindings--define-key menu [next-tag-otherw]
385 '(menu-item "Next Tag in Other Window"
386 menu-bar-next-tag-other-window
387 :enable (and (boundp 'tags-location-ring)
388 (not (ring-empty-p tags-location-ring)))
389 :help "Find next function/variable matching last tag name in another window"))
391 (bindings--define-key menu [next-tag]
392 '(menu-item "Find Next Tag"
394 :enable (and (boundp 'tags-location-ring)
395 (not (ring-empty-p tags-location-ring)))
396 :help "Find next function/variable matching last tag name"))
397 (bindings--define-key menu [find-tag-otherw]
398 '(menu-item "Find Tag in Other Window..." find-tag-other-window
399 :help "Find function/variable definition in another window"))
400 (bindings--define-key menu [find-tag]
401 '(menu-item "Find Tag..." find-tag
402 :help "Find definition of function or variable"))
404 (bindings--define-key menu [separator-tags]
407 (bindings--define-key menu [end-of-buf]
408 '(menu-item "Goto End of Buffer" end-of-buffer))
409 (bindings--define-key menu [beg-of-buf]
410 '(menu-item "Goto Beginning of Buffer" beginning-of-buffer))
411 (bindings--define-key menu [go-to-pos]
412 '(menu-item "Goto Buffer Position..." goto-char
413 :help "Read a number N and go to buffer position N"))
414 (bindings--define-key menu [go-to-line]
415 '(menu-item "Goto Line..." goto-line
416 :help "Read a line number and go to that line"))
420 (defvar yank-menu (cons (purecopy "Select Yank") nil))
421 (fset 'yank-menu (cons 'keymap yank-menu))
423 (defvar menu-bar-edit-menu
424 (let ((menu (make-sparse-keymap "Edit")))
426 (bindings--define-key menu [props]
427 `(menu-item "Text Properties" facemenu-menu))
429 ;; ns-win.el said: Add spell for platform consistency.
431 (bindings--define-key menu [spell]
432 `(menu-item "Spell" ispell-menu-map)))
434 (bindings--define-key menu [fill]
435 `(menu-item "Fill" fill-region
436 :enable (and mark-active (not buffer-read-only))
438 "Fill text in region to fit between left and right margin"))
440 (bindings--define-key menu [separator-bookmark]
443 (bindings--define-key menu [bookmark]
444 `(menu-item "Bookmarks" menu-bar-bookmark-map))
446 (bindings--define-key menu [goto]
447 `(menu-item "Go To" ,menu-bar-goto-menu))
449 (bindings--define-key menu [replace]
450 `(menu-item "Replace" ,menu-bar-replace-menu))
452 (bindings--define-key menu [search]
453 `(menu-item "Search" ,menu-bar-search-menu))
455 (bindings--define-key menu [separator-search]
458 (bindings--define-key menu [mark-whole-buffer]
459 '(menu-item "Select All" mark-whole-buffer
460 :help "Mark the whole buffer for a subsequent cut/copy"))
461 (bindings--define-key menu [clear]
462 '(menu-item "Clear" delete-region
463 :enable (and mark-active
464 (not buffer-read-only))
466 "Delete the text in region between mark and current position"))
469 (bindings--define-key menu (if (featurep 'ns) [select-paste]
471 ;; ns-win.el said: Change text to be more consistent with
472 ;; surrounding menu items `paste', etc."
473 `(menu-item ,(if (featurep 'ns) "Select and Paste" "Paste from Kill Menu")
475 :enable (and (cdr yank-menu) (not buffer-read-only))
476 :help "Choose a string from the kill ring and paste it"))
477 (bindings--define-key menu [paste]
478 '(menu-item "Paste" yank
480 (gui-call gui-selection-exists-p 'CLIPBOARD)
481 (if (featurep 'ns) ; like paste-from-menu
484 (not buffer-read-only))
485 :help "Paste (yank) text most recently cut/copied"))
486 (bindings--define-key menu [copy]
487 ;; ns-win.el said: Substitute a Copy function that works better
488 ;; under X (for GNUstep).
489 `(menu-item "Copy" ,(if (featurep 'ns)
490 'ns-copy-including-secondary
493 :help "Copy text in region between mark and current position"
494 :keys ,(if (featurep 'ns)
495 "\\[ns-copy-including-secondary]"
496 "\\[kill-ring-save]")))
497 (bindings--define-key menu [cut]
498 '(menu-item "Cut" kill-region
499 :enable (and mark-active (not buffer-read-only))
501 "Cut (kill) text in region between mark and current position"))
502 ;; ns-win.el said: Separate undo from cut/paste section.
504 (bindings--define-key menu [separator-undo] menu-bar-separator))
506 (bindings--define-key menu [undo]
507 '(menu-item "Undo" undo
508 :enable (and (not buffer-read-only)
509 (not (eq t buffer-undo-list))
510 (if (eq last-command 'undo)
511 (listp pending-undo-list)
512 (consp buffer-undo-list)))
513 :help "Undo last operation"))
517 (defun menu-bar-next-tag-other-window ()
518 "Find the next definition of the tag already specified."
520 (find-tag-other-window nil t))
522 (defun menu-bar-next-tag ()
523 "Find the next definition of the tag already specified."
527 (define-obsolete-function-alias
528 'menu-bar-kill-ring-save 'kill-ring-save "24.1")
530 ;; These are alternative definitions for the cut, paste and copy
531 ;; menu items. Use them if your system expects these to use the clipboard.
533 (put 'clipboard-kill-region 'menu-enable
534 '(and mark-active (not buffer-read-only)))
535 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
536 (put 'clipboard-yank 'menu-enable
537 '(and (or (gui-call gui-selection-exists-p 'PRIMARY)
538 (gui-call gui-selection-exists-p 'CLIPBOARD))
539 (not buffer-read-only)))
541 (defun clipboard-yank ()
542 "Insert the clipboard contents, or the last stretch of killed text."
544 (let ((gui-select-enable-clipboard t))
547 (defun clipboard-kill-ring-save (beg end &optional region)
548 "Copy region to kill ring, and save in the GUI's clipboard."
550 (let ((gui-select-enable-clipboard t))
551 (kill-ring-save beg end region)))
553 (defun clipboard-kill-region (beg end &optional region)
554 "Kill the region, and save it in the GUI's clipboard."
556 (let ((gui-select-enable-clipboard t))
557 (kill-region beg end region)))
559 (defun menu-bar-enable-clipboard ()
560 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
561 Do the same for the keys of the same name."
563 ;; These are Sun server keysyms for the Cut, Copy and Paste keys
564 ;; (also for XFree86 on Sun keyboard):
565 (define-key global-map [f20] 'clipboard-kill-region)
566 (define-key global-map [f16] 'clipboard-kill-ring-save)
567 (define-key global-map [f18] 'clipboard-yank)
569 (define-key global-map [cut] 'clipboard-kill-region)
570 (define-key global-map [copy] 'clipboard-kill-ring-save)
571 (define-key global-map [paste] 'clipboard-yank))
573 ;; The "Options" menu items
575 (defvar menu-bar-custom-menu
576 (let ((menu (make-sparse-keymap "Customize")))
578 (bindings--define-key menu [customize-apropos-faces]
579 '(menu-item "Faces Matching..." customize-apropos-faces
580 :help "Browse faces matching a regexp or word list"))
581 (bindings--define-key menu [customize-apropos-options]
582 '(menu-item "Options Matching..." customize-apropos-options
583 :help "Browse options matching a regexp or word list"))
584 (bindings--define-key menu [customize-apropos]
585 '(menu-item "All Settings Matching..." customize-apropos
586 :help "Browse customizable settings matching a regexp or word list"))
587 (bindings--define-key menu [separator-1]
589 (bindings--define-key menu [customize-group]
590 '(menu-item "Specific Group..." customize-group
591 :help "Customize settings of specific group"))
592 (bindings--define-key menu [customize-face]
593 '(menu-item "Specific Face..." customize-face
594 :help "Customize attributes of specific face"))
595 (bindings--define-key menu [customize-option]
596 '(menu-item "Specific Option..." customize-option
597 :help "Customize value of specific option"))
598 (bindings--define-key menu [separator-2]
600 (bindings--define-key menu [customize-changed-options]
601 '(menu-item "New Options..." customize-changed-options
602 :help "Options added or changed in recent Emacs versions"))
603 (bindings--define-key menu [customize-saved]
604 '(menu-item "Saved Options" customize-saved
605 :help "Customize previously saved options"))
606 (bindings--define-key menu [separator-3]
608 (bindings--define-key menu [customize-browse]
609 '(menu-item "Browse Customization Groups" customize-browse
610 :help "Browse all customization groups"))
611 (bindings--define-key menu [customize]
612 '(menu-item "Top-level Customization Group" customize
613 :help "The master group called `Emacs'"))
614 (bindings--define-key menu [customize-themes]
615 '(menu-item "Custom Themes" customize-themes
616 :help "Choose a pre-defined customization theme"))
618 ;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
620 (defmacro menu-bar-make-mm-toggle (fname doc help &optional props)
621 "Make a menu-item for a global minor mode toggle.
622 FNAME is the minor mode's name (variable and function).
623 DOC is the text to use for the menu entry.
624 HELP is the text to use for the tooltip.
625 PROPS are additional properties."
626 `'(menu-item ,doc ,fname
629 :button (:toggle . (and (default-boundp ',fname)
630 (default-value ',fname)))))
632 (defmacro menu-bar-make-toggle (name variable doc message help &rest body)
634 (defun ,name (&optional interactively)
635 ,(concat "Toggle whether to " (downcase (substring help 0 1))
636 (substring help 1) ".
637 In an interactive call, record this option as a candidate for saving
638 by \"Save Options\" in Custom buffers.")
640 (if ,(if body `(progn . ,body)
642 (custom-load-symbol ',variable)
643 (let ((set (or (get ',variable 'custom-set) 'set-default))
644 (get (or (get ',variable 'custom-get) 'default-value)))
645 (funcall set ',variable (not (funcall get ',variable))))))
646 (message ,message "enabled globally")
647 (message ,message "disabled globally"))
648 ;; The function `customize-mark-as-set' must only be called when
649 ;; a variable is set interactively, as the purpose is to mark it as
650 ;; a candidate for "Save Options", and we do not want to save options
651 ;; the user have already set explicitly in his init file.
652 (if interactively (customize-mark-as-set ',variable)))
653 '(menu-item ,doc ,name
655 :button (:toggle . (and (default-boundp ',variable)
656 (default-value ',variable))))))
658 ;; Function for setting/saving default font.
660 (defun menu-set-font ()
661 "Interactively select a font and make it the default on all existing frames."
663 (set-frame-font (if (fboundp 'x-select-font)
668 (defun menu-bar-options-save ()
669 "Save current values of Options menu items using Custom."
671 (let ((need-save nil))
672 ;; These are set with menu-bar-make-mm-toggle, which does not
673 ;; put on a customized-value property.
674 (dolist (elt '(line-number-mode column-number-mode size-indication-mode
675 cua-mode show-paren-mode transient-mark-mode
676 blink-cursor-mode display-time-mode display-battery-mode
677 ;; These are set by other functions that don't set
678 ;; the customized state. Having them here has the
679 ;; side-effect that turning them off via X
680 ;; resources acts like having customized them, but
681 ;; that seems harmless.
682 menu-bar-mode tool-bar-mode))
683 ;; FIXME ? It's a little annoying that running this command
684 ;; always loads cua-base, paren, time, and battery, even if they
685 ;; have not been customized in any way. (Due to custom-load-symbol.)
686 (and (customize-mark-to-save elt)
688 ;; These are set with `customize-set-variable'.
689 (dolist (elt '(scroll-bar-mode
690 debug-on-quit debug-on-error
691 ;; Somehow this works, when tool-bar and menu-bar don't.
693 save-place uniquify-buffer-name-style fringe-mode
694 indicate-empty-lines indicate-buffer-boundaries
695 case-fold-search font-use-system-font
696 current-language-environment default-input-method
697 ;; Saving `text-mode-hook' is somewhat questionable,
698 ;; as we might get more than we bargain for, if
699 ;; other code may has added hooks as well.
700 ;; Nonetheless, not saving it would like be confuse
702 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
703 text-mode-hook tool-bar-position))
704 (and (get elt 'customized-value)
705 (customize-mark-to-save elt)
707 (when (get 'default 'customized-face)
708 (put 'default 'saved-face (get 'default 'customized-face))
709 (put 'default 'customized-face nil)
711 ;; Save if we changed anything.
716 ;;; Assemble all the top-level items of the "Options" menu
718 ;; The "Show/Hide" submenu of menu "Options"
720 (defun menu-bar-showhide-fringe-ind-customize ()
721 "Show customization buffer for `indicate-buffer-boundaries'."
723 (customize-variable 'indicate-buffer-boundaries))
725 (defun menu-bar-showhide-fringe-ind-mixed ()
726 "Display top and bottom indicators in opposite fringes, arrows in right."
728 (customize-set-variable 'indicate-buffer-boundaries
729 '((t . right) (top . left))))
731 (defun menu-bar-showhide-fringe-ind-box ()
732 "Display top and bottom indicators in opposite fringes."
734 (customize-set-variable 'indicate-buffer-boundaries
735 '((top . left) (bottom . right))))
737 (defun menu-bar-showhide-fringe-ind-right ()
738 "Display buffer boundaries and arrows in the right fringe."
740 (customize-set-variable 'indicate-buffer-boundaries 'right))
742 (defun menu-bar-showhide-fringe-ind-left ()
743 "Display buffer boundaries and arrows in the left fringe."
745 (customize-set-variable 'indicate-buffer-boundaries 'left))
747 (defun menu-bar-showhide-fringe-ind-none ()
748 "Do not display any buffer boundary indicators."
750 (customize-set-variable 'indicate-buffer-boundaries nil))
752 (defvar menu-bar-showhide-fringe-ind-menu
753 (let ((menu (make-sparse-keymap "Buffer boundaries")))
755 (bindings--define-key menu [customize]
756 '(menu-item "Other (Customize)"
757 menu-bar-showhide-fringe-ind-customize
758 :help "Additional choices available through Custom buffer"
759 :visible (display-graphic-p)
760 :button (:radio . (not (member indicate-buffer-boundaries
762 ((top . left) (bottom . right))
763 ((t . right) (top . left))))))))
765 (bindings--define-key menu [mixed]
766 '(menu-item "Opposite, Arrows Right" menu-bar-showhide-fringe-ind-mixed
768 "Show top/bottom indicators in opposite fringes, arrows in right"
769 :visible (display-graphic-p)
770 :button (:radio . (equal indicate-buffer-boundaries
771 '((t . right) (top . left))))))
773 (bindings--define-key menu [box]
774 '(menu-item "Opposite, No Arrows" menu-bar-showhide-fringe-ind-box
775 :help "Show top/bottom indicators in opposite fringes, no arrows"
776 :visible (display-graphic-p)
777 :button (:radio . (equal indicate-buffer-boundaries
778 '((top . left) (bottom . right))))))
780 (bindings--define-key menu [right]
781 '(menu-item "In Right Fringe" menu-bar-showhide-fringe-ind-right
782 :help "Show buffer boundaries and arrows in right fringe"
783 :visible (display-graphic-p)
784 :button (:radio . (eq indicate-buffer-boundaries 'right))))
786 (bindings--define-key menu [left]
787 '(menu-item "In Left Fringe" menu-bar-showhide-fringe-ind-left
788 :help "Show buffer boundaries and arrows in left fringe"
789 :visible (display-graphic-p)
790 :button (:radio . (eq indicate-buffer-boundaries 'left))))
792 (bindings--define-key menu [none]
793 '(menu-item "No Indicators" menu-bar-showhide-fringe-ind-none
794 :help "Hide all buffer boundary indicators and arrows"
795 :visible (display-graphic-p)
796 :button (:radio . (eq indicate-buffer-boundaries nil))))
799 (defun menu-bar-showhide-fringe-menu-customize ()
800 "Show customization buffer for `fringe-mode'."
802 (customize-variable 'fringe-mode))
804 (defun menu-bar-showhide-fringe-menu-customize-reset ()
805 "Reset the fringe mode: display fringes on both sides of a window."
807 (customize-set-variable 'fringe-mode nil))
809 (defun menu-bar-showhide-fringe-menu-customize-right ()
810 "Display fringes only on the right of each window."
813 (customize-set-variable 'fringe-mode '(0 . nil)))
815 (defun menu-bar-showhide-fringe-menu-customize-left ()
816 "Display fringes only on the left of each window."
819 (customize-set-variable 'fringe-mode '(nil . 0)))
821 (defun menu-bar-showhide-fringe-menu-customize-disable ()
822 "Do not display window fringes."
825 (customize-set-variable 'fringe-mode 0))
827 (defvar menu-bar-showhide-fringe-menu
828 (let ((menu (make-sparse-keymap "Fringe")))
830 (bindings--define-key menu [showhide-fringe-ind]
831 `(menu-item "Buffer Boundaries" ,menu-bar-showhide-fringe-ind-menu
832 :visible (display-graphic-p)
833 :help "Indicate buffer boundaries in fringe"))
835 (bindings--define-key menu [indicate-empty-lines]
836 (menu-bar-make-toggle toggle-indicate-empty-lines indicate-empty-lines
837 "Empty Line Indicators"
838 "Indicating of empty lines %s"
839 "Indicate trailing empty lines in fringe, globally"))
841 (bindings--define-key menu [customize]
842 '(menu-item "Customize Fringe" menu-bar-showhide-fringe-menu-customize
843 :help "Detailed customization of fringe"
844 :visible (display-graphic-p)))
846 (bindings--define-key menu [default]
847 '(menu-item "Default" menu-bar-showhide-fringe-menu-customize-reset
848 :help "Default width fringe on both left and right side"
849 :visible (display-graphic-p)
850 :button (:radio . (eq fringe-mode nil))))
852 (bindings--define-key menu [right]
853 '(menu-item "On the Right" menu-bar-showhide-fringe-menu-customize-right
854 :help "Fringe only on the right side"
855 :visible (display-graphic-p)
856 :button (:radio . (equal fringe-mode '(0 . nil)))))
858 (bindings--define-key menu [left]
859 '(menu-item "On the Left" menu-bar-showhide-fringe-menu-customize-left
860 :help "Fringe only on the left side"
861 :visible (display-graphic-p)
862 :button (:radio . (equal fringe-mode '(nil . 0)))))
864 (bindings--define-key menu [none]
865 '(menu-item "None" menu-bar-showhide-fringe-menu-customize-disable
866 :help "Turn off fringe"
867 :visible (display-graphic-p)
868 :button (:radio . (eq fringe-mode 0))))
871 (defun menu-bar-right-scroll-bar ()
872 "Display scroll bars on the right of each window."
874 (customize-set-variable 'scroll-bar-mode 'right))
876 (defun menu-bar-left-scroll-bar ()
877 "Display scroll bars on the left of each window."
879 (customize-set-variable 'scroll-bar-mode 'left))
881 (defun menu-bar-no-scroll-bar ()
882 "Turn off scroll bars."
884 (customize-set-variable 'scroll-bar-mode nil))
886 (defun menu-bar-horizontal-scroll-bar ()
887 "Display horizontal scroll bars on each window."
889 (customize-set-variable 'horizontal-scroll-bar-mode t))
891 (defun menu-bar-no-horizontal-scroll-bar ()
892 "Turn off horizontal scroll bars."
894 (customize-set-variable 'horizontal-scroll-bar-mode nil))
896 (defvar menu-bar-showhide-scroll-bar-menu
897 (let ((menu (make-sparse-keymap "Scroll-bar")))
898 (bindings--define-key menu [horizontal]
899 '(menu-item "Horizontal"
900 menu-bar-horizontal-scroll-bar
901 :help "Horizontal scroll bar"
902 :visible (horizontal-scroll-bars-available-p)
903 :button (:radio . (cdr (assq 'horizontal-scroll-bars
904 (frame-parameters))))))
906 (bindings--define-key menu [none-horizontal]
907 '(menu-item "None-horizontal"
908 menu-bar-no-horizontal-scroll-bar
909 :help "Turn off horizontal scroll bars"
910 :visible (horizontal-scroll-bars-available-p)
911 :button (:radio . (not (cdr (assq 'horizontal-scroll-bars
912 (frame-parameters)))))))
914 (bindings--define-key menu [right]
915 '(menu-item "On the Right"
916 menu-bar-right-scroll-bar
917 :help "Scroll-bar on the right side"
918 :visible (display-graphic-p)
919 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
923 (bindings--define-key menu [left]
924 '(menu-item "On the Left"
925 menu-bar-left-scroll-bar
926 :help "Scroll-bar on the left side"
927 :visible (display-graphic-p)
928 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
932 (bindings--define-key menu [none]
934 menu-bar-no-scroll-bar
935 :help "Turn off scroll-bar"
936 :visible (display-graphic-p)
937 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
942 (defun menu-bar-frame-for-menubar ()
943 "Return the frame suitable for updating the menu bar."
944 (or (and (framep menu-updating-frame)
948 (defun menu-bar-positive-p (val)
949 "Return non-nil if VAL is a positive number."
953 (defun menu-bar-set-tool-bar-position (position)
954 (customize-set-variable 'tool-bar-mode t)
955 (customize-set-variable 'tool-bar-position position))
956 (defun menu-bar-showhide-tool-bar-menu-customize-disable ()
957 "Do not display tool bars."
959 (customize-set-variable 'tool-bar-mode nil))
960 (defun menu-bar-showhide-tool-bar-menu-customize-enable-left ()
961 "Display tool bars on the left side."
963 (menu-bar-set-tool-bar-position 'left))
964 (defun menu-bar-showhide-tool-bar-menu-customize-enable-right ()
965 "Display tool bars on the right side."
967 (menu-bar-set-tool-bar-position 'right))
968 (defun menu-bar-showhide-tool-bar-menu-customize-enable-top ()
969 "Display tool bars on the top side."
971 (menu-bar-set-tool-bar-position 'top))
972 (defun menu-bar-showhide-tool-bar-menu-customize-enable-bottom ()
973 "Display tool bars on the bottom side."
975 (menu-bar-set-tool-bar-position 'bottom))
977 (when (featurep 'move-toolbar)
978 (defvar menu-bar-showhide-tool-bar-menu
979 (let ((menu (make-sparse-keymap "Tool-bar")))
981 (bindings--define-key menu [showhide-tool-bar-left]
982 '(menu-item "On the Left"
983 menu-bar-showhide-tool-bar-menu-customize-enable-left
984 :help "Tool-bar at the left side"
985 :visible (display-graphic-p)
987 (:radio . (and tool-bar-mode
989 (menu-bar-frame-for-menubar)
993 (bindings--define-key menu [showhide-tool-bar-right]
994 '(menu-item "On the Right"
995 menu-bar-showhide-tool-bar-menu-customize-enable-right
996 :help "Tool-bar at the right side"
997 :visible (display-graphic-p)
999 (:radio . (and tool-bar-mode
1000 (eq (frame-parameter
1001 (menu-bar-frame-for-menubar)
1005 (bindings--define-key menu [showhide-tool-bar-bottom]
1006 '(menu-item "On the Bottom"
1007 menu-bar-showhide-tool-bar-menu-customize-enable-bottom
1008 :help "Tool-bar at the bottom"
1009 :visible (display-graphic-p)
1011 (:radio . (and tool-bar-mode
1012 (eq (frame-parameter
1013 (menu-bar-frame-for-menubar)
1017 (bindings--define-key menu [showhide-tool-bar-top]
1018 '(menu-item "On the Top"
1019 menu-bar-showhide-tool-bar-menu-customize-enable-top
1020 :help "Tool-bar at the top"
1021 :visible (display-graphic-p)
1023 (:radio . (and tool-bar-mode
1024 (eq (frame-parameter
1025 (menu-bar-frame-for-menubar)
1029 (bindings--define-key menu [showhide-tool-bar-none]
1031 menu-bar-showhide-tool-bar-menu-customize-disable
1032 :help "Turn tool-bar off"
1033 :visible (display-graphic-p)
1034 :button (:radio . (eq tool-bar-mode nil))))
1037 (defvar menu-bar-showhide-menu
1038 (let ((menu (make-sparse-keymap "Show/Hide")))
1040 (bindings--define-key menu [column-number-mode]
1041 (menu-bar-make-mm-toggle column-number-mode
1043 "Show the current column number in the mode line"))
1045 (bindings--define-key menu [line-number-mode]
1046 (menu-bar-make-mm-toggle line-number-mode
1048 "Show the current line number in the mode line"))
1050 (bindings--define-key menu [size-indication-mode]
1051 (menu-bar-make-mm-toggle size-indication-mode
1053 "Show the size of the buffer in the mode line"))
1055 (bindings--define-key menu [linecolumn-separator]
1058 (bindings--define-key menu [showhide-battery]
1059 (menu-bar-make-mm-toggle display-battery-mode
1061 "Display battery status information in mode line"))
1063 (bindings--define-key menu [showhide-date-time]
1064 (menu-bar-make-mm-toggle display-time-mode
1065 "Time, Load and Mail"
1066 "Display time, system load averages and \
1067 mail status in mode line"))
1069 (bindings--define-key menu [datetime-separator]
1072 (bindings--define-key menu [showhide-speedbar]
1073 '(menu-item "Speedbar" speedbar-frame-mode
1074 :help "Display a Speedbar quick-navigation frame"
1076 . (and (boundp 'speedbar-frame)
1077 (frame-live-p (symbol-value 'speedbar-frame))
1079 (symbol-value 'speedbar-frame))))))
1081 (bindings--define-key menu [showhide-fringe]
1082 `(menu-item "Fringe" ,menu-bar-showhide-fringe-menu
1083 :visible (display-graphic-p)))
1085 (bindings--define-key menu [showhide-scroll-bar]
1086 `(menu-item "Scroll-bar" ,menu-bar-showhide-scroll-bar-menu
1087 :visible (display-graphic-p)))
1089 (bindings--define-key menu [showhide-tooltip-mode]
1090 '(menu-item "Tooltips" tooltip-mode
1091 :help "Turn tooltips on/off"
1092 :visible (and (display-graphic-p) (fboundp 'x-show-tip))
1093 :button (:toggle . tooltip-mode)))
1095 (bindings--define-key menu [menu-bar-mode]
1096 '(menu-item "Menu-bar" toggle-menu-bar-mode-from-frame
1097 :help "Turn menu-bar on/off"
1099 (:toggle . (menu-bar-positive-p
1100 (frame-parameter (menu-bar-frame-for-menubar)
1101 'menu-bar-lines)))))
1103 (if (and (boundp 'menu-bar-showhide-tool-bar-menu)
1104 (keymapp menu-bar-showhide-tool-bar-menu))
1105 (bindings--define-key menu [showhide-tool-bar]
1106 `(menu-item "Tool-bar" ,menu-bar-showhide-tool-bar-menu
1107 :visible (display-graphic-p)))
1108 ;; else not tool bar that can move.
1109 (bindings--define-key menu [showhide-tool-bar]
1110 '(menu-item "Tool-bar" toggle-tool-bar-mode-from-frame
1111 :help "Turn tool-bar on/off"
1112 :visible (display-graphic-p)
1114 (:toggle . (menu-bar-positive-p
1115 (frame-parameter (menu-bar-frame-for-menubar)
1116 'tool-bar-lines))))))
1119 (defvar menu-bar-line-wrapping-menu
1120 (let ((menu (make-sparse-keymap "Line Wrapping")))
1122 (bindings--define-key menu [word-wrap]
1123 `(menu-item "Word Wrap (Visual Line mode)"
1126 (unless visual-line-mode
1127 (visual-line-mode 1))
1128 (message "Visual-Line mode enabled"))
1129 :help "Wrap long lines at word boundaries"
1131 . (and (null truncate-lines)
1132 (not (truncated-partial-width-window-p))
1134 :visible (menu-bar-menu-frame-live-and-visible-p)))
1136 (bindings--define-key menu [truncate]
1137 `(menu-item "Truncate Long Lines"
1140 (if visual-line-mode (visual-line-mode 0))
1141 (setq word-wrap nil)
1142 (toggle-truncate-lines 1))
1143 :help "Truncate long lines at window edge"
1144 :button (:radio . (or truncate-lines
1145 (truncated-partial-width-window-p)))
1146 :visible (menu-bar-menu-frame-live-and-visible-p)
1147 :enable (not (truncated-partial-width-window-p))))
1149 (bindings--define-key menu [window-wrap]
1150 `(menu-item "Wrap at Window Edge"
1151 ,(lambda () (interactive)
1152 (if visual-line-mode (visual-line-mode 0))
1153 (setq word-wrap nil)
1154 (if truncate-lines (toggle-truncate-lines -1)))
1155 :help "Wrap long lines at window edge"
1157 . (and (null truncate-lines)
1158 (not (truncated-partial-width-window-p))
1160 :visible (menu-bar-menu-frame-live-and-visible-p)
1161 :enable (not (truncated-partial-width-window-p))))
1164 (defvar menu-bar-options-menu
1165 (let ((menu (make-sparse-keymap "Options")))
1166 (bindings--define-key menu [customize]
1167 `(menu-item "Customize Emacs" ,menu-bar-custom-menu))
1169 (bindings--define-key menu [package]
1170 '(menu-item "Manage Emacs Packages" package-list-packages
1171 :help "Install or uninstall additional Emacs packages"))
1173 (bindings--define-key menu [save]
1174 '(menu-item "Save Options" menu-bar-options-save
1175 :help "Save options set from the menu above"))
1177 (bindings--define-key menu [custom-separator]
1180 (bindings--define-key menu [menu-set-font]
1181 '(menu-item "Set Default Font..." menu-set-font
1182 :visible (display-multi-font-p)
1183 :help "Select a default font"))
1185 (if (featurep 'system-font-setting)
1186 (bindings--define-key menu [menu-system-font]
1187 (menu-bar-make-toggle
1188 toggle-use-system-font font-use-system-font
1190 "Use system font: %s"
1191 "Use the monospaced font defined by the system")))
1193 (bindings--define-key menu [showhide]
1194 `(menu-item "Show/Hide" ,menu-bar-showhide-menu))
1196 (bindings--define-key menu [showhide-separator]
1199 (bindings--define-key menu [mule]
1200 ;; It is better not to use backquote here,
1201 ;; because that makes a bootstrapping problem
1202 ;; if you need to recompile all the Lisp files using interpreted code.
1203 `(menu-item "Multilingual Environment" ,mule-menu-keymap
1204 ;; Most of the MULE menu actually does make sense in
1205 ;; unibyte mode, e.g. language selection.
1206 ;; :visible '(default-value 'enable-multibyte-characters)
1208 ;;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
1209 ;;(bindings--define-key menu [preferences]
1210 ;; `(menu-item "Preferences" ,menu-bar-preferences-menu
1211 ;; :help "Toggle important global options"))
1213 (bindings--define-key menu [mule-separator]
1216 (bindings--define-key menu [debug-on-quit]
1217 (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
1218 "Enter Debugger on Quit/C-g" "Debug on Quit %s"
1219 "Enter Lisp debugger when C-g is pressed"))
1220 (bindings--define-key menu [debug-on-error]
1221 (menu-bar-make-toggle toggle-debug-on-error debug-on-error
1222 "Enter Debugger on Error" "Debug on Error %s"
1223 "Enter Lisp debugger when an error is signaled"))
1224 (bindings--define-key menu [debugger-separator]
1227 (bindings--define-key menu [blink-cursor-mode]
1228 (menu-bar-make-mm-toggle
1231 "Whether the cursor blinks (Blink Cursor mode)"))
1232 (bindings--define-key menu [cursor-separator]
1235 (bindings--define-key menu [save-place]
1236 (menu-bar-make-toggle
1237 toggle-save-place-globally save-place
1238 "Save Place in Files between Sessions"
1239 "Saving place in files %s"
1240 "Visit files of previous session when restarting Emacs"
1241 (require 'saveplace)
1242 ;; Do it by name, to avoid a free-variable
1243 ;; warning during byte compilation.
1245 'save-place (not (symbol-value 'save-place)))))
1247 (bindings--define-key menu [uniquify]
1248 (menu-bar-make-toggle
1249 toggle-uniquify-buffer-names uniquify-buffer-name-style
1250 "Use Directory Names in Buffer Names"
1251 "Directory name in buffer names (uniquify) %s"
1252 "Uniquify buffer names by adding parent directory names"
1253 (setq uniquify-buffer-name-style
1254 (if (not uniquify-buffer-name-style)
1255 'post-forward-angle-brackets))))
1257 (bindings--define-key menu [edit-options-separator]
1259 (bindings--define-key menu [cua-mode]
1260 (menu-bar-make-mm-toggle
1262 "Use CUA Keys (Cut/Paste with C-x/C-c/C-v)"
1263 "Use C-z/C-x/C-c/C-v keys for undo/cut/copy/paste"
1264 (:visible (or (not (boundp 'cua-enable-cua-keys))
1265 cua-enable-cua-keys))))
1267 (bindings--define-key menu [cua-emulation-mode]
1268 (menu-bar-make-mm-toggle
1270 "Shift movement mark region (CUA)"
1271 "Use shifted movement keys to set and extend the region"
1272 (:visible (and (boundp 'cua-enable-cua-keys)
1273 (not cua-enable-cua-keys)))))
1275 (bindings--define-key menu [case-fold-search]
1276 (menu-bar-make-toggle
1277 toggle-case-fold-search case-fold-search
1278 "Ignore Case for Search"
1279 "Case-Insensitive Search %s"
1280 "Ignore letter-case in search commands"))
1282 (bindings--define-key menu [line-wrapping]
1283 `(menu-item "Line Wrapping in This Buffer"
1284 ,menu-bar-line-wrapping-menu))
1287 (bindings--define-key menu [highlight-separator]
1289 (bindings--define-key menu [highlight-paren-mode]
1290 (menu-bar-make-mm-toggle
1292 "Highlight Matching Parentheses"
1293 "Highlight matching/mismatched parentheses at cursor (Show Paren mode)"))
1294 (bindings--define-key menu [transient-mark-mode]
1295 (menu-bar-make-mm-toggle
1297 "Highlight Active Region"
1298 "Make text in active region stand out in color (Transient Mark mode)"
1299 (:enable (not cua-mode))))
1303 ;; The "Tools" menu items
1305 (defvar menu-bar-games-menu
1306 (let ((menu (make-sparse-keymap "Games")))
1308 (bindings--define-key menu [zone]
1309 '(menu-item "Zone Out" zone
1310 :help "Play tricks with Emacs display when Emacs is idle"))
1311 (bindings--define-key menu [tetris]
1312 '(menu-item "Tetris" tetris
1313 :help "Falling blocks game"))
1314 (bindings--define-key menu [solitaire]
1315 '(menu-item "Solitaire" solitaire
1316 :help "Get rid of all the stones"))
1317 (bindings--define-key menu [snake]
1318 '(menu-item "Snake" snake
1319 :help "Move snake around avoiding collisions"))
1320 (bindings--define-key menu [pong]
1321 '(menu-item "Pong" pong
1322 :help "Bounce the ball to your opponent"))
1323 (bindings--define-key menu [mult]
1324 '(menu-item "Multiplication Puzzle" mpuz
1325 :help "Exercise brain with multiplication"))
1326 (bindings--define-key menu [life]
1327 '(menu-item "Life" life
1328 :help "Watch how John Conway's cellular automaton evolves"))
1329 (bindings--define-key menu [hanoi]
1330 '(menu-item "Towers of Hanoi" hanoi
1331 :help "Watch Towers-of-Hanoi puzzle solved by Emacs"))
1332 (bindings--define-key menu [gomoku]
1333 '(menu-item "Gomoku" gomoku
1334 :help "Mark 5 contiguous squares (like tic-tac-toe)"))
1335 (bindings--define-key menu [bubbles]
1336 '(menu-item "Bubbles" bubbles
1337 :help "Remove all bubbles using the fewest moves"))
1338 (bindings--define-key menu [black-box]
1339 '(menu-item "Blackbox" blackbox
1340 :help "Find balls in a black box by shooting rays"))
1341 (bindings--define-key menu [adventure]
1342 '(menu-item "Adventure" dunnet
1343 :help "Dunnet, a text Adventure game for Emacs"))
1344 (bindings--define-key menu [5x5]
1345 '(menu-item "5x5" 5x5
1346 :help "Fill in all the squares on a 5x5 board"))
1349 (defvar menu-bar-encryption-decryption-menu
1350 (let ((menu (make-sparse-keymap "Encryption/Decryption")))
1351 (bindings--define-key menu [insert-keys]
1352 '(menu-item "Insert Keys" epa-insert-keys
1353 :help "Insert public keys after the current point"))
1355 (bindings--define-key menu [export-keys]
1356 '(menu-item "Export Keys" epa-export-keys
1357 :help "Export public keys to a file"))
1359 (bindings--define-key menu [import-keys-region]
1360 '(menu-item "Import Keys from Region" epa-import-keys-region
1361 :help "Import public keys from the current region"))
1363 (bindings--define-key menu [import-keys]
1364 '(menu-item "Import Keys from File..." epa-import-keys
1365 :help "Import public keys from a file"))
1367 (bindings--define-key menu [list-keys]
1368 '(menu-item "List Keys" epa-list-keys
1369 :help "Browse your public keyring"))
1371 (bindings--define-key menu [separator-keys]
1374 (bindings--define-key menu [sign-region]
1375 '(menu-item "Sign Region" epa-sign-region
1376 :help "Create digital signature of the current region"))
1378 (bindings--define-key menu [verify-region]
1379 '(menu-item "Verify Region" epa-verify-region
1380 :help "Verify digital signature of the current region"))
1382 (bindings--define-key menu [encrypt-region]
1383 '(menu-item "Encrypt Region" epa-encrypt-region
1384 :help "Encrypt the current region"))
1386 (bindings--define-key menu [decrypt-region]
1387 '(menu-item "Decrypt Region" epa-decrypt-region
1388 :help "Decrypt the current region"))
1390 (bindings--define-key menu [separator-file]
1393 (bindings--define-key menu [sign-file]
1394 '(menu-item "Sign File..." epa-sign-file
1395 :help "Create digital signature of a file"))
1397 (bindings--define-key menu [verify-file]
1398 '(menu-item "Verify File..." epa-verify-file
1399 :help "Verify digital signature of a file"))
1401 (bindings--define-key menu [encrypt-file]
1402 '(menu-item "Encrypt File..." epa-encrypt-file
1403 :help "Encrypt a file"))
1405 (bindings--define-key menu [decrypt-file]
1406 '(menu-item "Decrypt File..." epa-decrypt-file
1407 :help "Decrypt a file"))
1411 (defun menu-bar-read-mail ()
1412 "Read mail using `read-mail-command'."
1414 (call-interactively read-mail-command))
1416 (defvar menu-bar-tools-menu
1417 (let ((menu (make-sparse-keymap "Tools")))
1419 (bindings--define-key menu [games]
1420 `(menu-item "Games" ,menu-bar-games-menu))
1422 (bindings--define-key menu [separator-games]
1425 (bindings--define-key menu [encryption-decryption]
1426 `(menu-item "Encryption/Decryption"
1427 ,menu-bar-encryption-decryption-menu))
1429 (bindings--define-key menu [separator-encryption-decryption]
1432 (bindings--define-key menu [simple-calculator]
1433 '(menu-item "Simple Calculator" calculator
1434 :help "Invoke the Emacs built-in quick calculator"))
1435 (bindings--define-key menu [calc]
1436 '(menu-item "Programmable Calculator" calc
1437 :help "Invoke the Emacs built-in full scientific calculator"))
1438 (bindings--define-key menu [calendar]
1439 '(menu-item "Calendar" calendar
1440 :help "Invoke the Emacs built-in calendar"))
1442 (bindings--define-key menu [separator-net]
1445 (bindings--define-key menu [browse-web]
1446 '(menu-item "Browse the Web..." browse-web))
1447 (bindings--define-key menu [directory-search]
1448 '(menu-item "Directory Search" eudc-tools-menu))
1449 (bindings--define-key menu [compose-mail]
1450 '(menu-item "Compose New Mail" compose-mail
1451 :visible (and mail-user-agent (not (eq mail-user-agent 'ignore)))
1452 :help "Start writing a new mail message"))
1453 (bindings--define-key menu [rmail]
1454 '(menu-item "Read Mail" menu-bar-read-mail
1455 :visible (and read-mail-command
1456 (not (eq read-mail-command 'ignore)))
1457 :help "Read your mail"))
1459 (bindings--define-key menu [gnus]
1460 '(menu-item "Read Net News" gnus
1461 :help "Read network news groups"))
1463 (bindings--define-key menu [separator-vc]
1466 (bindings--define-key menu [vc] nil) ;Create the place for the VC menu.
1468 (bindings--define-key menu [separator-compare]
1471 (bindings--define-key menu [epatch]
1472 '(menu-item "Apply Patch" menu-bar-epatch-menu))
1473 (bindings--define-key menu [ediff-merge]
1474 '(menu-item "Merge" menu-bar-ediff-merge-menu))
1475 (bindings--define-key menu [compare]
1476 '(menu-item "Compare (Ediff)" menu-bar-ediff-menu))
1478 (bindings--define-key menu [separator-spell]
1481 (bindings--define-key menu [spell]
1482 '(menu-item "Spell Checking" ispell-menu-map))
1484 (bindings--define-key menu [separator-prog]
1487 (bindings--define-key menu [semantic]
1488 '(menu-item "Source Code Parsers (Semantic)"
1490 :help "Toggle automatic parsing in source code buffers (Semantic mode)"
1491 :button (:toggle . (bound-and-true-p semantic-mode))))
1493 (bindings--define-key menu [ede]
1494 '(menu-item "Project Support (EDE)"
1496 :help "Toggle the Emacs Development Environment (Global EDE mode)"
1497 :button (:toggle . (bound-and-true-p global-ede-mode))))
1499 (bindings--define-key menu [gdb]
1500 '(menu-item "Debugger (GDB)..." gdb
1501 :help "Debug a program from within Emacs with GDB"))
1502 (bindings--define-key menu [shell-on-region]
1503 '(menu-item "Shell Command on Region..." shell-command-on-region
1505 :help "Pass marked region to a shell command"))
1506 (bindings--define-key menu [shell]
1507 '(menu-item "Shell Command..." shell-command
1508 :help "Invoke a shell command and catch its output"))
1509 (bindings--define-key menu [compile]
1510 '(menu-item "Compile..." compile
1511 :help "Invoke compiler or Make, view compilation errors"))
1512 (bindings--define-key menu [grep]
1513 '(menu-item "Search Files (Grep)..." grep
1514 :help "Search files for strings or regexps (with Grep)"))
1517 ;; The "Help" menu items
1519 (defvar menu-bar-describe-menu
1520 (let ((menu (make-sparse-keymap "Describe")))
1522 (bindings--define-key menu [mule-diag]
1523 '(menu-item "Show All of Mule Status" mule-diag
1524 :visible (default-value 'enable-multibyte-characters)
1525 :help "Display multilingual environment settings"))
1526 (bindings--define-key menu [describe-coding-system-briefly]
1527 '(menu-item "Describe Coding System (Briefly)"
1528 describe-current-coding-system-briefly
1529 :visible (default-value 'enable-multibyte-characters)))
1530 (bindings--define-key menu [describe-coding-system]
1531 '(menu-item "Describe Coding System..." describe-coding-system
1532 :visible (default-value 'enable-multibyte-characters)))
1533 (bindings--define-key menu [describe-input-method]
1534 '(menu-item "Describe Input Method..." describe-input-method
1535 :visible (default-value 'enable-multibyte-characters)
1536 :help "Keyboard layout for specific input method"))
1537 (bindings--define-key menu [describe-language-environment]
1538 `(menu-item "Describe Language Environment"
1539 ,describe-language-environment-map))
1541 (bindings--define-key menu [separator-desc-mule]
1544 (bindings--define-key menu [list-keybindings]
1545 '(menu-item "List Key Bindings" describe-bindings
1546 :help "Display all current key bindings (keyboard shortcuts)"))
1547 (bindings--define-key menu [describe-current-display-table]
1548 '(menu-item "Describe Display Table" describe-current-display-table
1549 :help "Describe the current display table"))
1550 (bindings--define-key menu [describe-package]
1551 '(menu-item "Describe Package..." describe-package
1552 :help "Display documentation of a Lisp package"))
1553 (bindings--define-key menu [describe-face]
1554 '(menu-item "Describe Face..." describe-face
1555 :help "Display the properties of a face"))
1556 (bindings--define-key menu [describe-variable]
1557 '(menu-item "Describe Variable..." describe-variable
1558 :help "Display documentation of variable/option"))
1559 (bindings--define-key menu [describe-function]
1560 '(menu-item "Describe Function..." describe-function
1561 :help "Display documentation of function/command"))
1562 (bindings--define-key menu [describe-key-1]
1563 '(menu-item "Describe Key or Mouse Operation..." describe-key
1564 ;; Users typically don't identify keys and menu items...
1565 :help "Display documentation of command bound to a \
1566 key, a click, or a menu-item"))
1567 (bindings--define-key menu [describe-mode]
1568 '(menu-item "Describe Buffer Modes" describe-mode
1569 :help "Describe this buffer's major and minor mode"))
1572 (defun menu-bar-read-lispref ()
1573 "Display the Emacs Lisp Reference manual in Info mode."
1577 (defun menu-bar-read-lispintro ()
1578 "Display the Introduction to Emacs Lisp Programming in Info mode."
1582 (defun search-emacs-glossary ()
1583 "Display the Glossary node of the Emacs manual in Info mode."
1585 (info "(emacs)Glossary"))
1587 (defun emacs-index-search (topic)
1588 "Look up TOPIC in the indices of the Emacs User Manual."
1589 (interactive "sSubject to look up: ")
1593 (defun elisp-index-search (topic)
1594 "Look up TOPIC in the indices of the Emacs Lisp Reference Manual."
1595 (interactive "sSubject to look up: ")
1599 (defvar menu-bar-search-documentation-menu
1600 (let ((menu (make-sparse-keymap "Search Documentation")))
1602 (bindings--define-key menu [search-documentation-strings]
1603 '(menu-item "Search Documentation Strings..." apropos-documentation
1605 "Find functions and variables whose doc strings match a regexp"))
1606 (bindings--define-key menu [find-any-object-by-name]
1607 '(menu-item "Find Any Object by Name..." apropos
1608 :help "Find symbols of any kind whose names match a regexp"))
1609 (bindings--define-key menu [find-option-by-value]
1610 '(menu-item "Find Options by Value..." apropos-value
1611 :help "Find variables whose values match a regexp"))
1612 (bindings--define-key menu [find-options-by-name]
1613 '(menu-item "Find Options by Name..." apropos-user-option
1614 :help "Find user options whose names match a regexp"))
1615 (bindings--define-key menu [find-commands-by-name]
1616 '(menu-item "Find Commands by Name..." apropos-command
1617 :help "Find commands whose names match a regexp"))
1618 (bindings--define-key menu [sep1]
1620 (bindings--define-key menu [lookup-command-in-manual]
1621 '(menu-item "Look Up Command in User Manual..." Info-goto-emacs-command-node
1622 :help "Display manual section that describes a command"))
1623 (bindings--define-key menu [lookup-key-in-manual]
1624 '(menu-item "Look Up Key in User Manual..." Info-goto-emacs-key-command-node
1625 :help "Display manual section that describes a key"))
1626 (bindings--define-key menu [lookup-subject-in-elisp-manual]
1627 '(menu-item "Look Up Subject in ELisp Manual..." elisp-index-search
1628 :help "Find description of a subject in Emacs Lisp manual"))
1629 (bindings--define-key menu [lookup-subject-in-emacs-manual]
1630 '(menu-item "Look Up Subject in User Manual..." emacs-index-search
1631 :help "Find description of a subject in Emacs User manual"))
1632 (bindings--define-key menu [emacs-terminology]
1633 '(menu-item "Emacs Terminology" search-emacs-glossary
1634 :help "Display the Glossary section of the Emacs manual"))
1637 (defvar menu-bar-manuals-menu
1638 (let ((menu (make-sparse-keymap "More Manuals")))
1640 (bindings--define-key menu [man]
1641 '(menu-item "Read Man Page..." manual-entry
1642 :help "Man-page docs for external commands and libraries"))
1643 (bindings--define-key menu [sep2]
1645 (bindings--define-key menu [order-emacs-manuals]
1646 '(menu-item "Ordering Manuals" view-order-manuals
1647 :help "How to order manuals from the Free Software Foundation"))
1648 (bindings--define-key menu [lookup-subject-in-all-manuals]
1649 '(menu-item "Lookup Subject in all Manuals..." info-apropos
1650 :help "Find description of a subject in all installed manuals"))
1651 (bindings--define-key menu [other-manuals]
1652 '(menu-item "All Other Manuals (Info)" Info-directory
1653 :help "Read any of the installed manuals"))
1654 (bindings--define-key menu [emacs-lisp-reference]
1655 '(menu-item "Emacs Lisp Reference" menu-bar-read-lispref
1656 :help "Read the Emacs Lisp Reference manual"))
1657 (bindings--define-key menu [emacs-lisp-intro]
1658 '(menu-item "Introduction to Emacs Lisp" menu-bar-read-lispintro
1659 :help "Read the Introduction to Emacs Lisp Programming"))
1662 (defun help-with-tutorial-spec-language ()
1663 "Use the Emacs tutorial, specifying which language you want."
1665 (help-with-tutorial t))
1667 (defvar menu-bar-help-menu
1668 (let ((menu (make-sparse-keymap "Help")))
1669 (bindings--define-key menu [about-gnu-project]
1670 '(menu-item "About GNU" describe-gnu-project
1671 :help "About the GNU System, GNU Project, and GNU/Linux"))
1672 (bindings--define-key menu [about-emacs]
1673 '(menu-item "About Emacs" about-emacs
1674 :help "Display version number, copyright info, and basic help"))
1675 (bindings--define-key menu [sep4]
1677 (bindings--define-key menu [describe-no-warranty]
1678 '(menu-item "(Non)Warranty" describe-no-warranty
1679 :help "Explain that Emacs has NO WARRANTY"))
1680 (bindings--define-key menu [describe-copying]
1681 '(menu-item "Copying Conditions" describe-copying
1682 :help "Show the Emacs license (GPL)"))
1683 (bindings--define-key menu [getting-new-versions]
1684 '(menu-item "Getting New Versions" describe-distribution
1685 :help "How to get the latest version of Emacs"))
1686 (bindings--define-key menu [sep2]
1688 (bindings--define-key menu [external-packages]
1689 '(menu-item "Finding Extra Packages" view-external-packages
1690 :help "How to get more Lisp packages for use in Emacs"))
1691 (bindings--define-key menu [find-emacs-packages]
1692 '(menu-item "Search Built-in Packages" finder-by-keyword
1693 :help "Find built-in packages and features by keyword"))
1694 (bindings--define-key menu [more-manuals]
1695 `(menu-item "More Manuals" ,menu-bar-manuals-menu))
1696 (bindings--define-key menu [emacs-manual]
1697 '(menu-item "Read the Emacs Manual" info-emacs-manual
1698 :help "Full documentation of Emacs features"))
1699 (bindings--define-key menu [describe]
1700 `(menu-item "Describe" ,menu-bar-describe-menu))
1701 (bindings--define-key menu [search-documentation]
1702 `(menu-item "Search Documentation" ,menu-bar-search-documentation-menu))
1703 (bindings--define-key menu [sep1]
1705 (bindings--define-key menu [emacs-psychotherapist]
1706 '(menu-item "Emacs Psychotherapist" doctor
1707 :help "Our doctor will help you feel better"))
1708 (bindings--define-key menu [send-emacs-bug-report]
1709 '(menu-item "Send Bug Report..." report-emacs-bug
1710 :help "Send e-mail to Emacs maintainers"))
1711 (bindings--define-key menu [emacs-manual-bug]
1712 '(menu-item "How to Report a Bug" info-emacs-bug
1713 :help "Read about how to report an Emacs bug"))
1714 (bindings--define-key menu [emacs-known-problems]
1715 '(menu-item "Emacs Known Problems" view-emacs-problems
1716 :help "Read about known problems with Emacs"))
1717 (bindings--define-key menu [emacs-news]
1718 '(menu-item "Emacs News" view-emacs-news
1719 :help "New features of this version"))
1720 (bindings--define-key menu [emacs-faq]
1721 '(menu-item "Emacs FAQ" view-emacs-FAQ
1722 :help "Frequently asked (and answered) questions about Emacs"))
1724 (bindings--define-key menu [emacs-tutorial-language-specific]
1725 '(menu-item "Emacs Tutorial (choose language)..."
1726 help-with-tutorial-spec-language
1727 :help "Learn how to use Emacs (choose a language)"))
1728 (bindings--define-key menu [emacs-tutorial]
1729 '(menu-item "Emacs Tutorial" help-with-tutorial
1730 :help "Learn how to use Emacs"))
1732 ;; In OS X it's in the app menu already.
1733 ;; FIXME? There already is an "About Emacs" (sans ...) entry in the Help menu.
1735 (not (eq system-type 'darwin))
1736 (bindings--define-key menu [info-panel]
1737 '(menu-item "About Emacs..." ns-do-emacs-info-panel)))
1740 (bindings--define-key global-map [menu-bar tools]
1741 (cons "Tools" menu-bar-tools-menu))
1742 (bindings--define-key global-map [menu-bar buffer]
1743 (cons "Buffers" global-buffers-menu-map))
1744 (bindings--define-key global-map [menu-bar options]
1745 (cons "Options" menu-bar-options-menu))
1746 (bindings--define-key global-map [menu-bar edit]
1747 (cons "Edit" menu-bar-edit-menu))
1748 (bindings--define-key global-map [menu-bar file]
1749 (cons "File" menu-bar-file-menu))
1750 (bindings--define-key global-map [menu-bar help-menu]
1751 (cons (purecopy "Help") menu-bar-help-menu))
1753 (defun menu-bar-menu-frame-live-and-visible-p ()
1754 "Return non-nil if the menu frame is alive and visible.
1755 The menu frame is the frame for which we are updating the menu."
1756 (let ((menu-frame (or menu-updating-frame (selected-frame))))
1757 (and (frame-live-p menu-frame)
1758 (frame-visible-p menu-frame))))
1760 (defun menu-bar-non-minibuffer-window-p ()
1761 "Return non-nil if selected window of the menu frame is not a minibuf window.
1763 See the documentation of `menu-bar-menu-frame-live-and-visible-p'
1764 for the definition of the menu frame."
1765 (let ((menu-frame (or menu-updating-frame (selected-frame))))
1766 (not (window-minibuffer-p (frame-selected-window menu-frame)))))
1768 (defun kill-this-buffer () ; for the menu bar
1769 "Kill the current buffer.
1770 When called in the minibuffer, get out of the minibuffer
1771 using `abort-recursive-edit'."
1774 ;; Don't do anything when `menu-frame' is not alive or visible
1776 ((not (menu-bar-menu-frame-live-and-visible-p)))
1777 ((menu-bar-non-minibuffer-window-p)
1778 (kill-buffer (current-buffer)))
1780 (abort-recursive-edit))))
1782 (defun kill-this-buffer-enabled-p ()
1783 "Return non-nil if the `kill-this-buffer' menu item should be enabled."
1784 (or (not (menu-bar-non-minibuffer-window-p))
1786 ;; Instead of looping over entire buffer list, stop once we've
1787 ;; found two "killable" buffers (Bug#8184).
1789 (dolist (buffer (buffer-list))
1790 (unless (string-match-p "^ " (buffer-name buffer))
1793 (throw 'found-2 t))))))))
1795 (put 'dired 'menu-enable '(menu-bar-non-minibuffer-window-p))
1797 ;; Permit deleting frame if it would leave a visible or iconified frame.
1798 (defun delete-frame-enabled-p ()
1799 "Return non-nil if `delete-frame' should be enabled in the menu bar."
1800 (let ((frames (frame-list))
1803 (if (frame-visible-p (car frames))
1804 (setq count (1+ count)))
1805 (setq frames (cdr frames)))
1808 (defcustom yank-menu-length 20
1809 "Maximum length to display in the yank-menu."
1813 (defun menu-bar-update-yank-menu (string old)
1814 (let ((front (car (cdr yank-menu)))
1815 (menu-string (if (<= (length string) yank-menu-length)
1818 (substring string 0 (/ yank-menu-length 2))
1820 (substring string (- (/ yank-menu-length 2)))))))
1821 ;; Don't let the menu string be all dashes
1822 ;; because that has a special meaning in a menu.
1823 (if (string-match "\\`-+\\'" menu-string)
1824 (setq menu-string (concat menu-string " ")))
1825 ;; If we're supposed to be extending an existing string, and that
1826 ;; string really is at the front of the menu, then update it in place.
1827 (if (and old (or (eq old (car front))
1828 (string= old (car front))))
1830 (setcar front string)
1831 (setcar (cdr front) menu-string))
1834 (cons string (cons menu-string 'menu-bar-select-yank))
1836 (if (> (length (cdr yank-menu)) kill-ring-max)
1837 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
1839 (put 'menu-bar-select-yank 'apropos-inhibit t)
1840 (defun menu-bar-select-yank ()
1841 "Insert the stretch of previously-killed text selected from menu.
1842 The menu shows all the killed text sequences stored in `kill-ring'."
1845 (insert last-command-event))
1850 (defcustom buffers-menu-max-size 10
1851 "Maximum number of entries which may appear on the Buffers menu.
1852 If this is 10, then only the ten most-recently-selected buffers are shown.
1853 If this is nil, then all buffers are shown.
1854 A large number or nil slows down menu responsiveness."
1855 :type '(choice integer
1856 (const :tag "All" nil))
1859 (defcustom buffers-menu-buffer-name-length 30
1860 "Maximum length of the buffer name on the Buffers menu.
1861 If this is a number, then buffer names are truncated to this length.
1862 If this is nil, then buffer names are shown in full.
1863 A large number or nil makes the menu too wide."
1864 :type '(choice integer
1865 (const :tag "Full length" nil))
1868 (defcustom buffers-menu-show-directories 'unless-uniquify
1869 "If non-nil, show directories in the Buffers menu for buffers that have them.
1870 The special value `unless-uniquify' means that directories will be shown
1871 unless `uniquify-buffer-name-style' is non-nil (in which case, buffer
1872 names should include enough of a buffer's directory to distinguish it
1873 from other buffers).
1875 Setting this variable directly does not take effect until next time the
1876 Buffers menu is regenerated."
1877 :set (lambda (symbol value)
1879 (menu-bar-update-buffers t))
1880 :initialize 'custom-initialize-default
1881 :type '(choice (const :tag "Never" nil)
1882 (const :tag "Unless uniquify is enabled" unless-uniquify)
1883 (const :tag "Always" t))
1886 (defcustom buffers-menu-show-status t
1887 "If non-nil, show modified/read-only status of buffers in the Buffers menu.
1888 Setting this variable directly does not take effect until next time the
1889 Buffers menu is regenerated."
1890 :set (lambda (symbol value)
1892 (menu-bar-update-buffers t))
1893 :initialize 'custom-initialize-default
1897 (defvar list-buffers-directory nil
1898 "String to display in buffer listings for buffers not visiting a file.")
1899 (make-variable-buffer-local 'list-buffers-directory)
1901 (defun menu-bar-select-buffer ()
1903 (switch-to-buffer last-command-event))
1905 (defun menu-bar-select-frame (frame)
1906 (make-frame-visible frame)
1908 (select-frame frame))
1910 (defun menu-bar-update-buffers-1 (elt)
1911 (let* ((buf (car elt))
1913 (and (if (eq buffers-menu-show-directories 'unless-uniquify)
1914 (or (not (boundp 'uniquify-buffer-name-style))
1915 (null uniquify-buffer-name-style))
1916 buffers-menu-show-directories)
1917 (or (buffer-file-name buf)
1918 (buffer-local-value 'list-buffers-directory buf)))))
1920 (setq file (file-name-directory file)))
1921 (when (and file (> (length file) 20))
1922 (setq file (concat "..." (substring file -17))))
1923 (cons (if buffers-menu-show-status
1924 (let ((mod (if (buffer-modified-p buf) "*" ""))
1925 (ro (if (buffer-local-value 'buffer-read-only buf) "%" "")))
1927 (format "%s %s%s -- %s" (cdr elt) mod ro file)
1928 (format "%s %s%s" (cdr elt) mod ro)))
1930 (format "%s -- %s" (cdr elt) file)
1934 ;; Used to cache the menu entries for commands in the Buffers menu
1935 (defvar menu-bar-buffers-menu-command-entries nil)
1937 (defvar menu-bar-select-buffer-function 'switch-to-buffer
1938 "Function to select the buffer chosen from the `Buffers' menu-bar menu.
1939 It must accept a buffer as its only required argument.")
1941 (defun menu-bar-update-buffers (&optional force)
1942 ;; If user discards the Buffers item, play along.
1943 (and (lookup-key (current-global-map) [menu-bar buffer])
1944 (or force (frame-or-buffer-changed-p))
1945 (let ((buffers (buffer-list))
1946 (frames (frame-list))
1948 ;; If requested, list only the N most recently selected buffers.
1949 (if (and (integerp buffers-menu-max-size)
1950 (> buffers-menu-max-size 1))
1951 (if (> (length buffers) buffers-menu-max-size)
1952 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
1954 ;; Make the menu of buffers proper.
1957 ;; Put into each element of buffer-list
1958 ;; the name for actual display,
1959 ;; perhaps truncated in the middle.
1960 (dolist (buf buffers)
1961 (let ((name (buffer-name buf)))
1962 (unless (eq ?\s (aref name 0))
1963 (push (menu-bar-update-buffers-1
1965 (if (and (integerp buffers-menu-buffer-name-length)
1966 (> (length name) buffers-menu-buffer-name-length))
1969 name 0 (/ buffers-menu-buffer-name-length 2))
1972 name (- (/ buffers-menu-buffer-name-length 2))))
1976 ;; Now make the actual list of items.
1977 (let ((buffers-vec (make-vector (length alist) nil))
1979 (dolist (pair alist)
1985 (funcall menu-bar-select-buffer-function ,(cdr pair))))))
1986 (list buffers-vec))))
1988 ;; Make a Frames menu if we have more than one frame.
1990 (let* ((frames-vec (make-vector (length frames) nil))
1993 (list "Select Frame" frames-vec)))
1995 (dolist (frame frames)
1998 (frame-parameter frame 'name)
2000 (interactive) (menu-bar-select-frame ,frame))))
2002 ;; Put it after the normal buffers
2005 `((frames-separator "--")
2006 (frames menu-item "Frames" ,frames-menu))))))
2008 ;; Add in some normal commands at the end of the menu. We use
2009 ;; the copy cached in `menu-bar-buffers-menu-command-entries'
2010 ;; if it's been set already. Note that we can't use constant
2011 ;; lists for the menu-entries, because the low-level menu-code
2013 (unless menu-bar-buffers-menu-command-entries
2014 (setq menu-bar-buffers-menu-command-entries
2015 (list '(command-separator "--")
2020 :help "Switch to the \"next\" buffer in a cyclic order")
2021 (list 'previous-buffer
2025 :help "Switch to the \"previous\" buffer in a cyclic order")
2026 (list 'select-named-buffer
2028 "Select Named Buffer..."
2030 :help "Prompt for a buffer name, and select that buffer in the current window")
2031 (list 'list-all-buffers
2035 :help "Pop up a window listing all Emacs buffers"
2038 (nconc buffers-menu menu-bar-buffers-menu-command-entries))
2040 ;; We used to "(define-key (current-global-map) [menu-bar buffer]"
2041 ;; but that did not do the right thing when the [menu-bar buffer]
2042 ;; entry above had been moved (e.g. to a parent keymap).
2043 (setcdr global-buffers-menu-map (cons "Buffers" buffers-menu)))))
2045 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
2047 (menu-bar-update-buffers)
2049 ;; this version is too slow
2050 ;;(defun format-buffers-menu-line (buffer)
2051 ;; "Returns a string to represent the given buffer in the Buffer menu.
2052 ;;nil means the buffer shouldn't be listed. You can redefine this."
2053 ;; (if (string-match "\\` " (buffer-name buffer))
2055 ;; (with-current-buffer buffer
2056 ;; (let ((size (buffer-size)))
2057 ;; (format "%s%s %-19s %6s %-15s %s"
2058 ;; (if (buffer-modified-p) "*" " ")
2059 ;; (if buffer-read-only "%" " ")
2063 ;; (or (buffer-file-name) ""))))))
2065 ;;; Set up a menu bar menu for the minibuffer.
2067 (dolist (map (list minibuffer-local-map
2068 ;; This shouldn't be necessary, but there's a funny
2069 ;; bug in keymap.c that I don't understand yet. -stef
2070 minibuffer-local-completion-map))
2071 (bindings--define-key map [menu-bar minibuf]
2072 (cons "Minibuf" (make-sparse-keymap "Minibuf"))))
2074 (let ((map minibuffer-local-completion-map))
2075 (bindings--define-key map [menu-bar minibuf ?\?]
2076 '(menu-item "List Completions" minibuffer-completion-help
2077 :help "Display all possible completions"))
2078 (bindings--define-key map [menu-bar minibuf space]
2079 '(menu-item "Complete Word" minibuffer-complete-word
2080 :help "Complete at most one word"))
2081 (bindings--define-key map [menu-bar minibuf tab]
2082 '(menu-item "Complete" minibuffer-complete
2083 :help "Complete as far as possible")))
2085 (let ((map minibuffer-local-map))
2086 (bindings--define-key map [menu-bar minibuf quit]
2087 '(menu-item "Quit" abort-recursive-edit
2088 :help "Abort input and exit minibuffer"))
2089 (bindings--define-key map [menu-bar minibuf return]
2090 '(menu-item "Enter" exit-minibuffer
2092 :help "Terminate input and exit minibuffer"))
2093 (bindings--define-key map [menu-bar minibuf isearch-forward]
2094 '(menu-item "Isearch History Forward" isearch-forward
2095 :help "Incrementally search minibuffer history forward"))
2096 (bindings--define-key map [menu-bar minibuf isearch-backward]
2097 '(menu-item "Isearch History Backward" isearch-backward
2098 :help "Incrementally search minibuffer history backward"))
2099 (bindings--define-key map [menu-bar minibuf next]
2100 '(menu-item "Next History Item" next-history-element
2101 :help "Put next minibuffer history element in the minibuffer"))
2102 (bindings--define-key map [menu-bar minibuf previous]
2103 '(menu-item "Previous History Item" previous-history-element
2104 :help "Put previous minibuffer history element in the minibuffer")))
2106 (define-minor-mode menu-bar-mode
2107 "Toggle display of a menu bar on each frame (Menu Bar mode).
2108 With a prefix argument ARG, enable Menu Bar mode if ARG is
2109 positive, and disable it otherwise. If called from Lisp, enable
2110 Menu Bar mode if ARG is omitted or nil.
2112 This command applies to all frames that exist and frames to be
2113 created in the future."
2116 ;; It's defined in C/cus-start, this stops the d-m-m macro defining it again.
2117 :variable menu-bar-mode
2119 ;; Turn the menu-bars on all frames on or off.
2120 (let ((val (if menu-bar-mode 1 0)))
2121 (dolist (frame (frame-list))
2122 (set-frame-parameter frame 'menu-bar-lines val))
2123 ;; If the user has given `default-frame-alist' a `menu-bar-lines'
2124 ;; parameter, replace it.
2125 (if (assq 'menu-bar-lines default-frame-alist)
2126 (setq default-frame-alist
2127 (cons (cons 'menu-bar-lines val)
2128 (assq-delete-all 'menu-bar-lines
2129 default-frame-alist)))))
2130 ;; Make the message appear when Emacs is idle. We can not call message
2131 ;; directly. The minor-mode message "Menu-bar mode disabled" comes
2132 ;; after this function returns, overwriting any message we do here.
2133 (when (and (called-interactively-p 'interactive) (not menu-bar-mode))
2134 (run-with-idle-timer 0 nil 'message
2135 "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear.")))
2138 ;; (This does not work right unless it comes after the above definition.)
2139 ;; This comment is taken from tool-bar.el near
2140 ;; (put 'tool-bar-mode ...)
2141 ;; We want to pretend the menu bar by standard is on, as this will make
2142 ;; customize consider disabling the menu bar a customization, and save
2143 ;; that. We could do this for real by setting :init-value above, but
2144 ;; that would overwrite disabling the menu bar from X resources.
2145 (put 'menu-bar-mode 'standard-value '(t))
2147 (defun toggle-menu-bar-mode-from-frame (&optional arg)
2148 "Toggle menu bar on or off, based on the status of the current frame.
2149 See `menu-bar-mode' for more information."
2150 (interactive (list (or current-prefix-arg 'toggle)))
2151 (if (eq arg 'toggle)
2153 (if (menu-bar-positive-p
2154 (frame-parameter (menu-bar-frame-for-menubar) 'menu-bar-lines))
2156 (menu-bar-mode arg)))
2158 (declare-function x-menu-bar-open "term/x-win" (&optional frame))
2159 (declare-function w32-menu-bar-open "term/w32-win" (&optional frame))
2161 (defun lookup-key-ignore-too-long (map key)
2162 "Call `lookup-key' and convert numeric values to nil."
2163 (let ((binding (lookup-key map key)))
2164 (if (numberp binding) ; `too long'
2168 (defun popup-menu (menu &optional position prefix from-menu-bar)
2169 "Popup the given menu and call the selected option.
2170 MENU can be a keymap, an easymenu-style menu or a list of keymaps as for
2172 The menu is shown at the place where POSITION specifies. About
2173 the form of POSITION, see `popup-menu-normalize-position'.
2174 PREFIX is the prefix argument (if any) to pass to the command.
2175 FROM-MENU-BAR, if non-nil, means we are dropping one of menu-bar's menus."
2177 ((keymapp menu) menu)
2178 ((and (listp menu) (keymapp (car menu))) menu)
2179 (t (let* ((map (easy-menu-create-menu (car menu) (cdr menu)))
2180 (filter (when (symbolp map)
2181 (plist-get (get map 'menu-prop) :filter))))
2182 (if filter (funcall filter (symbol-function map)) map)))))
2183 (frame (selected-frame))
2186 (let* ((xy (posn-x-y position))
2187 (menu-symbol (menu-bar-menu-at-x-y (car xy) (cdr xy))))
2188 (setq position (list menu-symbol (list frame '(menu-bar)
2190 (setq position (popup-menu-normalize-position position)))
2191 ;; The looping behavior was taken from lmenu's popup-menu-popup
2192 (while (and map (setq event
2193 ;; map could be a prefix key, in which case
2194 ;; we need to get its function cell
2196 (x-popup-menu position (indirect-function map))))
2197 ;; Strangely x-popup-menu returns a list.
2198 ;; mouse-major-mode-menu was using a weird:
2199 ;; (key-binding (apply 'vector (append '(menu-bar) menu-prefix events)))
2204 (numberp (car event))
2205 (numberp (cdr event)))
2206 (let ((x (car event))
2209 (setq menu-symbol (menu-bar-menu-at-x-y x y))
2210 (setq position (list menu-symbol (list frame '(menu-bar)
2213 (key-binding (vector 'menu-bar menu-symbol)))))
2214 ((and (not (keymapp map)) (listp map))
2215 ;; We were given a list of keymaps. Search them all
2216 ;; in sequence until a first binding is found.
2217 (let ((mouse-click (apply 'vector event))
2219 (while (and map (null binding))
2220 (setq binding (lookup-key-ignore-too-long (car map) mouse-click))
2221 (setq map (cdr map)))
2224 ;; We were given a single keymap.
2225 (lookup-key map (apply 'vector event)))))
2226 ;; Clear out echoing, which perhaps shows a prefix arg.
2228 ;; Maybe try again but with the submap.
2229 (setq map (if (keymapp cmd) cmd)))
2230 ;; If the user did not cancel by refusing to select,
2231 ;; and if the result is a command, run it.
2232 (when (and (null map) (commandp cmd))
2233 (setq prefix-arg prefix)
2234 ;; `setup-specified-language-environment', for instance,
2235 ;; expects this to be set from a menu keymap.
2236 (setq last-command-event (car (last event)))
2237 ;; mouse-major-mode-menu was using `command-execute' instead.
2238 (call-interactively cmd))))
2240 (defun popup-menu-normalize-position (position)
2241 "Convert the POSITION to the form which `popup-menu' expects internally.
2242 POSITION can an event, a posn- value, a value having
2243 form ((XOFFSET YOFFSET) WINDOW), or nil.
2244 If nil, the current mouse position is used."
2246 ;; nil -> mouse cursor position
2248 (let ((mp (mouse-pixel-position)))
2249 (list (list (cadr mp) (cddr mp)) (car mp))))
2250 ;; Value returned from `event-end' or `posn-at-point'.
2252 (let ((xy (posn-x-y position)))
2253 (list (list (car xy) (cdr xy))
2254 (posn-window position))))
2257 (popup-menu-normalize-position (event-end position)))
2260 (defcustom tty-menu-open-use-tmm nil
2261 "If non-nil, \\[menu-bar-open] on a TTY will invoke `tmm-menubar'.
2263 If nil, \\[menu-bar-open] will drop down the menu corresponding to the
2264 first (leftmost) menu-bar item; you can select other items by typing
2265 \\[forward-char], \\[backward-char], \\[right-char] and \\[left-char]."
2266 :type '(choice (const :tag "F10 drops down TTY menus" nil)
2267 (const :tag "F10 invokes tmm-menubar" t))
2271 (defvar tty-menu--initial-menu-x 1
2272 "X coordinate of the first menu-bar menu dropped by F10.
2274 This is meant to be used only for debugging TTY menus.")
2276 (defun menu-bar-open (&optional frame)
2277 "Start key navigation of the menu bar in FRAME.
2279 This function decides which method to use to access the menu
2280 depending on FRAME's terminal device. On X displays, it calls
2281 `x-menu-bar-open'; on Windows, `w32-menu-bar-open'; otherwise it
2282 calls either `popup-menu' or `tmm-menubar' depending on whether
2283 \`tty-menu-open-use-tmm' is nil or not.
2285 If FRAME is nil or not given, use the selected frame."
2287 (let ((type (framep (or frame (selected-frame)))))
2289 ((eq type 'x) (x-menu-bar-open frame))
2290 ((eq type 'w32) (w32-menu-bar-open frame))
2291 ((and (null tty-menu-open-use-tmm)
2292 (not (zerop (or (frame-parameter nil 'menu-bar-lines) 0))))
2293 ;; Make sure the menu bar is up to date. One situation where
2294 ;; this is important is when this function is invoked by name
2295 ;; via M-x, in which case the menu bar includes the "Minibuf"
2296 ;; menu item that should be removed when we exit the minibuffer.
2297 (force-mode-line-update)
2299 (let* ((x tty-menu--initial-menu-x)
2300 (menu (menu-bar-menu-at-x-y x 0 frame)))
2302 (lookup-key-ignore-too-long
2303 global-map (vector 'menu-bar menu))
2304 (lookup-key-ignore-too-long
2305 (current-local-map) (vector 'menu-bar menu))
2306 (cdar (minor-mode-key-binding (vector 'menu-bar menu)))
2307 (mouse-menu-bar-map))
2308 (posn-at-x-y x 0 nil t) nil t)))
2309 (t (with-selected-frame (or frame (selected-frame))
2312 (global-set-key [f10] 'menu-bar-open)
2314 (defvar tty-menu-navigation-map
2315 (let ((map (make-sparse-keymap)))
2316 ;; The next line is disabled because it breaks interpretation of
2317 ;; escape sequences, produced by TTY arrow keys, as tty-menu-*
2318 ;; commands. Instead, we explicitly bind some keys to
2320 ;;(define-key map [t] 'tty-menu-exit)
2322 ;; The tty-menu-* are just symbols interpreted by term.c, they are
2323 ;; not real commands.
2324 (dolist (bind '((keyboard-quit . tty-menu-exit)
2325 (keyboard-escape-quit . tty-menu-exit)
2326 ;; The following two will need to be revised if we ever
2327 ;; support a right-to-left menu bar.
2328 (forward-char . tty-menu-next-menu)
2329 (backward-char . tty-menu-prev-menu)
2330 (right-char . tty-menu-next-menu)
2331 (left-char . tty-menu-prev-menu)
2332 (next-line . tty-menu-next-item)
2333 (previous-line . tty-menu-prev-item)
2334 (newline . tty-menu-select)
2335 (newline-and-indent . tty-menu-select)
2336 (menu-bar-open . tty-menu-exit)))
2337 (substitute-key-definition (car bind) (cdr bind)
2338 map (current-global-map)))
2340 ;; The bindings of menu-bar items are so that clicking on the menu
2341 ;; bar when a menu is already shown pops down that menu.
2342 (define-key map [menu-bar t] 'tty-menu-exit)
2344 (define-key map [?\C-r] 'tty-menu-select)
2345 (define-key map [?\C-j] 'tty-menu-select)
2346 (define-key map [return] 'tty-menu-select)
2347 (define-key map [linefeed] 'tty-menu-select)
2348 (define-key map [mouse-1] 'tty-menu-select)
2349 (define-key map [drag-mouse-1] 'tty-menu-select)
2350 (define-key map [mouse-2] 'tty-menu-select)
2351 (define-key map [drag-mouse-2] 'tty-menu-select)
2352 (define-key map [mouse-3] 'tty-menu-select)
2353 (define-key map [drag-mouse-3] 'tty-menu-select)
2354 (define-key map [wheel-down] 'tty-menu-next-item)
2355 (define-key map [wheel-up] 'tty-menu-prev-item)
2356 (define-key map [wheel-left] 'tty-menu-prev-menu)
2357 (define-key map [wheel-right] 'tty-menu-next-menu)
2358 ;; The following 4 bindings are for those whose text-mode mouse
2360 (define-key map [S-mouse-1] 'tty-menu-next-item)
2361 (define-key map [S-drag-mouse-1] 'tty-menu-next-item)
2362 (define-key map [S-mouse-2] 'tty-menu-prev-item)
2363 (define-key map [S-drag-mouse-2] 'tty-menu-prev-item)
2364 (define-key map [S-mouse-3] 'tty-menu-prev-item)
2365 (define-key map [S-drag-mouse-3] 'tty-menu-prev-item)
2366 (define-key map [header-line mouse-1] 'tty-menu-select)
2367 (define-key map [header-line drag-mouse-1] 'tty-menu-select)
2368 ;; The down-mouse events must be bound to tty-menu-ignore, so that
2369 ;; only releasing the mouse button pops up the menu.
2370 (define-key map [mode-line down-mouse-1] 'tty-menu-ignore)
2371 (define-key map [mode-line down-mouse-2] 'tty-menu-ignore)
2372 (define-key map [mode-line down-mouse-3] 'tty-menu-ignore)
2373 (define-key map [mode-line C-down-mouse-1] 'tty-menu-ignore)
2374 (define-key map [mode-line C-down-mouse-2] 'tty-menu-ignore)
2375 (define-key map [mode-line C-down-mouse-3] 'tty-menu-ignore)
2376 (define-key map [down-mouse-1] 'tty-menu-ignore)
2377 (define-key map [C-down-mouse-1] 'tty-menu-ignore)
2378 (define-key map [C-down-mouse-2] 'tty-menu-ignore)
2379 (define-key map [C-down-mouse-3] 'tty-menu-ignore)
2380 (define-key map [mouse-movement] 'tty-menu-mouse-movement)
2382 "Keymap used while processing TTY menus.")
2386 ;;; menu-bar.el ends here