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