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