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