Update copyright year to 2015
[emacs.git] / lisp / menu-bar.el
blob7d7e4660fb55bac0332ff3c857d045c3e4f42a1a
1 ;;; menu-bar.el --- define a default menu bar
3 ;; Copyright (C) 1993-1995, 2000-2015 Free Software Foundation, Inc.
5 ;; Author: Richard M. Stallman
6 ;; Maintainer: emacs-devel@gnu.org
7 ;; Keywords: internal, mouse
8 ;; Package: emacs
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.
27 ;;; Commentary:
29 ;;; Code:
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
45 ;; help key.
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]
64 menu-bar-separator)
66 ;; Don't use delete-frame as event name because that is a special
67 ;; event.
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]
83 menu-bar-separator)
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]
103 menu-bar-separator)
105 (bindings--define-key menu [ps-print-region]
106 '(menu-item "PostScript Print Region (B+W)" ps-print-region
107 :enable mark-active
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
116 :enable mark-active
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
125 :enable mark-active
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]
133 menu-bar-separator)
135 (bindings--define-key menu [recover-session]
136 '(menu-item "Recover Crashed Session" recover-session
137 :enable
138 (and auto-save-list-file-prefix
139 (file-directory-p
140 (file-name-directory auto-save-list-file-prefix))
141 (directory-files
142 (file-name-directory auto-save-list-file-prefix)
144 (concat "\\`"
145 (regexp-quote
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))
154 (not (eq
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)
170 (buffer-file-name)
171 (menu-bar-non-minibuffer-window-p))
172 :help "Save current buffer to its file"))
174 (bindings--define-key menu [separator-save]
175 menu-bar-separator)
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"))
199 menu))
201 (defun menu-find-file-existing ()
202 "Edit the existing file FILENAME."
203 (interactive)
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))))
207 (if 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."
217 (interactive)
218 (cond
219 ((and (eq menu-bar-last-search-type 'string)
220 search-ring)
221 (search-forward (car search-ring)))
222 ((and (eq menu-bar-last-search-type 'regexp)
223 regexp-search-ring)
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."
230 (interactive)
231 (cond
232 ((and (eq menu-bar-last-search-type 'string)
233 search-ring)
234 (search-backward (car search-ring)))
235 ((and (eq menu-bar-last-search-type 'regexp)
236 regexp-search-ring)
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"))
292 menu))
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]
300 menu-bar-separator)
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)
314 search-ring)
315 (and (eq menu-bar-last-search-type 'regexp)
316 regexp-search-ring))
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)
322 search-ring)
323 (and (eq menu-bar-last-search-type 'regexp)
324 regexp-search-ring))
325 :help "Repeat last search forward"))
326 (bindings--define-key menu [separator-repeat-search]
327 menu-bar-separator)
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"))
345 menu))
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]
358 menu-bar-separator)
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"))
368 menu))
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 :visible (menu-bar-goto-uses-etags-p)
377 :help "Tell navigation commands which tag table file to use"))
379 (bindings--define-key menu [separator-tag-file]
380 '(menu-item "--" nil :visible (menu-bar-goto-uses-etags-p)))
382 (bindings--define-key menu [xref-pop]
383 '(menu-item "Back" xref-pop-marker-stack
384 :help "Back to the position of the last search"))
386 (bindings--define-key menu [xref-apropos]
387 '(menu-item "Find Apropos..." xref-find-apropos
388 :help "Find function/variables whose names match regexp"))
390 (bindings--define-key menu [xref-find-otherw]
391 '(menu-item "Find Definition in Other Window..."
392 xref-find-definitions-other-window
393 :help "Find function/variable definition in another window"))
394 (bindings--define-key menu [xref-find-def]
395 '(menu-item "Find Definition..." xref-find-definitions
396 :help "Find definition of function or variable"))
398 (bindings--define-key menu [separator-xref]
399 menu-bar-separator)
401 (bindings--define-key menu [end-of-buf]
402 '(menu-item "Goto End of Buffer" end-of-buffer))
403 (bindings--define-key menu [beg-of-buf]
404 '(menu-item "Goto Beginning of Buffer" beginning-of-buffer))
405 (bindings--define-key menu [go-to-pos]
406 '(menu-item "Goto Buffer Position..." goto-char
407 :help "Read a number N and go to buffer position N"))
408 (bindings--define-key menu [go-to-line]
409 '(menu-item "Goto Line..." goto-line
410 :help "Read a line number and go to that line"))
411 menu))
413 (defun menu-bar-goto-uses-etags-p ()
414 (or (not (boundp 'xref-find-function))
415 (eq xref-find-function 'etags-xref-find)))
417 (defvar yank-menu (cons (purecopy "Select Yank") nil))
418 (fset 'yank-menu (cons 'keymap yank-menu))
420 (defvar menu-bar-edit-menu
421 (let ((menu (make-sparse-keymap "Edit")))
423 (bindings--define-key menu [props]
424 `(menu-item "Text Properties" facemenu-menu))
426 ;; ns-win.el said: Add spell for platform consistency.
427 (if (featurep 'ns)
428 (bindings--define-key menu [spell]
429 `(menu-item "Spell" ispell-menu-map)))
431 (bindings--define-key menu [fill]
432 `(menu-item "Fill" fill-region
433 :enable (and mark-active (not buffer-read-only))
434 :help
435 "Fill text in region to fit between left and right margin"))
437 (bindings--define-key menu [separator-bookmark]
438 menu-bar-separator)
440 (bindings--define-key menu [bookmark]
441 `(menu-item "Bookmarks" menu-bar-bookmark-map))
443 (bindings--define-key menu [goto]
444 `(menu-item "Go To" ,menu-bar-goto-menu))
446 (bindings--define-key menu [replace]
447 `(menu-item "Replace" ,menu-bar-replace-menu))
449 (bindings--define-key menu [search]
450 `(menu-item "Search" ,menu-bar-search-menu))
452 (bindings--define-key menu [separator-search]
453 menu-bar-separator)
455 (bindings--define-key menu [mark-whole-buffer]
456 '(menu-item "Select All" mark-whole-buffer
457 :help "Mark the whole buffer for a subsequent cut/copy"))
458 (bindings--define-key menu [clear]
459 '(menu-item "Clear" delete-region
460 :enable (and mark-active
461 (not buffer-read-only))
462 :help
463 "Delete the text in region between mark and current position"))
466 (bindings--define-key menu (if (featurep 'ns) [select-paste]
467 [paste-from-menu])
468 ;; ns-win.el said: Change text to be more consistent with
469 ;; surrounding menu items `paste', etc."
470 `(menu-item ,(if (featurep 'ns) "Select and Paste" "Paste from Kill Menu")
471 yank-menu
472 :enable (and (cdr yank-menu) (not buffer-read-only))
473 :help "Choose a string from the kill ring and paste it"))
474 (bindings--define-key menu [paste]
475 '(menu-item "Paste" yank
476 :enable (and (or
477 (gui-call gui-selection-exists-p 'CLIPBOARD)
478 (if (featurep 'ns) ; like paste-from-menu
479 (cdr yank-menu)
480 kill-ring))
481 (not buffer-read-only))
482 :help "Paste (yank) text most recently cut/copied"))
483 (bindings--define-key menu [copy]
484 ;; ns-win.el said: Substitute a Copy function that works better
485 ;; under X (for GNUstep).
486 `(menu-item "Copy" ,(if (featurep 'ns)
487 'ns-copy-including-secondary
488 'kill-ring-save)
489 :enable mark-active
490 :help "Copy text in region between mark and current position"
491 :keys ,(if (featurep 'ns)
492 "\\[ns-copy-including-secondary]"
493 "\\[kill-ring-save]")))
494 (bindings--define-key menu [cut]
495 '(menu-item "Cut" kill-region
496 :enable (and mark-active (not buffer-read-only))
497 :help
498 "Cut (kill) text in region between mark and current position"))
499 ;; ns-win.el said: Separate undo from cut/paste section.
500 (if (featurep 'ns)
501 (bindings--define-key menu [separator-undo] menu-bar-separator))
503 (bindings--define-key menu [undo]
504 '(menu-item "Undo" undo
505 :enable (and (not buffer-read-only)
506 (not (eq t buffer-undo-list))
507 (if (eq last-command 'undo)
508 (listp pending-undo-list)
509 (consp buffer-undo-list)))
510 :help "Undo last operation"))
512 menu))
514 (define-obsolete-function-alias
515 'menu-bar-kill-ring-save 'kill-ring-save "24.1")
517 ;; These are alternative definitions for the cut, paste and copy
518 ;; menu items. Use them if your system expects these to use the clipboard.
520 (put 'clipboard-kill-region 'menu-enable
521 '(and mark-active (not buffer-read-only)))
522 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
523 (put 'clipboard-yank 'menu-enable
524 '(and (or (gui-call gui-selection-exists-p 'PRIMARY)
525 (gui-call gui-selection-exists-p 'CLIPBOARD))
526 (not buffer-read-only)))
528 (defun clipboard-yank ()
529 "Insert the clipboard contents, or the last stretch of killed text."
530 (interactive "*")
531 (let ((gui-select-enable-clipboard t))
532 (yank)))
534 (defun clipboard-kill-ring-save (beg end &optional region)
535 "Copy region to kill ring, and save in the GUI's clipboard."
536 (interactive "r\np")
537 (let ((gui-select-enable-clipboard t))
538 (kill-ring-save beg end region)))
540 (defun clipboard-kill-region (beg end &optional region)
541 "Kill the region, and save it in the GUI's clipboard."
542 (interactive "r\np")
543 (let ((gui-select-enable-clipboard t))
544 (kill-region beg end region)))
546 (defun menu-bar-enable-clipboard ()
547 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
548 Do the same for the keys of the same name."
549 (interactive)
550 ;; These are Sun server keysyms for the Cut, Copy and Paste keys
551 ;; (also for XFree86 on Sun keyboard):
552 (define-key global-map [f20] 'clipboard-kill-region)
553 (define-key global-map [f16] 'clipboard-kill-ring-save)
554 (define-key global-map [f18] 'clipboard-yank)
555 ;; X11R6 versions:
556 (define-key global-map [cut] 'clipboard-kill-region)
557 (define-key global-map [copy] 'clipboard-kill-ring-save)
558 (define-key global-map [paste] 'clipboard-yank))
560 ;; The "Options" menu items
562 (defvar menu-bar-custom-menu
563 (let ((menu (make-sparse-keymap "Customize")))
565 (bindings--define-key menu [customize-apropos-faces]
566 '(menu-item "Faces Matching..." customize-apropos-faces
567 :help "Browse faces matching a regexp or word list"))
568 (bindings--define-key menu [customize-apropos-options]
569 '(menu-item "Options Matching..." customize-apropos-options
570 :help "Browse options matching a regexp or word list"))
571 (bindings--define-key menu [customize-apropos]
572 '(menu-item "All Settings Matching..." customize-apropos
573 :help "Browse customizable settings matching a regexp or word list"))
574 (bindings--define-key menu [separator-1]
575 menu-bar-separator)
576 (bindings--define-key menu [customize-group]
577 '(menu-item "Specific Group..." customize-group
578 :help "Customize settings of specific group"))
579 (bindings--define-key menu [customize-face]
580 '(menu-item "Specific Face..." customize-face
581 :help "Customize attributes of specific face"))
582 (bindings--define-key menu [customize-option]
583 '(menu-item "Specific Option..." customize-option
584 :help "Customize value of specific option"))
585 (bindings--define-key menu [separator-2]
586 menu-bar-separator)
587 (bindings--define-key menu [customize-changed-options]
588 '(menu-item "New Options..." customize-changed-options
589 :help "Options added or changed in recent Emacs versions"))
590 (bindings--define-key menu [customize-saved]
591 '(menu-item "Saved Options" customize-saved
592 :help "Customize previously saved options"))
593 (bindings--define-key menu [separator-3]
594 menu-bar-separator)
595 (bindings--define-key menu [customize-browse]
596 '(menu-item "Browse Customization Groups" customize-browse
597 :help "Browse all customization groups"))
598 (bindings--define-key menu [customize]
599 '(menu-item "Top-level Customization Group" customize
600 :help "The master group called `Emacs'"))
601 (bindings--define-key menu [customize-themes]
602 '(menu-item "Custom Themes" customize-themes
603 :help "Choose a pre-defined customization theme"))
604 menu))
605 ;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
607 (defmacro menu-bar-make-mm-toggle (fname doc help &optional props)
608 "Make a menu-item for a global minor mode toggle.
609 FNAME is the minor mode's name (variable and function).
610 DOC is the text to use for the menu entry.
611 HELP is the text to use for the tooltip.
612 PROPS are additional properties."
613 `'(menu-item ,doc ,fname
614 ,@props
615 :help ,help
616 :button (:toggle . (and (default-boundp ',fname)
617 (default-value ',fname)))))
619 (defmacro menu-bar-make-toggle (name variable doc message help &rest body)
620 `(progn
621 (defun ,name (&optional interactively)
622 ,(concat "Toggle whether to " (downcase (substring help 0 1))
623 (substring help 1) ".
624 In an interactive call, record this option as a candidate for saving
625 by \"Save Options\" in Custom buffers.")
626 (interactive "p")
627 (if ,(if body `(progn . ,body)
628 `(progn
629 (custom-load-symbol ',variable)
630 (let ((set (or (get ',variable 'custom-set) 'set-default))
631 (get (or (get ',variable 'custom-get) 'default-value)))
632 (funcall set ',variable (not (funcall get ',variable))))))
633 (message ,message "enabled globally")
634 (message ,message "disabled globally"))
635 ;; The function `customize-mark-as-set' must only be called when
636 ;; a variable is set interactively, as the purpose is to mark it as
637 ;; a candidate for "Save Options", and we do not want to save options
638 ;; the user have already set explicitly in his init file.
639 (if interactively (customize-mark-as-set ',variable)))
640 '(menu-item ,doc ,name
641 :help ,help
642 :button (:toggle . (and (default-boundp ',variable)
643 (default-value ',variable))))))
645 ;; Function for setting/saving default font.
647 (defun menu-set-font ()
648 "Interactively select a font and make it the default on all existing frames."
649 (interactive)
650 (set-frame-font (if (fboundp 'x-select-font)
651 (x-select-font)
652 (mouse-select-font))
653 nil t))
655 (defun menu-bar-options-save ()
656 "Save current values of Options menu items using Custom."
657 (interactive)
658 (let ((need-save nil))
659 ;; These are set with menu-bar-make-mm-toggle, which does not
660 ;; put on a customized-value property.
661 (dolist (elt '(line-number-mode column-number-mode size-indication-mode
662 cua-mode show-paren-mode transient-mark-mode
663 blink-cursor-mode display-time-mode display-battery-mode
664 ;; These are set by other functions that don't set
665 ;; the customized state. Having them here has the
666 ;; side-effect that turning them off via X
667 ;; resources acts like having customized them, but
668 ;; that seems harmless.
669 menu-bar-mode tool-bar-mode))
670 ;; FIXME ? It's a little annoying that running this command
671 ;; always loads cua-base, paren, time, and battery, even if they
672 ;; have not been customized in any way. (Due to custom-load-symbol.)
673 (and (customize-mark-to-save elt)
674 (setq need-save t)))
675 ;; These are set with `customize-set-variable'.
676 (dolist (elt '(scroll-bar-mode
677 debug-on-quit debug-on-error
678 ;; Somehow this works, when tool-bar and menu-bar don't.
679 tooltip-mode
680 save-place uniquify-buffer-name-style fringe-mode
681 indicate-empty-lines indicate-buffer-boundaries
682 case-fold-search font-use-system-font
683 current-language-environment default-input-method
684 ;; Saving `text-mode-hook' is somewhat questionable,
685 ;; as we might get more than we bargain for, if
686 ;; other code may has added hooks as well.
687 ;; Nonetheless, not saving it would like be confuse
688 ;; more often.
689 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
690 text-mode-hook tool-bar-position))
691 (and (get elt 'customized-value)
692 (customize-mark-to-save elt)
693 (setq need-save t)))
694 (when (get 'default 'customized-face)
695 (put 'default 'saved-face (get 'default 'customized-face))
696 (put 'default 'customized-face nil)
697 (setq need-save t))
698 ;; Save if we changed anything.
699 (when need-save
700 (custom-save-all))))
703 ;;; Assemble all the top-level items of the "Options" menu
705 ;; The "Show/Hide" submenu of menu "Options"
707 (defun menu-bar-showhide-fringe-ind-customize ()
708 "Show customization buffer for `indicate-buffer-boundaries'."
709 (interactive)
710 (customize-variable 'indicate-buffer-boundaries))
712 (defun menu-bar-showhide-fringe-ind-mixed ()
713 "Display top and bottom indicators in opposite fringes, arrows in right."
714 (interactive)
715 (customize-set-variable 'indicate-buffer-boundaries
716 '((t . right) (top . left))))
718 (defun menu-bar-showhide-fringe-ind-box ()
719 "Display top and bottom indicators in opposite fringes."
720 (interactive)
721 (customize-set-variable 'indicate-buffer-boundaries
722 '((top . left) (bottom . right))))
724 (defun menu-bar-showhide-fringe-ind-right ()
725 "Display buffer boundaries and arrows in the right fringe."
726 (interactive)
727 (customize-set-variable 'indicate-buffer-boundaries 'right))
729 (defun menu-bar-showhide-fringe-ind-left ()
730 "Display buffer boundaries and arrows in the left fringe."
731 (interactive)
732 (customize-set-variable 'indicate-buffer-boundaries 'left))
734 (defun menu-bar-showhide-fringe-ind-none ()
735 "Do not display any buffer boundary indicators."
736 (interactive)
737 (customize-set-variable 'indicate-buffer-boundaries nil))
739 (defvar menu-bar-showhide-fringe-ind-menu
740 (let ((menu (make-sparse-keymap "Buffer boundaries")))
742 (bindings--define-key menu [customize]
743 '(menu-item "Other (Customize)"
744 menu-bar-showhide-fringe-ind-customize
745 :help "Additional choices available through Custom buffer"
746 :visible (display-graphic-p)
747 :button (:radio . (not (member indicate-buffer-boundaries
748 '(nil left right
749 ((top . left) (bottom . right))
750 ((t . right) (top . left))))))))
752 (bindings--define-key menu [mixed]
753 '(menu-item "Opposite, Arrows Right" menu-bar-showhide-fringe-ind-mixed
754 :help
755 "Show top/bottom indicators in opposite fringes, arrows in right"
756 :visible (display-graphic-p)
757 :button (:radio . (equal indicate-buffer-boundaries
758 '((t . right) (top . left))))))
760 (bindings--define-key menu [box]
761 '(menu-item "Opposite, No Arrows" menu-bar-showhide-fringe-ind-box
762 :help "Show top/bottom indicators in opposite fringes, no arrows"
763 :visible (display-graphic-p)
764 :button (:radio . (equal indicate-buffer-boundaries
765 '((top . left) (bottom . right))))))
767 (bindings--define-key menu [right]
768 '(menu-item "In Right Fringe" menu-bar-showhide-fringe-ind-right
769 :help "Show buffer boundaries and arrows in right fringe"
770 :visible (display-graphic-p)
771 :button (:radio . (eq indicate-buffer-boundaries 'right))))
773 (bindings--define-key menu [left]
774 '(menu-item "In Left Fringe" menu-bar-showhide-fringe-ind-left
775 :help "Show buffer boundaries and arrows in left fringe"
776 :visible (display-graphic-p)
777 :button (:radio . (eq indicate-buffer-boundaries 'left))))
779 (bindings--define-key menu [none]
780 '(menu-item "No Indicators" menu-bar-showhide-fringe-ind-none
781 :help "Hide all buffer boundary indicators and arrows"
782 :visible (display-graphic-p)
783 :button (:radio . (eq indicate-buffer-boundaries nil))))
784 menu))
786 (defun menu-bar-showhide-fringe-menu-customize ()
787 "Show customization buffer for `fringe-mode'."
788 (interactive)
789 (customize-variable 'fringe-mode))
791 (defun menu-bar-showhide-fringe-menu-customize-reset ()
792 "Reset the fringe mode: display fringes on both sides of a window."
793 (interactive)
794 (customize-set-variable 'fringe-mode nil))
796 (defun menu-bar-showhide-fringe-menu-customize-right ()
797 "Display fringes only on the right of each window."
798 (interactive)
799 (require 'fringe)
800 (customize-set-variable 'fringe-mode '(0 . nil)))
802 (defun menu-bar-showhide-fringe-menu-customize-left ()
803 "Display fringes only on the left of each window."
804 (interactive)
805 (require 'fringe)
806 (customize-set-variable 'fringe-mode '(nil . 0)))
808 (defun menu-bar-showhide-fringe-menu-customize-disable ()
809 "Do not display window fringes."
810 (interactive)
811 (require 'fringe)
812 (customize-set-variable 'fringe-mode 0))
814 (defvar menu-bar-showhide-fringe-menu
815 (let ((menu (make-sparse-keymap "Fringe")))
817 (bindings--define-key menu [showhide-fringe-ind]
818 `(menu-item "Buffer Boundaries" ,menu-bar-showhide-fringe-ind-menu
819 :visible (display-graphic-p)
820 :help "Indicate buffer boundaries in fringe"))
822 (bindings--define-key menu [indicate-empty-lines]
823 (menu-bar-make-toggle toggle-indicate-empty-lines indicate-empty-lines
824 "Empty Line Indicators"
825 "Indicating of empty lines %s"
826 "Indicate trailing empty lines in fringe, globally"))
828 (bindings--define-key menu [customize]
829 '(menu-item "Customize Fringe" menu-bar-showhide-fringe-menu-customize
830 :help "Detailed customization of fringe"
831 :visible (display-graphic-p)))
833 (bindings--define-key menu [default]
834 '(menu-item "Default" menu-bar-showhide-fringe-menu-customize-reset
835 :help "Default width fringe on both left and right side"
836 :visible (display-graphic-p)
837 :button (:radio . (eq fringe-mode nil))))
839 (bindings--define-key menu [right]
840 '(menu-item "On the Right" menu-bar-showhide-fringe-menu-customize-right
841 :help "Fringe only on the right side"
842 :visible (display-graphic-p)
843 :button (:radio . (equal fringe-mode '(0 . nil)))))
845 (bindings--define-key menu [left]
846 '(menu-item "On the Left" menu-bar-showhide-fringe-menu-customize-left
847 :help "Fringe only on the left side"
848 :visible (display-graphic-p)
849 :button (:radio . (equal fringe-mode '(nil . 0)))))
851 (bindings--define-key menu [none]
852 '(menu-item "None" menu-bar-showhide-fringe-menu-customize-disable
853 :help "Turn off fringe"
854 :visible (display-graphic-p)
855 :button (:radio . (eq fringe-mode 0))))
856 menu))
858 (defun menu-bar-right-scroll-bar ()
859 "Display scroll bars on the right of each window."
860 (interactive)
861 (customize-set-variable 'scroll-bar-mode 'right))
863 (defun menu-bar-left-scroll-bar ()
864 "Display scroll bars on the left of each window."
865 (interactive)
866 (customize-set-variable 'scroll-bar-mode 'left))
868 (defun menu-bar-no-scroll-bar ()
869 "Turn off scroll bars."
870 (interactive)
871 (customize-set-variable 'scroll-bar-mode nil))
873 (defun menu-bar-horizontal-scroll-bar ()
874 "Display horizontal scroll bars on each window."
875 (interactive)
876 (customize-set-variable 'horizontal-scroll-bar-mode t))
878 (defun menu-bar-no-horizontal-scroll-bar ()
879 "Turn off horizontal scroll bars."
880 (interactive)
881 (customize-set-variable 'horizontal-scroll-bar-mode nil))
883 (defvar menu-bar-showhide-scroll-bar-menu
884 (let ((menu (make-sparse-keymap "Scroll-bar")))
885 (bindings--define-key menu [horizontal]
886 '(menu-item "Horizontal"
887 menu-bar-horizontal-scroll-bar
888 :help "Horizontal scroll bar"
889 :visible (horizontal-scroll-bars-available-p)
890 :button (:radio . (cdr (assq 'horizontal-scroll-bars
891 (frame-parameters))))))
893 (bindings--define-key menu [none-horizontal]
894 '(menu-item "None-horizontal"
895 menu-bar-no-horizontal-scroll-bar
896 :help "Turn off horizontal scroll bars"
897 :visible (horizontal-scroll-bars-available-p)
898 :button (:radio . (not (cdr (assq 'horizontal-scroll-bars
899 (frame-parameters)))))))
901 (bindings--define-key menu [right]
902 '(menu-item "On the Right"
903 menu-bar-right-scroll-bar
904 :help "Scroll-bar on the right side"
905 :visible (display-graphic-p)
906 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
907 (frame-parameters)))
908 'right))))
910 (bindings--define-key menu [left]
911 '(menu-item "On the Left"
912 menu-bar-left-scroll-bar
913 :help "Scroll-bar on the left side"
914 :visible (display-graphic-p)
915 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
916 (frame-parameters)))
917 'left))))
919 (bindings--define-key menu [none]
920 '(menu-item "None"
921 menu-bar-no-scroll-bar
922 :help "Turn off scroll-bar"
923 :visible (display-graphic-p)
924 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
925 (frame-parameters)))
926 nil))))
927 menu))
929 (defun menu-bar-frame-for-menubar ()
930 "Return the frame suitable for updating the menu bar."
931 (or (and (framep menu-updating-frame)
932 menu-updating-frame)
933 (selected-frame)))
935 (defun menu-bar-positive-p (val)
936 "Return non-nil if VAL is a positive number."
937 (and (numberp val)
938 (> val 0)))
940 (defun menu-bar-set-tool-bar-position (position)
941 (customize-set-variable 'tool-bar-mode t)
942 (customize-set-variable 'tool-bar-position position))
943 (defun menu-bar-showhide-tool-bar-menu-customize-disable ()
944 "Do not display tool bars."
945 (interactive)
946 (customize-set-variable 'tool-bar-mode nil))
947 (defun menu-bar-showhide-tool-bar-menu-customize-enable-left ()
948 "Display tool bars on the left side."
949 (interactive)
950 (menu-bar-set-tool-bar-position 'left))
951 (defun menu-bar-showhide-tool-bar-menu-customize-enable-right ()
952 "Display tool bars on the right side."
953 (interactive)
954 (menu-bar-set-tool-bar-position 'right))
955 (defun menu-bar-showhide-tool-bar-menu-customize-enable-top ()
956 "Display tool bars on the top side."
957 (interactive)
958 (menu-bar-set-tool-bar-position 'top))
959 (defun menu-bar-showhide-tool-bar-menu-customize-enable-bottom ()
960 "Display tool bars on the bottom side."
961 (interactive)
962 (menu-bar-set-tool-bar-position 'bottom))
964 (when (featurep 'move-toolbar)
965 (defvar menu-bar-showhide-tool-bar-menu
966 (let ((menu (make-sparse-keymap "Tool-bar")))
968 (bindings--define-key menu [showhide-tool-bar-left]
969 '(menu-item "On the Left"
970 menu-bar-showhide-tool-bar-menu-customize-enable-left
971 :help "Tool-bar at the left side"
972 :visible (display-graphic-p)
973 :button
974 (:radio . (and tool-bar-mode
975 (eq (frame-parameter
976 (menu-bar-frame-for-menubar)
977 'tool-bar-position)
978 'left)))))
980 (bindings--define-key menu [showhide-tool-bar-right]
981 '(menu-item "On the Right"
982 menu-bar-showhide-tool-bar-menu-customize-enable-right
983 :help "Tool-bar at the right side"
984 :visible (display-graphic-p)
985 :button
986 (:radio . (and tool-bar-mode
987 (eq (frame-parameter
988 (menu-bar-frame-for-menubar)
989 'tool-bar-position)
990 'right)))))
992 (bindings--define-key menu [showhide-tool-bar-bottom]
993 '(menu-item "On the Bottom"
994 menu-bar-showhide-tool-bar-menu-customize-enable-bottom
995 :help "Tool-bar at the bottom"
996 :visible (display-graphic-p)
997 :button
998 (:radio . (and tool-bar-mode
999 (eq (frame-parameter
1000 (menu-bar-frame-for-menubar)
1001 'tool-bar-position)
1002 'bottom)))))
1004 (bindings--define-key menu [showhide-tool-bar-top]
1005 '(menu-item "On the Top"
1006 menu-bar-showhide-tool-bar-menu-customize-enable-top
1007 :help "Tool-bar at the top"
1008 :visible (display-graphic-p)
1009 :button
1010 (:radio . (and tool-bar-mode
1011 (eq (frame-parameter
1012 (menu-bar-frame-for-menubar)
1013 'tool-bar-position)
1014 'top)))))
1016 (bindings--define-key menu [showhide-tool-bar-none]
1017 '(menu-item "None"
1018 menu-bar-showhide-tool-bar-menu-customize-disable
1019 :help "Turn tool-bar off"
1020 :visible (display-graphic-p)
1021 :button (:radio . (eq tool-bar-mode nil))))
1022 menu)))
1024 (defvar menu-bar-showhide-menu
1025 (let ((menu (make-sparse-keymap "Show/Hide")))
1027 (bindings--define-key menu [column-number-mode]
1028 (menu-bar-make-mm-toggle column-number-mode
1029 "Column Numbers"
1030 "Show the current column number in the mode line"))
1032 (bindings--define-key menu [line-number-mode]
1033 (menu-bar-make-mm-toggle line-number-mode
1034 "Line Numbers"
1035 "Show the current line number in the mode line"))
1037 (bindings--define-key menu [size-indication-mode]
1038 (menu-bar-make-mm-toggle size-indication-mode
1039 "Size Indication"
1040 "Show the size of the buffer in the mode line"))
1042 (bindings--define-key menu [linecolumn-separator]
1043 menu-bar-separator)
1045 (bindings--define-key menu [showhide-battery]
1046 (menu-bar-make-mm-toggle display-battery-mode
1047 "Battery Status"
1048 "Display battery status information in mode line"))
1050 (bindings--define-key menu [showhide-date-time]
1051 (menu-bar-make-mm-toggle display-time-mode
1052 "Time, Load and Mail"
1053 "Display time, system load averages and \
1054 mail status in mode line"))
1056 (bindings--define-key menu [datetime-separator]
1057 menu-bar-separator)
1059 (bindings--define-key menu [showhide-speedbar]
1060 '(menu-item "Speedbar" speedbar-frame-mode
1061 :help "Display a Speedbar quick-navigation frame"
1062 :button (:toggle
1063 . (and (boundp 'speedbar-frame)
1064 (frame-live-p (symbol-value 'speedbar-frame))
1065 (frame-visible-p
1066 (symbol-value 'speedbar-frame))))))
1068 (bindings--define-key menu [showhide-fringe]
1069 `(menu-item "Fringe" ,menu-bar-showhide-fringe-menu
1070 :visible (display-graphic-p)))
1072 (bindings--define-key menu [showhide-scroll-bar]
1073 `(menu-item "Scroll-bar" ,menu-bar-showhide-scroll-bar-menu
1074 :visible (display-graphic-p)))
1076 (bindings--define-key menu [showhide-tooltip-mode]
1077 '(menu-item "Tooltips" tooltip-mode
1078 :help "Turn tooltips on/off"
1079 :visible (and (display-graphic-p) (fboundp 'x-show-tip))
1080 :button (:toggle . tooltip-mode)))
1082 (bindings--define-key menu [menu-bar-mode]
1083 '(menu-item "Menu-bar" toggle-menu-bar-mode-from-frame
1084 :help "Turn menu-bar on/off"
1085 :button
1086 (:toggle . (menu-bar-positive-p
1087 (frame-parameter (menu-bar-frame-for-menubar)
1088 'menu-bar-lines)))))
1090 (if (and (boundp 'menu-bar-showhide-tool-bar-menu)
1091 (keymapp menu-bar-showhide-tool-bar-menu))
1092 (bindings--define-key menu [showhide-tool-bar]
1093 `(menu-item "Tool-bar" ,menu-bar-showhide-tool-bar-menu
1094 :visible (display-graphic-p)))
1095 ;; else not tool bar that can move.
1096 (bindings--define-key menu [showhide-tool-bar]
1097 '(menu-item "Tool-bar" toggle-tool-bar-mode-from-frame
1098 :help "Turn tool-bar on/off"
1099 :visible (display-graphic-p)
1100 :button
1101 (:toggle . (menu-bar-positive-p
1102 (frame-parameter (menu-bar-frame-for-menubar)
1103 'tool-bar-lines))))))
1104 menu))
1106 (defvar menu-bar-line-wrapping-menu
1107 (let ((menu (make-sparse-keymap "Line Wrapping")))
1109 (bindings--define-key menu [word-wrap]
1110 `(menu-item "Word Wrap (Visual Line mode)"
1111 ,(lambda ()
1112 (interactive)
1113 (unless visual-line-mode
1114 (visual-line-mode 1))
1115 (message "Visual-Line mode enabled"))
1116 :help "Wrap long lines at word boundaries"
1117 :button (:radio
1118 . (and (null truncate-lines)
1119 (not (truncated-partial-width-window-p))
1120 word-wrap))
1121 :visible (menu-bar-menu-frame-live-and-visible-p)))
1123 (bindings--define-key menu [truncate]
1124 `(menu-item "Truncate Long Lines"
1125 ,(lambda ()
1126 (interactive)
1127 (if visual-line-mode (visual-line-mode 0))
1128 (setq word-wrap nil)
1129 (toggle-truncate-lines 1))
1130 :help "Truncate long lines at window edge"
1131 :button (:radio . (or truncate-lines
1132 (truncated-partial-width-window-p)))
1133 :visible (menu-bar-menu-frame-live-and-visible-p)
1134 :enable (not (truncated-partial-width-window-p))))
1136 (bindings--define-key menu [window-wrap]
1137 `(menu-item "Wrap at Window Edge"
1138 ,(lambda () (interactive)
1139 (if visual-line-mode (visual-line-mode 0))
1140 (setq word-wrap nil)
1141 (if truncate-lines (toggle-truncate-lines -1)))
1142 :help "Wrap long lines at window edge"
1143 :button (:radio
1144 . (and (null truncate-lines)
1145 (not (truncated-partial-width-window-p))
1146 (not word-wrap)))
1147 :visible (menu-bar-menu-frame-live-and-visible-p)
1148 :enable (not (truncated-partial-width-window-p))))
1149 menu))
1151 (defvar menu-bar-options-menu
1152 (let ((menu (make-sparse-keymap "Options")))
1153 (bindings--define-key menu [customize]
1154 `(menu-item "Customize Emacs" ,menu-bar-custom-menu))
1156 (bindings--define-key menu [package]
1157 '(menu-item "Manage Emacs Packages" package-list-packages
1158 :help "Install or uninstall additional Emacs packages"))
1160 (bindings--define-key menu [save]
1161 '(menu-item "Save Options" menu-bar-options-save
1162 :help "Save options set from the menu above"))
1164 (bindings--define-key menu [custom-separator]
1165 menu-bar-separator)
1167 (bindings--define-key menu [menu-set-font]
1168 '(menu-item "Set Default Font..." menu-set-font
1169 :visible (display-multi-font-p)
1170 :help "Select a default font"))
1172 (if (featurep 'system-font-setting)
1173 (bindings--define-key menu [menu-system-font]
1174 (menu-bar-make-toggle
1175 toggle-use-system-font font-use-system-font
1176 "Use System Font"
1177 "Use system font: %s"
1178 "Use the monospaced font defined by the system")))
1180 (bindings--define-key menu [showhide]
1181 `(menu-item "Show/Hide" ,menu-bar-showhide-menu))
1183 (bindings--define-key menu [showhide-separator]
1184 menu-bar-separator)
1186 (bindings--define-key menu [mule]
1187 ;; It is better not to use backquote here,
1188 ;; because that makes a bootstrapping problem
1189 ;; if you need to recompile all the Lisp files using interpreted code.
1190 `(menu-item "Multilingual Environment" ,mule-menu-keymap
1191 ;; Most of the MULE menu actually does make sense in
1192 ;; unibyte mode, e.g. language selection.
1193 ;; :visible '(default-value 'enable-multibyte-characters)
1195 ;;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
1196 ;;(bindings--define-key menu [preferences]
1197 ;; `(menu-item "Preferences" ,menu-bar-preferences-menu
1198 ;; :help "Toggle important global options"))
1200 (bindings--define-key menu [mule-separator]
1201 menu-bar-separator)
1203 (bindings--define-key menu [debug-on-quit]
1204 (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
1205 "Enter Debugger on Quit/C-g" "Debug on Quit %s"
1206 "Enter Lisp debugger when C-g is pressed"))
1207 (bindings--define-key menu [debug-on-error]
1208 (menu-bar-make-toggle toggle-debug-on-error debug-on-error
1209 "Enter Debugger on Error" "Debug on Error %s"
1210 "Enter Lisp debugger when an error is signaled"))
1211 (bindings--define-key menu [debugger-separator]
1212 menu-bar-separator)
1214 (bindings--define-key menu [blink-cursor-mode]
1215 (menu-bar-make-mm-toggle
1216 blink-cursor-mode
1217 "Blink Cursor"
1218 "Whether the cursor blinks (Blink Cursor mode)"))
1219 (bindings--define-key menu [cursor-separator]
1220 menu-bar-separator)
1222 (bindings--define-key menu [save-place]
1223 (menu-bar-make-toggle
1224 toggle-save-place-globally save-place
1225 "Save Place in Files between Sessions"
1226 "Saving place in files %s"
1227 "Visit files of previous session when restarting Emacs"
1228 (require 'saveplace)
1229 ;; Do it by name, to avoid a free-variable
1230 ;; warning during byte compilation.
1231 (set-default
1232 'save-place (not (symbol-value 'save-place)))))
1234 (bindings--define-key menu [uniquify]
1235 (menu-bar-make-toggle
1236 toggle-uniquify-buffer-names uniquify-buffer-name-style
1237 "Use Directory Names in Buffer Names"
1238 "Directory name in buffer names (uniquify) %s"
1239 "Uniquify buffer names by adding parent directory names"
1240 (setq uniquify-buffer-name-style
1241 (if (not uniquify-buffer-name-style)
1242 'post-forward-angle-brackets))))
1244 (bindings--define-key menu [edit-options-separator]
1245 menu-bar-separator)
1246 (bindings--define-key menu [cua-mode]
1247 (menu-bar-make-mm-toggle
1248 cua-mode
1249 "Use CUA Keys (Cut/Paste with C-x/C-c/C-v)"
1250 "Use C-z/C-x/C-c/C-v keys for undo/cut/copy/paste"
1251 (:visible (or (not (boundp 'cua-enable-cua-keys))
1252 cua-enable-cua-keys))))
1254 (bindings--define-key menu [cua-emulation-mode]
1255 (menu-bar-make-mm-toggle
1256 cua-mode
1257 "Shift movement mark region (CUA)"
1258 "Use shifted movement keys to set and extend the region"
1259 (:visible (and (boundp 'cua-enable-cua-keys)
1260 (not cua-enable-cua-keys)))))
1262 (bindings--define-key menu [case-fold-search]
1263 (menu-bar-make-toggle
1264 toggle-case-fold-search case-fold-search
1265 "Ignore Case for Search"
1266 "Case-Insensitive Search %s"
1267 "Ignore letter-case in search commands"))
1269 (bindings--define-key menu [line-wrapping]
1270 `(menu-item "Line Wrapping in This Buffer"
1271 ,menu-bar-line-wrapping-menu))
1274 (bindings--define-key menu [highlight-separator]
1275 menu-bar-separator)
1276 (bindings--define-key menu [highlight-paren-mode]
1277 (menu-bar-make-mm-toggle
1278 show-paren-mode
1279 "Highlight Matching Parentheses"
1280 "Highlight matching/mismatched parentheses at cursor (Show Paren mode)"))
1281 (bindings--define-key menu [transient-mark-mode]
1282 (menu-bar-make-mm-toggle
1283 transient-mark-mode
1284 "Highlight Active Region"
1285 "Make text in active region stand out in color (Transient Mark mode)"
1286 (:enable (not cua-mode))))
1287 menu))
1290 ;; The "Tools" menu items
1292 (defvar menu-bar-games-menu
1293 (let ((menu (make-sparse-keymap "Games")))
1295 (bindings--define-key menu [zone]
1296 '(menu-item "Zone Out" zone
1297 :help "Play tricks with Emacs display when Emacs is idle"))
1298 (bindings--define-key menu [tetris]
1299 '(menu-item "Tetris" tetris
1300 :help "Falling blocks game"))
1301 (bindings--define-key menu [solitaire]
1302 '(menu-item "Solitaire" solitaire
1303 :help "Get rid of all the stones"))
1304 (bindings--define-key menu [snake]
1305 '(menu-item "Snake" snake
1306 :help "Move snake around avoiding collisions"))
1307 (bindings--define-key menu [pong]
1308 '(menu-item "Pong" pong
1309 :help "Bounce the ball to your opponent"))
1310 (bindings--define-key menu [mult]
1311 '(menu-item "Multiplication Puzzle" mpuz
1312 :help "Exercise brain with multiplication"))
1313 (bindings--define-key menu [life]
1314 '(menu-item "Life" life
1315 :help "Watch how John Conway's cellular automaton evolves"))
1316 (bindings--define-key menu [hanoi]
1317 '(menu-item "Towers of Hanoi" hanoi
1318 :help "Watch Towers-of-Hanoi puzzle solved by Emacs"))
1319 (bindings--define-key menu [gomoku]
1320 '(menu-item "Gomoku" gomoku
1321 :help "Mark 5 contiguous squares (like tic-tac-toe)"))
1322 (bindings--define-key menu [bubbles]
1323 '(menu-item "Bubbles" bubbles
1324 :help "Remove all bubbles using the fewest moves"))
1325 (bindings--define-key menu [black-box]
1326 '(menu-item "Blackbox" blackbox
1327 :help "Find balls in a black box by shooting rays"))
1328 (bindings--define-key menu [adventure]
1329 '(menu-item "Adventure" dunnet
1330 :help "Dunnet, a text Adventure game for Emacs"))
1331 (bindings--define-key menu [5x5]
1332 '(menu-item "5x5" 5x5
1333 :help "Fill in all the squares on a 5x5 board"))
1334 menu))
1336 (defvar menu-bar-encryption-decryption-menu
1337 (let ((menu (make-sparse-keymap "Encryption/Decryption")))
1338 (bindings--define-key menu [insert-keys]
1339 '(menu-item "Insert Keys" epa-insert-keys
1340 :help "Insert public keys after the current point"))
1342 (bindings--define-key menu [export-keys]
1343 '(menu-item "Export Keys" epa-export-keys
1344 :help "Export public keys to a file"))
1346 (bindings--define-key menu [import-keys-region]
1347 '(menu-item "Import Keys from Region" epa-import-keys-region
1348 :help "Import public keys from the current region"))
1350 (bindings--define-key menu [import-keys]
1351 '(menu-item "Import Keys from File..." epa-import-keys
1352 :help "Import public keys from a file"))
1354 (bindings--define-key menu [list-keys]
1355 '(menu-item "List Keys" epa-list-keys
1356 :help "Browse your public keyring"))
1358 (bindings--define-key menu [separator-keys]
1359 menu-bar-separator)
1361 (bindings--define-key menu [sign-region]
1362 '(menu-item "Sign Region" epa-sign-region
1363 :help "Create digital signature of the current region"))
1365 (bindings--define-key menu [verify-region]
1366 '(menu-item "Verify Region" epa-verify-region
1367 :help "Verify digital signature of the current region"))
1369 (bindings--define-key menu [encrypt-region]
1370 '(menu-item "Encrypt Region" epa-encrypt-region
1371 :help "Encrypt the current region"))
1373 (bindings--define-key menu [decrypt-region]
1374 '(menu-item "Decrypt Region" epa-decrypt-region
1375 :help "Decrypt the current region"))
1377 (bindings--define-key menu [separator-file]
1378 menu-bar-separator)
1380 (bindings--define-key menu [sign-file]
1381 '(menu-item "Sign File..." epa-sign-file
1382 :help "Create digital signature of a file"))
1384 (bindings--define-key menu [verify-file]
1385 '(menu-item "Verify File..." epa-verify-file
1386 :help "Verify digital signature of a file"))
1388 (bindings--define-key menu [encrypt-file]
1389 '(menu-item "Encrypt File..." epa-encrypt-file
1390 :help "Encrypt a file"))
1392 (bindings--define-key menu [decrypt-file]
1393 '(menu-item "Decrypt File..." epa-decrypt-file
1394 :help "Decrypt a file"))
1396 menu))
1398 (defun menu-bar-read-mail ()
1399 "Read mail using `read-mail-command'."
1400 (interactive)
1401 (call-interactively read-mail-command))
1403 (defvar menu-bar-tools-menu
1404 (let ((menu (make-sparse-keymap "Tools")))
1406 (bindings--define-key menu [games]
1407 `(menu-item "Games" ,menu-bar-games-menu))
1409 (bindings--define-key menu [separator-games]
1410 menu-bar-separator)
1412 (bindings--define-key menu [encryption-decryption]
1413 `(menu-item "Encryption/Decryption"
1414 ,menu-bar-encryption-decryption-menu))
1416 (bindings--define-key menu [separator-encryption-decryption]
1417 menu-bar-separator)
1419 (bindings--define-key menu [simple-calculator]
1420 '(menu-item "Simple Calculator" calculator
1421 :help "Invoke the Emacs built-in quick calculator"))
1422 (bindings--define-key menu [calc]
1423 '(menu-item "Programmable Calculator" calc
1424 :help "Invoke the Emacs built-in full scientific calculator"))
1425 (bindings--define-key menu [calendar]
1426 '(menu-item "Calendar" calendar
1427 :help "Invoke the Emacs built-in calendar"))
1429 (bindings--define-key menu [separator-net]
1430 menu-bar-separator)
1432 (bindings--define-key menu [browse-web]
1433 '(menu-item "Browse the Web..." browse-web))
1434 (bindings--define-key menu [directory-search]
1435 '(menu-item "Directory Search" eudc-tools-menu))
1436 (bindings--define-key menu [compose-mail]
1437 '(menu-item "Compose New Mail" compose-mail
1438 :visible (and mail-user-agent (not (eq mail-user-agent 'ignore)))
1439 :help "Start writing a new mail message"))
1440 (bindings--define-key menu [rmail]
1441 '(menu-item "Read Mail" menu-bar-read-mail
1442 :visible (and read-mail-command
1443 (not (eq read-mail-command 'ignore)))
1444 :help "Read your mail"))
1446 (bindings--define-key menu [gnus]
1447 '(menu-item "Read Net News" gnus
1448 :help "Read network news groups"))
1450 (bindings--define-key menu [separator-vc]
1451 menu-bar-separator)
1453 (bindings--define-key menu [vc] nil) ;Create the place for the VC menu.
1455 (bindings--define-key menu [separator-compare]
1456 menu-bar-separator)
1458 (bindings--define-key menu [epatch]
1459 '(menu-item "Apply Patch" menu-bar-epatch-menu))
1460 (bindings--define-key menu [ediff-merge]
1461 '(menu-item "Merge" menu-bar-ediff-merge-menu))
1462 (bindings--define-key menu [compare]
1463 '(menu-item "Compare (Ediff)" menu-bar-ediff-menu))
1465 (bindings--define-key menu [separator-spell]
1466 menu-bar-separator)
1468 (bindings--define-key menu [spell]
1469 '(menu-item "Spell Checking" ispell-menu-map))
1471 (bindings--define-key menu [separator-prog]
1472 menu-bar-separator)
1474 (bindings--define-key menu [semantic]
1475 '(menu-item "Source Code Parsers (Semantic)"
1476 semantic-mode
1477 :help "Toggle automatic parsing in source code buffers (Semantic mode)"
1478 :button (:toggle . (bound-and-true-p semantic-mode))))
1480 (bindings--define-key menu [ede]
1481 '(menu-item "Project Support (EDE)"
1482 global-ede-mode
1483 :help "Toggle the Emacs Development Environment (Global EDE mode)"
1484 :button (:toggle . (bound-and-true-p global-ede-mode))))
1486 (bindings--define-key menu [gdb]
1487 '(menu-item "Debugger (GDB)..." gdb
1488 :help "Debug a program from within Emacs with GDB"))
1489 (bindings--define-key menu [shell-on-region]
1490 '(menu-item "Shell Command on Region..." shell-command-on-region
1491 :enable mark-active
1492 :help "Pass marked region to a shell command"))
1493 (bindings--define-key menu [shell]
1494 '(menu-item "Shell Command..." shell-command
1495 :help "Invoke a shell command and catch its output"))
1496 (bindings--define-key menu [compile]
1497 '(menu-item "Compile..." compile
1498 :help "Invoke compiler or Make, view compilation errors"))
1499 (bindings--define-key menu [grep]
1500 '(menu-item "Search Files (Grep)..." grep
1501 :help "Search files for strings or regexps (with Grep)"))
1502 menu))
1504 ;; The "Help" menu items
1506 (defvar menu-bar-describe-menu
1507 (let ((menu (make-sparse-keymap "Describe")))
1509 (bindings--define-key menu [mule-diag]
1510 '(menu-item "Show All of Mule Status" mule-diag
1511 :visible (default-value 'enable-multibyte-characters)
1512 :help "Display multilingual environment settings"))
1513 (bindings--define-key menu [describe-coding-system-briefly]
1514 '(menu-item "Describe Coding System (Briefly)"
1515 describe-current-coding-system-briefly
1516 :visible (default-value 'enable-multibyte-characters)))
1517 (bindings--define-key menu [describe-coding-system]
1518 '(menu-item "Describe Coding System..." describe-coding-system
1519 :visible (default-value 'enable-multibyte-characters)))
1520 (bindings--define-key menu [describe-input-method]
1521 '(menu-item "Describe Input Method..." describe-input-method
1522 :visible (default-value 'enable-multibyte-characters)
1523 :help "Keyboard layout for specific input method"))
1524 (bindings--define-key menu [describe-language-environment]
1525 `(menu-item "Describe Language Environment"
1526 ,describe-language-environment-map))
1528 (bindings--define-key menu [separator-desc-mule]
1529 menu-bar-separator)
1531 (bindings--define-key menu [list-keybindings]
1532 '(menu-item "List Key Bindings" describe-bindings
1533 :help "Display all current key bindings (keyboard shortcuts)"))
1534 (bindings--define-key menu [describe-current-display-table]
1535 '(menu-item "Describe Display Table" describe-current-display-table
1536 :help "Describe the current display table"))
1537 (bindings--define-key menu [describe-package]
1538 '(menu-item "Describe Package..." describe-package
1539 :help "Display documentation of a Lisp package"))
1540 (bindings--define-key menu [describe-face]
1541 '(menu-item "Describe Face..." describe-face
1542 :help "Display the properties of a face"))
1543 (bindings--define-key menu [describe-variable]
1544 '(menu-item "Describe Variable..." describe-variable
1545 :help "Display documentation of variable/option"))
1546 (bindings--define-key menu [describe-function]
1547 '(menu-item "Describe Function..." describe-function
1548 :help "Display documentation of function/command"))
1549 (bindings--define-key menu [describe-key-1]
1550 '(menu-item "Describe Key or Mouse Operation..." describe-key
1551 ;; Users typically don't identify keys and menu items...
1552 :help "Display documentation of command bound to a \
1553 key, a click, or a menu-item"))
1554 (bindings--define-key menu [describe-mode]
1555 '(menu-item "Describe Buffer Modes" describe-mode
1556 :help "Describe this buffer's major and minor mode"))
1557 menu))
1559 (defun menu-bar-read-lispref ()
1560 "Display the Emacs Lisp Reference manual in Info mode."
1561 (interactive)
1562 (info "elisp"))
1564 (defun menu-bar-read-lispintro ()
1565 "Display the Introduction to Emacs Lisp Programming in Info mode."
1566 (interactive)
1567 (info "eintr"))
1569 (defun search-emacs-glossary ()
1570 "Display the Glossary node of the Emacs manual in Info mode."
1571 (interactive)
1572 (info "(emacs)Glossary"))
1574 (defun emacs-index-search (topic)
1575 "Look up TOPIC in the indices of the Emacs User Manual."
1576 (interactive "sSubject to look up: ")
1577 (info "emacs")
1578 (Info-index topic))
1580 (defun elisp-index-search (topic)
1581 "Look up TOPIC in the indices of the Emacs Lisp Reference Manual."
1582 (interactive "sSubject to look up: ")
1583 (info "elisp")
1584 (Info-index topic))
1586 (defvar menu-bar-search-documentation-menu
1587 (let ((menu (make-sparse-keymap "Search Documentation")))
1589 (bindings--define-key menu [search-documentation-strings]
1590 '(menu-item "Search Documentation Strings..." apropos-documentation
1591 :help
1592 "Find functions and variables whose doc strings match a regexp"))
1593 (bindings--define-key menu [find-any-object-by-name]
1594 '(menu-item "Find Any Object by Name..." apropos
1595 :help "Find symbols of any kind whose names match a regexp"))
1596 (bindings--define-key menu [find-option-by-value]
1597 '(menu-item "Find Options by Value..." apropos-value
1598 :help "Find variables whose values match a regexp"))
1599 (bindings--define-key menu [find-options-by-name]
1600 '(menu-item "Find Options by Name..." apropos-user-option
1601 :help "Find user options whose names match a regexp"))
1602 (bindings--define-key menu [find-commands-by-name]
1603 '(menu-item "Find Commands by Name..." apropos-command
1604 :help "Find commands whose names match a regexp"))
1605 (bindings--define-key menu [sep1]
1606 menu-bar-separator)
1607 (bindings--define-key menu [lookup-command-in-manual]
1608 '(menu-item "Look Up Command in User Manual..." Info-goto-emacs-command-node
1609 :help "Display manual section that describes a command"))
1610 (bindings--define-key menu [lookup-key-in-manual]
1611 '(menu-item "Look Up Key in User Manual..." Info-goto-emacs-key-command-node
1612 :help "Display manual section that describes a key"))
1613 (bindings--define-key menu [lookup-subject-in-elisp-manual]
1614 '(menu-item "Look Up Subject in ELisp Manual..." elisp-index-search
1615 :help "Find description of a subject in Emacs Lisp manual"))
1616 (bindings--define-key menu [lookup-subject-in-emacs-manual]
1617 '(menu-item "Look Up Subject in User Manual..." emacs-index-search
1618 :help "Find description of a subject in Emacs User manual"))
1619 (bindings--define-key menu [emacs-terminology]
1620 '(menu-item "Emacs Terminology" search-emacs-glossary
1621 :help "Display the Glossary section of the Emacs manual"))
1622 menu))
1624 (defvar menu-bar-manuals-menu
1625 (let ((menu (make-sparse-keymap "More Manuals")))
1627 (bindings--define-key menu [man]
1628 '(menu-item "Read Man Page..." manual-entry
1629 :help "Man-page docs for external commands and libraries"))
1630 (bindings--define-key menu [sep2]
1631 menu-bar-separator)
1632 (bindings--define-key menu [order-emacs-manuals]
1633 '(menu-item "Ordering Manuals" view-order-manuals
1634 :help "How to order manuals from the Free Software Foundation"))
1635 (bindings--define-key menu [lookup-subject-in-all-manuals]
1636 '(menu-item "Lookup Subject in all Manuals..." info-apropos
1637 :help "Find description of a subject in all installed manuals"))
1638 (bindings--define-key menu [other-manuals]
1639 '(menu-item "All Other Manuals (Info)" Info-directory
1640 :help "Read any of the installed manuals"))
1641 (bindings--define-key menu [emacs-lisp-reference]
1642 '(menu-item "Emacs Lisp Reference" menu-bar-read-lispref
1643 :help "Read the Emacs Lisp Reference manual"))
1644 (bindings--define-key menu [emacs-lisp-intro]
1645 '(menu-item "Introduction to Emacs Lisp" menu-bar-read-lispintro
1646 :help "Read the Introduction to Emacs Lisp Programming"))
1647 menu))
1649 (defun help-with-tutorial-spec-language ()
1650 "Use the Emacs tutorial, specifying which language you want."
1651 (interactive)
1652 (help-with-tutorial t))
1654 (defvar menu-bar-help-menu
1655 (let ((menu (make-sparse-keymap "Help")))
1656 (bindings--define-key menu [about-gnu-project]
1657 '(menu-item "About GNU" describe-gnu-project
1658 :help "About the GNU System, GNU Project, and GNU/Linux"))
1659 (bindings--define-key menu [about-emacs]
1660 '(menu-item "About Emacs" about-emacs
1661 :help "Display version number, copyright info, and basic help"))
1662 (bindings--define-key menu [sep4]
1663 menu-bar-separator)
1664 (bindings--define-key menu [describe-no-warranty]
1665 '(menu-item "(Non)Warranty" describe-no-warranty
1666 :help "Explain that Emacs has NO WARRANTY"))
1667 (bindings--define-key menu [describe-copying]
1668 '(menu-item "Copying Conditions" describe-copying
1669 :help "Show the Emacs license (GPL)"))
1670 (bindings--define-key menu [getting-new-versions]
1671 '(menu-item "Getting New Versions" describe-distribution
1672 :help "How to get the latest version of Emacs"))
1673 (bindings--define-key menu [sep2]
1674 menu-bar-separator)
1675 (bindings--define-key menu [external-packages]
1676 '(menu-item "Finding Extra Packages" view-external-packages
1677 :help "How to get more Lisp packages for use in Emacs"))
1678 (bindings--define-key menu [find-emacs-packages]
1679 '(menu-item "Search Built-in Packages" finder-by-keyword
1680 :help "Find built-in packages and features by keyword"))
1681 (bindings--define-key menu [more-manuals]
1682 `(menu-item "More Manuals" ,menu-bar-manuals-menu))
1683 (bindings--define-key menu [emacs-manual]
1684 '(menu-item "Read the Emacs Manual" info-emacs-manual
1685 :help "Full documentation of Emacs features"))
1686 (bindings--define-key menu [describe]
1687 `(menu-item "Describe" ,menu-bar-describe-menu))
1688 (bindings--define-key menu [search-documentation]
1689 `(menu-item "Search Documentation" ,menu-bar-search-documentation-menu))
1690 (bindings--define-key menu [sep1]
1691 menu-bar-separator)
1692 (bindings--define-key menu [emacs-psychotherapist]
1693 '(menu-item "Emacs Psychotherapist" doctor
1694 :help "Our doctor will help you feel better"))
1695 (bindings--define-key menu [send-emacs-bug-report]
1696 '(menu-item "Send Bug Report..." report-emacs-bug
1697 :help "Send e-mail to Emacs maintainers"))
1698 (bindings--define-key menu [emacs-manual-bug]
1699 '(menu-item "How to Report a Bug" info-emacs-bug
1700 :help "Read about how to report an Emacs bug"))
1701 (bindings--define-key menu [emacs-known-problems]
1702 '(menu-item "Emacs Known Problems" view-emacs-problems
1703 :help "Read about known problems with Emacs"))
1704 (bindings--define-key menu [emacs-news]
1705 '(menu-item "Emacs News" view-emacs-news
1706 :help "New features of this version"))
1707 (bindings--define-key menu [emacs-faq]
1708 '(menu-item "Emacs FAQ" view-emacs-FAQ
1709 :help "Frequently asked (and answered) questions about Emacs"))
1711 (bindings--define-key menu [emacs-tutorial-language-specific]
1712 '(menu-item "Emacs Tutorial (choose language)..."
1713 help-with-tutorial-spec-language
1714 :help "Learn how to use Emacs (choose a language)"))
1715 (bindings--define-key menu [emacs-tutorial]
1716 '(menu-item "Emacs Tutorial" help-with-tutorial
1717 :help "Learn how to use Emacs"))
1719 ;; In OS X it's in the app menu already.
1720 ;; FIXME? There already is an "About Emacs" (sans ...) entry in the Help menu.
1721 (and (featurep 'ns)
1722 (not (eq system-type 'darwin))
1723 (bindings--define-key menu [info-panel]
1724 '(menu-item "About Emacs..." ns-do-emacs-info-panel)))
1725 menu))
1727 (bindings--define-key global-map [menu-bar tools]
1728 (cons "Tools" menu-bar-tools-menu))
1729 (bindings--define-key global-map [menu-bar buffer]
1730 (cons "Buffers" global-buffers-menu-map))
1731 (bindings--define-key global-map [menu-bar options]
1732 (cons "Options" menu-bar-options-menu))
1733 (bindings--define-key global-map [menu-bar edit]
1734 (cons "Edit" menu-bar-edit-menu))
1735 (bindings--define-key global-map [menu-bar file]
1736 (cons "File" menu-bar-file-menu))
1737 (bindings--define-key global-map [menu-bar help-menu]
1738 (cons (purecopy "Help") menu-bar-help-menu))
1740 (defun menu-bar-menu-frame-live-and-visible-p ()
1741 "Return non-nil if the menu frame is alive and visible.
1742 The menu frame is the frame for which we are updating the menu."
1743 (let ((menu-frame (or menu-updating-frame (selected-frame))))
1744 (and (frame-live-p menu-frame)
1745 (frame-visible-p menu-frame))))
1747 (defun menu-bar-non-minibuffer-window-p ()
1748 "Return non-nil if selected window of the menu frame is not a minibuf window.
1750 See the documentation of `menu-bar-menu-frame-live-and-visible-p'
1751 for the definition of the menu frame."
1752 (let ((menu-frame (or menu-updating-frame (selected-frame))))
1753 (not (window-minibuffer-p (frame-selected-window menu-frame)))))
1755 (defun kill-this-buffer () ; for the menu bar
1756 "Kill the current buffer.
1757 When called in the minibuffer, get out of the minibuffer
1758 using `abort-recursive-edit'."
1759 (interactive)
1760 (cond
1761 ;; Don't do anything when `menu-frame' is not alive or visible
1762 ;; (Bug#8184).
1763 ((not (menu-bar-menu-frame-live-and-visible-p)))
1764 ((menu-bar-non-minibuffer-window-p)
1765 (kill-buffer (current-buffer)))
1767 (abort-recursive-edit))))
1769 (defun kill-this-buffer-enabled-p ()
1770 "Return non-nil if the `kill-this-buffer' menu item should be enabled."
1771 (or (not (menu-bar-non-minibuffer-window-p))
1772 (let (found-1)
1773 ;; Instead of looping over entire buffer list, stop once we've
1774 ;; found two "killable" buffers (Bug#8184).
1775 (catch 'found-2
1776 (dolist (buffer (buffer-list))
1777 (unless (string-match-p "^ " (buffer-name buffer))
1778 (if (not found-1)
1779 (setq found-1 t)
1780 (throw 'found-2 t))))))))
1782 (put 'dired 'menu-enable '(menu-bar-non-minibuffer-window-p))
1784 ;; Permit deleting frame if it would leave a visible or iconified frame.
1785 (defun delete-frame-enabled-p ()
1786 "Return non-nil if `delete-frame' should be enabled in the menu bar."
1787 (let ((frames (frame-list))
1788 (count 0))
1789 (while frames
1790 (if (frame-visible-p (car frames))
1791 (setq count (1+ count)))
1792 (setq frames (cdr frames)))
1793 (> count 1)))
1795 (defcustom yank-menu-length 20
1796 "Maximum length to display in the yank-menu."
1797 :type 'integer
1798 :group 'menu)
1800 (defun menu-bar-update-yank-menu (string old)
1801 (let ((front (car (cdr yank-menu)))
1802 (menu-string (if (<= (length string) yank-menu-length)
1803 string
1804 (concat
1805 (substring string 0 (/ yank-menu-length 2))
1806 "..."
1807 (substring string (- (/ yank-menu-length 2)))))))
1808 ;; Don't let the menu string be all dashes
1809 ;; because that has a special meaning in a menu.
1810 (if (string-match "\\`-+\\'" menu-string)
1811 (setq menu-string (concat menu-string " ")))
1812 ;; If we're supposed to be extending an existing string, and that
1813 ;; string really is at the front of the menu, then update it in place.
1814 (if (and old (or (eq old (car front))
1815 (string= old (car front))))
1816 (progn
1817 (setcar front string)
1818 (setcar (cdr front) menu-string))
1819 (setcdr yank-menu
1820 (cons
1821 (cons string (cons menu-string 'menu-bar-select-yank))
1822 (cdr yank-menu)))))
1823 (if (> (length (cdr yank-menu)) kill-ring-max)
1824 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
1826 (put 'menu-bar-select-yank 'apropos-inhibit t)
1827 (defun menu-bar-select-yank ()
1828 "Insert the stretch of previously-killed text selected from menu.
1829 The menu shows all the killed text sequences stored in `kill-ring'."
1830 (interactive "*")
1831 (push-mark (point))
1832 (insert last-command-event))
1835 ;;; Buffers Menu
1837 (defcustom buffers-menu-max-size 10
1838 "Maximum number of entries which may appear on the Buffers menu.
1839 If this is 10, then only the ten most-recently-selected buffers are shown.
1840 If this is nil, then all buffers are shown.
1841 A large number or nil slows down menu responsiveness."
1842 :type '(choice integer
1843 (const :tag "All" nil))
1844 :group 'menu)
1846 (defcustom buffers-menu-buffer-name-length 30
1847 "Maximum length of the buffer name on the Buffers menu.
1848 If this is a number, then buffer names are truncated to this length.
1849 If this is nil, then buffer names are shown in full.
1850 A large number or nil makes the menu too wide."
1851 :type '(choice integer
1852 (const :tag "Full length" nil))
1853 :group 'menu)
1855 (defcustom buffers-menu-show-directories 'unless-uniquify
1856 "If non-nil, show directories in the Buffers menu for buffers that have them.
1857 The special value `unless-uniquify' means that directories will be shown
1858 unless `uniquify-buffer-name-style' is non-nil (in which case, buffer
1859 names should include enough of a buffer's directory to distinguish it
1860 from other buffers).
1862 Setting this variable directly does not take effect until next time the
1863 Buffers menu is regenerated."
1864 :set (lambda (symbol value)
1865 (set symbol value)
1866 (menu-bar-update-buffers t))
1867 :initialize 'custom-initialize-default
1868 :type '(choice (const :tag "Never" nil)
1869 (const :tag "Unless uniquify is enabled" unless-uniquify)
1870 (const :tag "Always" t))
1871 :group 'menu)
1873 (defcustom buffers-menu-show-status t
1874 "If non-nil, show modified/read-only status of buffers in the Buffers menu.
1875 Setting this variable directly does not take effect until next time the
1876 Buffers menu is regenerated."
1877 :set (lambda (symbol value)
1878 (set symbol value)
1879 (menu-bar-update-buffers t))
1880 :initialize 'custom-initialize-default
1881 :type 'boolean
1882 :group 'menu)
1884 (defvar list-buffers-directory nil
1885 "String to display in buffer listings for buffers not visiting a file.")
1886 (make-variable-buffer-local 'list-buffers-directory)
1888 (defun menu-bar-select-buffer ()
1889 (interactive)
1890 (switch-to-buffer last-command-event))
1892 (defun menu-bar-select-frame (frame)
1893 (make-frame-visible frame)
1894 (raise-frame frame)
1895 (select-frame frame))
1897 (defun menu-bar-update-buffers-1 (elt)
1898 (let* ((buf (car elt))
1899 (file
1900 (and (if (eq buffers-menu-show-directories 'unless-uniquify)
1901 (or (not (boundp 'uniquify-buffer-name-style))
1902 (null uniquify-buffer-name-style))
1903 buffers-menu-show-directories)
1904 (or (buffer-file-name buf)
1905 (buffer-local-value 'list-buffers-directory buf)))))
1906 (when file
1907 (setq file (file-name-directory file)))
1908 (when (and file (> (length file) 20))
1909 (setq file (concat "..." (substring file -17))))
1910 (cons (if buffers-menu-show-status
1911 (let ((mod (if (buffer-modified-p buf) "*" ""))
1912 (ro (if (buffer-local-value 'buffer-read-only buf) "%" "")))
1913 (if file
1914 (format "%s %s%s -- %s" (cdr elt) mod ro file)
1915 (format "%s %s%s" (cdr elt) mod ro)))
1916 (if file
1917 (format "%s -- %s" (cdr elt) file)
1918 (cdr elt)))
1919 buf)))
1921 ;; Used to cache the menu entries for commands in the Buffers menu
1922 (defvar menu-bar-buffers-menu-command-entries nil)
1924 (defvar menu-bar-select-buffer-function 'switch-to-buffer
1925 "Function to select the buffer chosen from the `Buffers' menu-bar menu.
1926 It must accept a buffer as its only required argument.")
1928 (defun menu-bar-buffer-vector (alist)
1929 ;; turn ((name . buffer) ...) into a menu
1930 (let ((buffers-vec (make-vector (length alist) nil))
1931 (i (length alist)))
1932 (dolist (pair alist)
1933 (setq i (1- i))
1934 (aset buffers-vec i
1935 (cons (car pair)
1936 `(lambda ()
1937 (interactive)
1938 (funcall menu-bar-select-buffer-function ,(cdr pair))))))
1939 buffers-vec))
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))
1947 buffers-menu)
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.
1955 (setq buffers-menu
1956 (let (alist)
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
1964 (cons buf
1965 (if (and (integerp buffers-menu-buffer-name-length)
1966 (> (length name) buffers-menu-buffer-name-length))
1967 (concat
1968 (substring
1969 name 0 (/ buffers-menu-buffer-name-length 2))
1970 "..."
1971 (substring
1972 name (- (/ buffers-menu-buffer-name-length 2))))
1973 name)
1975 alist))))
1976 (list (menu-bar-buffer-vector alist))))
1978 ;; Make a Frames menu if we have more than one frame.
1979 (when (cdr frames)
1980 (let* ((frames-vec (make-vector (length frames) nil))
1981 (frames-menu
1982 (cons 'keymap
1983 (list "Select Frame" frames-vec)))
1984 (i 0))
1985 (dolist (frame frames)
1986 (aset frames-vec i
1987 (cons
1988 (frame-parameter frame 'name)
1989 `(lambda ()
1990 (interactive) (menu-bar-select-frame ,frame))))
1991 (setq i (1+ i)))
1992 ;; Put it after the normal buffers
1993 (setq buffers-menu
1994 (nconc buffers-menu
1995 `((frames-separator "--")
1996 (frames menu-item "Frames" ,frames-menu))))))
1998 ;; Add in some normal commands at the end of the menu. We use
1999 ;; the copy cached in `menu-bar-buffers-menu-command-entries'
2000 ;; if it's been set already. Note that we can't use constant
2001 ;; lists for the menu-entries, because the low-level menu-code
2002 ;; modifies them.
2003 (unless menu-bar-buffers-menu-command-entries
2004 (setq menu-bar-buffers-menu-command-entries
2005 (list '(command-separator "--")
2006 (list 'next-buffer
2007 'menu-item
2008 "Next Buffer"
2009 'next-buffer
2010 :help "Switch to the \"next\" buffer in a cyclic order")
2011 (list 'previous-buffer
2012 'menu-item
2013 "Previous Buffer"
2014 'previous-buffer
2015 :help "Switch to the \"previous\" buffer in a cyclic order")
2016 (list 'select-named-buffer
2017 'menu-item
2018 "Select Named Buffer..."
2019 'switch-to-buffer
2020 :help "Prompt for a buffer name, and select that buffer in the current window")
2021 (list 'list-all-buffers
2022 'menu-item
2023 "List All Buffers"
2024 'list-buffers
2025 :help "Pop up a window listing all Emacs buffers"
2026 ))))
2027 (setq buffers-menu
2028 (nconc buffers-menu menu-bar-buffers-menu-command-entries))
2030 ;; We used to "(define-key (current-global-map) [menu-bar buffer]"
2031 ;; but that did not do the right thing when the [menu-bar buffer]
2032 ;; entry above had been moved (e.g. to a parent keymap).
2033 (setcdr global-buffers-menu-map (cons "Buffers" buffers-menu)))))
2035 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
2037 (menu-bar-update-buffers)
2039 ;; this version is too slow
2040 ;;(defun format-buffers-menu-line (buffer)
2041 ;; "Returns a string to represent the given buffer in the Buffer menu.
2042 ;;nil means the buffer shouldn't be listed. You can redefine this."
2043 ;; (if (string-match "\\` " (buffer-name buffer))
2044 ;; nil
2045 ;; (with-current-buffer buffer
2046 ;; (let ((size (buffer-size)))
2047 ;; (format "%s%s %-19s %6s %-15s %s"
2048 ;; (if (buffer-modified-p) "*" " ")
2049 ;; (if buffer-read-only "%" " ")
2050 ;; (buffer-name)
2051 ;; size
2052 ;; mode-name
2053 ;; (or (buffer-file-name) ""))))))
2055 ;;; Set up a menu bar menu for the minibuffer.
2057 (dolist (map (list minibuffer-local-map
2058 ;; This shouldn't be necessary, but there's a funny
2059 ;; bug in keymap.c that I don't understand yet. -stef
2060 minibuffer-local-completion-map))
2061 (bindings--define-key map [menu-bar minibuf]
2062 (cons "Minibuf" (make-sparse-keymap "Minibuf"))))
2064 (let ((map minibuffer-local-completion-map))
2065 (bindings--define-key map [menu-bar minibuf ?\?]
2066 '(menu-item "List Completions" minibuffer-completion-help
2067 :help "Display all possible completions"))
2068 (bindings--define-key map [menu-bar minibuf space]
2069 '(menu-item "Complete Word" minibuffer-complete-word
2070 :help "Complete at most one word"))
2071 (bindings--define-key map [menu-bar minibuf tab]
2072 '(menu-item "Complete" minibuffer-complete
2073 :help "Complete as far as possible")))
2075 (let ((map minibuffer-local-map))
2076 (bindings--define-key map [menu-bar minibuf quit]
2077 '(menu-item "Quit" abort-recursive-edit
2078 :help "Abort input and exit minibuffer"))
2079 (bindings--define-key map [menu-bar minibuf return]
2080 '(menu-item "Enter" exit-minibuffer
2081 :key-sequence "\r"
2082 :help "Terminate input and exit minibuffer"))
2083 (bindings--define-key map [menu-bar minibuf isearch-forward]
2084 '(menu-item "Isearch History Forward" isearch-forward
2085 :help "Incrementally search minibuffer history forward"))
2086 (bindings--define-key map [menu-bar minibuf isearch-backward]
2087 '(menu-item "Isearch History Backward" isearch-backward
2088 :help "Incrementally search minibuffer history backward"))
2089 (bindings--define-key map [menu-bar minibuf next]
2090 '(menu-item "Next History Item" next-history-element
2091 :help "Put next minibuffer history element in the minibuffer"))
2092 (bindings--define-key map [menu-bar minibuf previous]
2093 '(menu-item "Previous History Item" previous-history-element
2094 :help "Put previous minibuffer history element in the minibuffer")))
2096 (define-minor-mode menu-bar-mode
2097 "Toggle display of a menu bar on each frame (Menu Bar mode).
2098 With a prefix argument ARG, enable Menu Bar mode if ARG is
2099 positive, and disable it otherwise. If called from Lisp, enable
2100 Menu Bar mode if ARG is omitted or nil.
2102 This command applies to all frames that exist and frames to be
2103 created in the future."
2104 :init-value t
2105 :global t
2106 ;; It's defined in C/cus-start, this stops the d-m-m macro defining it again.
2107 :variable menu-bar-mode
2109 ;; Turn the menu-bars on all frames on or off.
2110 (let ((val (if menu-bar-mode 1 0)))
2111 (dolist (frame (frame-list))
2112 (set-frame-parameter frame 'menu-bar-lines val))
2113 ;; If the user has given `default-frame-alist' a `menu-bar-lines'
2114 ;; parameter, replace it.
2115 (if (assq 'menu-bar-lines default-frame-alist)
2116 (setq default-frame-alist
2117 (cons (cons 'menu-bar-lines val)
2118 (assq-delete-all 'menu-bar-lines
2119 default-frame-alist)))))
2120 ;; Make the message appear when Emacs is idle. We can not call message
2121 ;; directly. The minor-mode message "Menu-bar mode disabled" comes
2122 ;; after this function returns, overwriting any message we do here.
2123 (when (and (called-interactively-p 'interactive) (not menu-bar-mode))
2124 (run-with-idle-timer 0 nil 'message
2125 "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear.")))
2127 ;;;###autoload
2128 ;; (This does not work right unless it comes after the above definition.)
2129 ;; This comment is taken from tool-bar.el near
2130 ;; (put 'tool-bar-mode ...)
2131 ;; We want to pretend the menu bar by standard is on, as this will make
2132 ;; customize consider disabling the menu bar a customization, and save
2133 ;; that. We could do this for real by setting :init-value above, but
2134 ;; that would overwrite disabling the menu bar from X resources.
2135 (put 'menu-bar-mode 'standard-value '(t))
2137 (defun toggle-menu-bar-mode-from-frame (&optional arg)
2138 "Toggle menu bar on or off, based on the status of the current frame.
2139 See `menu-bar-mode' for more information."
2140 (interactive (list (or current-prefix-arg 'toggle)))
2141 (if (eq arg 'toggle)
2142 (menu-bar-mode
2143 (if (menu-bar-positive-p
2144 (frame-parameter (menu-bar-frame-for-menubar) 'menu-bar-lines))
2145 0 1))
2146 (menu-bar-mode arg)))
2148 (declare-function x-menu-bar-open "term/x-win" (&optional frame))
2149 (declare-function w32-menu-bar-open "term/w32-win" (&optional frame))
2151 (defun lookup-key-ignore-too-long (map key)
2152 "Call `lookup-key' and convert numeric values to nil."
2153 (let ((binding (lookup-key map key)))
2154 (if (numberp binding) ; `too long'
2156 binding)))
2158 (defun popup-menu (menu &optional position prefix from-menu-bar)
2159 "Popup the given menu and call the selected option.
2160 MENU can be a keymap, an easymenu-style menu or a list of keymaps as for
2161 `x-popup-menu'.
2162 The menu is shown at the place where POSITION specifies. About
2163 the form of POSITION, see `popup-menu-normalize-position'.
2164 PREFIX is the prefix argument (if any) to pass to the command.
2165 FROM-MENU-BAR, if non-nil, means we are dropping one of menu-bar's menus."
2166 (let* ((map (cond
2167 ((keymapp menu) menu)
2168 ((and (listp menu) (keymapp (car menu))) menu)
2169 (t (let* ((map (easy-menu-create-menu (car menu) (cdr menu)))
2170 (filter (when (symbolp map)
2171 (plist-get (get map 'menu-prop) :filter))))
2172 (if filter (funcall filter (symbol-function map)) map)))))
2173 (frame (selected-frame))
2174 event cmd)
2175 (if from-menu-bar
2176 (let* ((xy (posn-x-y position))
2177 (menu-symbol (menu-bar-menu-at-x-y (car xy) (cdr xy))))
2178 (setq position (list menu-symbol (list frame '(menu-bar)
2179 xy 0))))
2180 (setq position (popup-menu-normalize-position position)))
2181 ;; The looping behavior was taken from lmenu's popup-menu-popup
2182 (while (and map (setq event
2183 ;; map could be a prefix key, in which case
2184 ;; we need to get its function cell
2185 ;; definition.
2186 (x-popup-menu position (indirect-function map))))
2187 ;; Strangely x-popup-menu returns a list.
2188 ;; mouse-major-mode-menu was using a weird:
2189 ;; (key-binding (apply 'vector (append '(menu-bar) menu-prefix events)))
2190 (setq cmd
2191 (cond
2192 ((and from-menu-bar
2193 (consp event)
2194 (numberp (car event))
2195 (numberp (cdr event)))
2196 (let ((x (car event))
2197 (y (cdr event))
2198 menu-symbol)
2199 (setq menu-symbol (menu-bar-menu-at-x-y x y))
2200 (setq position (list menu-symbol (list frame '(menu-bar)
2201 event 0)))
2202 (setq map
2203 (key-binding (vector 'menu-bar menu-symbol)))))
2204 ((and (not (keymapp map)) (listp map))
2205 ;; We were given a list of keymaps. Search them all
2206 ;; in sequence until a first binding is found.
2207 (let ((mouse-click (apply 'vector event))
2208 binding)
2209 (while (and map (null binding))
2210 (setq binding (lookup-key-ignore-too-long (car map) mouse-click))
2211 (setq map (cdr map)))
2212 binding))
2214 ;; We were given a single keymap.
2215 (lookup-key map (apply 'vector event)))))
2216 ;; Clear out echoing, which perhaps shows a prefix arg.
2217 (message "")
2218 ;; Maybe try again but with the submap.
2219 (setq map (if (keymapp cmd) cmd)))
2220 ;; If the user did not cancel by refusing to select,
2221 ;; and if the result is a command, run it.
2222 (when (and (null map) (commandp cmd))
2223 (setq prefix-arg prefix)
2224 ;; `setup-specified-language-environment', for instance,
2225 ;; expects this to be set from a menu keymap.
2226 (setq last-command-event (car (last event)))
2227 ;; mouse-major-mode-menu was using `command-execute' instead.
2228 (call-interactively cmd))))
2230 (defun popup-menu-normalize-position (position)
2231 "Convert the POSITION to the form which `popup-menu' expects internally.
2232 POSITION can an event, a posn- value, a value having
2233 form ((XOFFSET YOFFSET) WINDOW), or nil.
2234 If nil, the current mouse position is used."
2235 (pcase position
2236 ;; nil -> mouse cursor position
2237 (`nil
2238 (let ((mp (mouse-pixel-position)))
2239 (list (list (cadr mp) (cddr mp)) (car mp))))
2240 ;; Value returned from `event-end' or `posn-at-point'.
2241 ((pred posnp)
2242 (let ((xy (posn-x-y position)))
2243 (list (list (car xy) (cdr xy))
2244 (posn-window position))))
2245 ;; Event.
2246 ((pred eventp)
2247 (popup-menu-normalize-position (event-end position)))
2248 (t position)))
2250 (defcustom tty-menu-open-use-tmm nil
2251 "If non-nil, \\[menu-bar-open] on a TTY will invoke `tmm-menubar'.
2253 If nil, \\[menu-bar-open] will drop down the menu corresponding to the
2254 first (leftmost) menu-bar item; you can select other items by typing
2255 \\[forward-char], \\[backward-char], \\[right-char] and \\[left-char]."
2256 :type '(choice (const :tag "F10 drops down TTY menus" nil)
2257 (const :tag "F10 invokes tmm-menubar" t))
2258 :group 'display
2259 :version "24.4")
2261 (defvar tty-menu--initial-menu-x 1
2262 "X coordinate of the first menu-bar menu dropped by F10.
2264 This is meant to be used only for debugging TTY menus.")
2266 (defun menu-bar-open (&optional frame)
2267 "Start key navigation of the menu bar in FRAME.
2269 This function decides which method to use to access the menu
2270 depending on FRAME's terminal device. On X displays, it calls
2271 `x-menu-bar-open'; on Windows, `w32-menu-bar-open'; otherwise it
2272 calls either `popup-menu' or `tmm-menubar' depending on whether
2273 \`tty-menu-open-use-tmm' is nil or not.
2275 If FRAME is nil or not given, use the selected frame."
2276 (interactive)
2277 (let ((type (framep (or frame (selected-frame)))))
2278 (cond
2279 ((eq type 'x) (x-menu-bar-open frame))
2280 ((eq type 'w32) (w32-menu-bar-open frame))
2281 ((and (null tty-menu-open-use-tmm)
2282 (not (zerop (or (frame-parameter nil 'menu-bar-lines) 0))))
2283 ;; Make sure the menu bar is up to date. One situation where
2284 ;; this is important is when this function is invoked by name
2285 ;; via M-x, in which case the menu bar includes the "Minibuf"
2286 ;; menu item that should be removed when we exit the minibuffer.
2287 (force-mode-line-update)
2288 (redisplay)
2289 (let* ((x tty-menu--initial-menu-x)
2290 (menu (menu-bar-menu-at-x-y x 0 frame)))
2291 (popup-menu (or
2292 (lookup-key-ignore-too-long
2293 global-map (vector 'menu-bar menu))
2294 (lookup-key-ignore-too-long
2295 (current-local-map) (vector 'menu-bar menu))
2296 (cdar (minor-mode-key-binding (vector 'menu-bar menu)))
2297 (mouse-menu-bar-map))
2298 (posn-at-x-y x 0 nil t) nil t)))
2299 (t (with-selected-frame (or frame (selected-frame))
2300 (tmm-menubar))))))
2302 (global-set-key [f10] 'menu-bar-open)
2304 (defun buffer-menu-open ()
2305 "Start key navigation of the buffer menu.
2306 This is the keyboard interface to \\[mouse-buffer-menu]."
2307 (interactive)
2308 (popup-menu (mouse-buffer-menu-keymap)
2309 (posn-at-x-y 0 0 nil t)))
2311 (global-set-key [C-f10] 'buffer-menu-open)
2313 (defun mouse-buffer-menu-keymap ()
2314 (let* ((menu (mouse-buffer-menu-map))
2315 (km (make-sparse-keymap (pop menu))))
2316 (dolist (item (nreverse menu))
2317 (let* ((name (pop item)))
2318 (define-key km (vector (intern name))
2319 (list name 'keymap name
2320 (menu-bar-buffer-vector item)))))
2321 km))
2323 (defvar tty-menu-navigation-map
2324 (let ((map (make-sparse-keymap)))
2325 ;; The next line is disabled because it breaks interpretation of
2326 ;; escape sequences, produced by TTY arrow keys, as tty-menu-*
2327 ;; commands. Instead, we explicitly bind some keys to
2328 ;; tty-menu-exit.
2329 ;;(define-key map [t] 'tty-menu-exit)
2331 ;; The tty-menu-* are just symbols interpreted by term.c, they are
2332 ;; not real commands.
2333 (dolist (bind '((keyboard-quit . tty-menu-exit)
2334 (keyboard-escape-quit . tty-menu-exit)
2335 ;; The following two will need to be revised if we ever
2336 ;; support a right-to-left menu bar.
2337 (forward-char . tty-menu-next-menu)
2338 (backward-char . tty-menu-prev-menu)
2339 (right-char . tty-menu-next-menu)
2340 (left-char . tty-menu-prev-menu)
2341 (next-line . tty-menu-next-item)
2342 (previous-line . tty-menu-prev-item)
2343 (newline . tty-menu-select)
2344 (newline-and-indent . tty-menu-select)
2345 (menu-bar-open . tty-menu-exit)))
2346 (substitute-key-definition (car bind) (cdr bind)
2347 map (current-global-map)))
2349 ;; The bindings of menu-bar items are so that clicking on the menu
2350 ;; bar when a menu is already shown pops down that menu.
2351 (define-key map [menu-bar t] 'tty-menu-exit)
2353 (define-key map [?\C-r] 'tty-menu-select)
2354 (define-key map [?\C-j] 'tty-menu-select)
2355 (define-key map [return] 'tty-menu-select)
2356 (define-key map [linefeed] 'tty-menu-select)
2357 (define-key map [mouse-1] 'tty-menu-select)
2358 (define-key map [drag-mouse-1] 'tty-menu-select)
2359 (define-key map [mouse-2] 'tty-menu-select)
2360 (define-key map [drag-mouse-2] 'tty-menu-select)
2361 (define-key map [mouse-3] 'tty-menu-select)
2362 (define-key map [drag-mouse-3] 'tty-menu-select)
2363 (define-key map [wheel-down] 'tty-menu-next-item)
2364 (define-key map [wheel-up] 'tty-menu-prev-item)
2365 (define-key map [wheel-left] 'tty-menu-prev-menu)
2366 (define-key map [wheel-right] 'tty-menu-next-menu)
2367 ;; The following 4 bindings are for those whose text-mode mouse
2368 ;; lack the wheel.
2369 (define-key map [S-mouse-1] 'tty-menu-next-item)
2370 (define-key map [S-drag-mouse-1] 'tty-menu-next-item)
2371 (define-key map [S-mouse-2] 'tty-menu-prev-item)
2372 (define-key map [S-drag-mouse-2] 'tty-menu-prev-item)
2373 (define-key map [S-mouse-3] 'tty-menu-prev-item)
2374 (define-key map [S-drag-mouse-3] 'tty-menu-prev-item)
2375 (define-key map [header-line mouse-1] 'tty-menu-select)
2376 (define-key map [header-line drag-mouse-1] 'tty-menu-select)
2377 ;; The down-mouse events must be bound to tty-menu-ignore, so that
2378 ;; only releasing the mouse button pops up the menu.
2379 (define-key map [mode-line down-mouse-1] 'tty-menu-ignore)
2380 (define-key map [mode-line down-mouse-2] 'tty-menu-ignore)
2381 (define-key map [mode-line down-mouse-3] 'tty-menu-ignore)
2382 (define-key map [mode-line C-down-mouse-1] 'tty-menu-ignore)
2383 (define-key map [mode-line C-down-mouse-2] 'tty-menu-ignore)
2384 (define-key map [mode-line C-down-mouse-3] 'tty-menu-ignore)
2385 (define-key map [down-mouse-1] 'tty-menu-ignore)
2386 (define-key map [C-down-mouse-1] 'tty-menu-ignore)
2387 (define-key map [C-down-mouse-2] 'tty-menu-ignore)
2388 (define-key map [C-down-mouse-3] 'tty-menu-ignore)
2389 (define-key map [mouse-movement] 'tty-menu-mouse-movement)
2390 map)
2391 "Keymap used while processing TTY menus.")
2393 (provide 'menu-bar)
2395 ;;; menu-bar.el ends here