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