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