1 ;;; menu-bar.el --- define a default menu bar
3 ;; Copyright (C) 1993-1995, 2000-2011 Free Software Foundation, Inc.
7 ;; Keywords: internal, mouse
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; Avishai Yacobi suggested some menu rearrangements.
31 ;; This is referenced by some code below; it is defined in uniquify.el
32 (defvar uniquify-buffer-name-style
)
34 ;; From emulation/cua-base.el; used below
35 (defvar cua-enable-cua-keys
)
38 ;; Don't clobber an existing menu-bar keymap, to preserve any menu-bar key
39 ;; definitions made in loaddefs.el.
40 (or (lookup-key global-map
[menu-bar
])
41 (define-key global-map
[menu-bar
] (make-sparse-keymap "menu-bar")))
43 (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
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 (define-key global-map
[menu-bar quit
]
53 `(menu-item ,(purecopy "Quit") save-buffers-kill-emacs
54 :help
,(purecopy "Save unsaved buffers, then exit")))
55 (define-key global-map
[menu-bar hide-app
]
56 `(menu-item ,(purecopy "Hide") ns-do-hide-emacs
57 :help
,(purecopy "Hide Emacs"))))
58 (define-key global-map
[menu-bar services
] ; set-up in ns-win
59 (cons (purecopy "Services") (make-sparse-keymap "Services"))))
61 ;; This definition is just to show what this looks like.
62 ;; It gets modified in place when menu-bar-update-buffers is called.
63 (defvar global-buffers-menu-map
(make-sparse-keymap "Buffers"))
65 ;; Only declared obsolete (and only made a proper alias) in 23.3.
66 (define-obsolete-variable-alias
67 'menu-bar-files-menu
'menu-bar-file-menu
"22.1")
68 (defvar menu-bar-file-menu
69 (let ((menu (make-sparse-keymap "File")))
71 ;; The "File" menu items
72 (define-key menu
[exit-emacs
]
73 `(menu-item ,(purecopy "Quit") save-buffers-kill-terminal
74 :help
,(purecopy "Save unsaved buffers, then exit")))
76 (define-key menu
[separator-exit
]
79 ;; Don't use delete-frame as event name because that is a special
81 (define-key menu
[delete-this-frame
]
82 `(menu-item ,(purecopy "Delete Frame") delete-frame
83 :visible
(fboundp 'delete-frame
)
84 :enable
(delete-frame-enabled-p)
85 :help
,(purecopy "Delete currently selected frame")))
86 (define-key menu
[make-frame-on-display
]
87 `(menu-item ,(purecopy "New Frame on Display...") make-frame-on-display
88 :visible
(fboundp 'make-frame-on-display
)
89 :help
,(purecopy "Open a new frame on another display")))
90 (define-key menu
[make-frame
]
91 `(menu-item ,(purecopy "New Frame") make-frame-command
92 :visible
(fboundp 'make-frame-command
)
93 :help
,(purecopy "Open a new frame")))
95 (define-key menu
[separator-frame
]
98 (define-key menu
[one-window
]
99 `(menu-item ,(purecopy "Remove Other Windows") delete-other-windows
100 :enable
(not (one-window-p t nil
))
101 :help
,(purecopy "Make selected window fill whole frame")))
103 (define-key menu
[new-window-on-right
]
104 `(menu-item ,(purecopy "New Window on Right") split-window-right
105 :enable
(and (menu-bar-menu-frame-live-and-visible-p)
106 (menu-bar-non-minibuffer-window-p))
107 :help
,(purecopy "Make new window on right of selected one")))
109 (define-key menu
[new-window-below
]
110 `(menu-item ,(purecopy "New Window Below") split-window-below
111 :enable
(and (menu-bar-menu-frame-live-and-visible-p)
112 (menu-bar-non-minibuffer-window-p))
113 :help
,(purecopy "Make new window below selected one")))
115 (define-key menu
[separator-window
]
118 (define-key menu
[ps-print-region
]
119 `(menu-item ,(purecopy "Postscript Print Region (B+W)") ps-print-region
121 :help
,(purecopy "Pretty-print marked region in black and white to PostScript printer")))
122 (define-key menu
[ps-print-buffer
]
123 `(menu-item ,(purecopy "Postscript Print Buffer (B+W)") ps-print-buffer
124 :enable
(menu-bar-menu-frame-live-and-visible-p)
125 :help
,(purecopy "Pretty-print current buffer in black and white to PostScript printer")))
126 (define-key menu
[ps-print-region-faces
]
127 `(menu-item ,(purecopy "Postscript Print Region")
128 ps-print-region-with-faces
131 "Pretty-print marked region to PostScript printer")))
132 (define-key menu
[ps-print-buffer-faces
]
133 `(menu-item ,(purecopy "Postscript Print Buffer")
134 ps-print-buffer-with-faces
135 :enable
(menu-bar-menu-frame-live-and-visible-p)
136 :help
,(purecopy "Pretty-print current buffer to PostScript printer")))
137 (define-key menu
[print-region
]
138 `(menu-item ,(purecopy "Print Region") print-region
140 :help
,(purecopy "Print region between mark and current position")))
141 (define-key menu
[print-buffer
]
142 `(menu-item ,(purecopy "Print Buffer") print-buffer
143 :enable
(menu-bar-menu-frame-live-and-visible-p)
144 :help
,(purecopy "Print current buffer with page headings")))
146 (define-key menu
[separator-print
]
149 (define-key menu
[recover-session
]
150 `(menu-item ,(purecopy "Recover Crashed Session") recover-session
152 (and auto-save-list-file-prefix
154 (file-name-directory auto-save-list-file-prefix
))
156 (file-name-directory auto-save-list-file-prefix
)
160 (file-name-nondirectory
161 auto-save-list-file-prefix
)))
163 :help
,(purecopy "Recover edits from a crashed session")))
164 (define-key menu
[revert-buffer
]
165 `(menu-item ,(purecopy "Revert Buffer") revert-buffer
166 :enable
(or revert-buffer-function
167 revert-buffer-insert-file-contents-function
168 (and buffer-file-number
169 (or (buffer-modified-p)
170 (not (verify-visited-file-modtime
171 (current-buffer))))))
172 :help
,(purecopy "Re-read current buffer from its file")))
173 (define-key menu
[write-file
]
174 `(menu-item ,(purecopy "Save As...") write-file
175 :enable
(and (menu-bar-menu-frame-live-and-visible-p)
176 (menu-bar-non-minibuffer-window-p))
177 :help
,(purecopy "Write current buffer to another file")))
178 (define-key menu
[save-buffer
]
179 `(menu-item ,(purecopy "Save") save-buffer
180 :enable
(and (buffer-modified-p)
182 (menu-bar-non-minibuffer-window-p))
183 :help
,(purecopy "Save current buffer to its file")))
185 (define-key menu
[separator-save
]
189 (define-key menu
[kill-buffer
]
190 `(menu-item ,(purecopy "Close") kill-this-buffer
191 :enable
(kill-this-buffer-enabled-p)
192 :help
,(purecopy "Discard (kill) current buffer")))
193 (define-key menu
[insert-file
]
194 `(menu-item ,(purecopy "Insert File...") insert-file
195 :enable
(menu-bar-non-minibuffer-window-p)
196 :help
,(purecopy "Insert another file into current buffer")))
197 (define-key menu
[dired]
198 `(menu-item ,(purecopy "Open Directory...") dired
199 :enable (menu-bar-non-minibuffer-window-p)
201 "Read a directory, to operate on its files")))
202 (define-key menu [open-file]
203 `(menu-item ,(purecopy "Open File...") menu-find-file-existing
204 :enable (menu-bar-non-minibuffer-window-p)
206 "Read an existing file into an Emacs buffer")))
207 (define-key menu [new-file]
208 `(menu-item ,(purecopy "Visit New File...") find-file
209 :enable (menu-bar-non-minibuffer-window-p)
211 "Specify a new file's name, to edit the file")))
215 (defun menu-find-file-existing ()
216 "Edit the existing file FILENAME."
218 (let* ((mustmatch (not (and (fboundp 'x-uses-old-gtk-dialog)
219 (x-uses-old-gtk-dialog))))
220 (filename (car (find-file-read-args "Find file: " mustmatch))))
222 (find-file-existing filename)
223 (find-file filename))))
225 ;; The "Edit->Search" submenu
226 (defvar menu-bar-last-search-type nil
227 "Type of last non-incremental search command called from the menu.")
229 (defun nonincremental-repeat-search-forward ()
230 "Search forward for the previous search string or regexp."
233 ((and (eq menu-bar-last-search-type 'string)
235 (search-forward (car search-ring)))
236 ((and (eq menu-bar-last-search-type 'regexp)
238 (re-search-forward (car regexp-search-ring)))
240 (error "No previous search"))))
242 (defun nonincremental-repeat-search-backward ()
243 "Search backward for the previous search string or regexp."
246 ((and (eq menu-bar-last-search-type 'string)
248 (search-backward (car search-ring)))
249 ((and (eq menu-bar-last-search-type 'regexp)
251 (re-search-backward (car regexp-search-ring)))
253 (error "No previous search"))))
255 (defun nonincremental-search-forward (string)
256 "Read a string and search for it nonincrementally."
257 (interactive "sSearch for string: ")
258 (setq menu-bar-last-search-type 'string)
259 (if (equal string "")
260 (search-forward (car search-ring))
261 (isearch-update-ring string nil)
262 (search-forward string)))
264 (defun nonincremental-search-backward (string)
265 "Read a string and search backward for it nonincrementally."
266 (interactive "sSearch for string: ")
267 (setq menu-bar-last-search-type 'string)
268 (if (equal string "")
269 (search-backward (car search-ring))
270 (isearch-update-ring string nil)
271 (search-backward string)))
273 (defun nonincremental-re-search-forward (string)
274 "Read a regular expression and search for it nonincrementally."
275 (interactive "sSearch for regexp: ")
276 (setq menu-bar-last-search-type 'regexp)
277 (if (equal string "")
278 (re-search-forward (car regexp-search-ring))
279 (isearch-update-ring string t)
280 (re-search-forward string)))
282 (defun nonincremental-re-search-backward (string)
283 "Read a regular expression and search backward for it nonincrementally."
284 (interactive "sSearch for regexp: ")
285 (setq menu-bar-last-search-type 'regexp)
286 (if (equal string "")
287 (re-search-backward (car regexp-search-ring))
288 (isearch-update-ring string t)
289 (re-search-backward string)))
291 ;; The Edit->Search->Incremental Search menu
292 (defvar menu-bar-i-search-menu
293 (let ((menu (make-sparse-keymap "Incremental Search")))
294 (define-key menu [isearch-backward-regexp]
295 `(menu-item ,(purecopy "Backward Regexp...") isearch-backward-regexp
297 "Search backwards for a regular expression as you type it")))
298 (define-key menu [isearch-forward-regexp]
299 `(menu-item ,(purecopy "Forward Regexp...") isearch-forward-regexp
301 "Search forward for a regular expression as you type it")))
302 (define-key menu [isearch-backward]
303 `(menu-item ,(purecopy "Backward String...") isearch-backward
304 :help ,(purecopy "Search backwards for a string as you type it")))
305 (define-key menu [isearch-forward]
306 `(menu-item ,(purecopy "Forward String...") isearch-forward
307 :help ,(purecopy "Search forward for a string as you type it")))
310 (defvar menu-bar-search-menu
311 (let ((menu (make-sparse-keymap "Search")))
313 (define-key menu [i-search]
314 `(menu-item ,(purecopy "Incremental Search") ,menu-bar-i-search-menu))
315 (define-key menu [separator-tag-isearch]
318 (define-key menu [tags-continue]
319 `(menu-item ,(purecopy "Continue Tags Search") tags-loop-continue
320 :help ,(purecopy "Continue last tags search operation")))
321 (define-key menu [tags-srch]
322 `(menu-item ,(purecopy "Search Tagged Files...") tags-search
323 :help ,(purecopy "Search for a regexp in all tagged files")))
324 (define-key menu [separator-tag-search] menu-bar-separator)
326 (define-key menu [repeat-search-back]
327 `(menu-item ,(purecopy "Repeat Backwards")
328 nonincremental-repeat-search-backward
329 :enable (or (and (eq menu-bar-last-search-type 'string)
331 (and (eq menu-bar-last-search-type 'regexp)
333 :help ,(purecopy "Repeat last search backwards")))
334 (define-key menu [repeat-search-fwd]
335 `(menu-item ,(purecopy "Repeat Forward")
336 nonincremental-repeat-search-forward
337 :enable (or (and (eq menu-bar-last-search-type 'string)
339 (and (eq menu-bar-last-search-type 'regexp)
341 :help ,(purecopy "Repeat last search forward")))
342 (define-key menu [separator-repeat-search]
345 (define-key menu [re-search-backward]
346 `(menu-item ,(purecopy "Regexp Backwards...")
347 nonincremental-re-search-backward
349 "Search backwards for a regular expression")))
350 (define-key menu [re-search-forward]
351 `(menu-item ,(purecopy "Regexp Forward...")
352 nonincremental-re-search-forward
353 :help ,(purecopy "Search forward for a regular expression")))
355 (define-key menu [search-backward]
356 `(menu-item ,(purecopy "String Backwards...")
357 nonincremental-search-backward
358 :help ,(purecopy "Search backwards for a string")))
359 (define-key menu [search-forward]
360 `(menu-item ,(purecopy "String Forward...") nonincremental-search-forward
361 :help ,(purecopy "Search forward for a string")))
364 ;; The Edit->Replace submenu
366 (defvar menu-bar-replace-menu
367 (let ((menu (make-sparse-keymap "Replace")))
368 (define-key menu [tags-repl-continue]
369 `(menu-item ,(purecopy "Continue Replace") tags-loop-continue
370 :help ,(purecopy "Continue last tags replace operation")))
371 (define-key menu [tags-repl]
372 `(menu-item ,(purecopy "Replace in Tagged Files...") tags-query-replace
374 "Interactively replace a regexp in all tagged files")))
375 (define-key menu [separator-replace-tags]
378 (define-key menu [query-replace-regexp]
379 `(menu-item ,(purecopy "Replace Regexp...") query-replace-regexp
380 :enable (not buffer-read-only)
381 :help ,(purecopy "Replace regular expression interactively, ask about each occurrence")))
382 (define-key menu [query-replace]
383 `(menu-item ,(purecopy "Replace String...") query-replace
384 :enable (not buffer-read-only)
386 "Replace string interactively, ask about each occurrence")))
389 ;;; Assemble the top-level Edit menu items.
390 (defvar menu-bar-goto-menu
391 (let ((menu (make-sparse-keymap "Go To")))
393 (define-key menu [set-tags-name]
394 `(menu-item ,(purecopy "Set Tags File Name...") visit-tags-table
395 :help ,(purecopy "Tell Tags commands which tag table file to use")))
397 (define-key menu [separator-tag-file]
400 (define-key menu [apropos-tags]
401 `(menu-item ,(purecopy "Tags Apropos...") tags-apropos
402 :help ,(purecopy "Find function/variables whose names match regexp")))
403 (define-key menu [next-tag-otherw]
404 `(menu-item ,(purecopy "Next Tag in Other Window")
405 menu-bar-next-tag-other-window
406 :enable (and (boundp 'tags-location-ring)
407 (not (ring-empty-p tags-location-ring)))
408 :help ,(purecopy "Find next function/variable matching last tag name in another window")))
410 (define-key menu [next-tag]
411 `(menu-item ,(purecopy "Find Next Tag")
413 :enable (and (boundp 'tags-location-ring)
414 (not (ring-empty-p tags-location-ring)))
415 :help ,(purecopy "Find next function/variable matching last tag name")))
416 (define-key menu [find-tag-otherw]
417 `(menu-item ,(purecopy "Find Tag in Other Window...") find-tag-other-window
418 :help ,(purecopy "Find function/variable definition in another window")))
419 (define-key menu [find-tag]
420 `(menu-item ,(purecopy "Find Tag...") find-tag
421 :help ,(purecopy "Find definition of function or variable")))
423 (define-key menu [separator-tags]
426 (define-key menu [end-of-buf]
427 `(menu-item ,(purecopy "Goto End of Buffer") end-of-buffer))
428 (define-key menu [beg-of-buf]
429 `(menu-item ,(purecopy "Goto Beginning of Buffer") beginning-of-buffer))
430 (define-key menu [go-to-pos]
431 `(menu-item ,(purecopy "Goto Buffer Position...") goto-char
432 :help ,(purecopy "Read a number N and go to buffer position N")))
433 (define-key menu [go-to-line]
434 `(menu-item ,(purecopy "Goto Line...") goto-line
435 :help ,(purecopy "Read a line number and go to that line")))
439 (defvar yank-menu (cons (purecopy "Select Yank") nil))
440 (fset 'yank-menu (cons 'keymap yank-menu))
442 (defvar menu-bar-edit-menu
443 (let ((menu (make-sparse-keymap "Edit")))
445 (define-key menu [props]
446 `(menu-item ,(purecopy "Text Properties") facemenu-menu))
448 ;; ns-win.el said: Add spell for platorm consistency.
450 (define-key menu [spell]
451 `(menu-item ,(purecopy "Spell") ispell-menu-map)))
453 (define-key menu [fill]
454 `(menu-item ,(purecopy "Fill") fill-region
455 :enable (and mark-active (not buffer-read-only))
457 ,(purecopy "Fill text in region to fit between left and right margin")))
459 (define-key menu [separator-bookmark]
462 (define-key menu [bookmark]
463 `(menu-item ,(purecopy "Bookmarks") menu-bar-bookmark-map))
465 (define-key menu [goto]
466 `(menu-item ,(purecopy "Go To") ,menu-bar-goto-menu))
468 (define-key menu [replace]
469 `(menu-item ,(purecopy "Replace") ,menu-bar-replace-menu))
471 (define-key menu [search]
472 `(menu-item ,(purecopy "Search") ,menu-bar-search-menu))
474 (define-key menu [separator-search]
477 (define-key menu [mark-whole-buffer]
478 `(menu-item ,(purecopy "Select All") mark-whole-buffer
479 :help ,(purecopy "Mark the whole buffer for a subsequent cut/copy")))
480 (define-key menu [clear]
481 `(menu-item ,(purecopy "Clear") delete-region
482 :enable (and mark-active
483 (not buffer-read-only))
485 ,(purecopy "Delete the text in region between mark and current position")))
488 (define-key menu (if (featurep 'ns) [select-paste]
490 ;; ns-win.el said: Change text to be more consistent with
491 ;; surrounding menu items `paste', etc."
492 `(menu-item ,(purecopy (if (featurep 'ns) "Select and Paste"
493 "Paste from Kill Menu")) yank-menu
494 :enable (and (cdr yank-menu) (not buffer-read-only))
495 :help ,(purecopy "Choose a string from the kill ring and paste it")))
496 (define-key menu [paste]
497 `(menu-item ,(purecopy "Paste") yank
499 ;; Emacs compiled --without-x (or --with-ns)
500 ;; doesn't have x-selection-exists-p.
501 (and (fboundp 'x-selection-exists-p)
502 (x-selection-exists-p 'CLIPBOARD))
503 (if (featurep 'ns) ; like paste-from-menu
506 (not buffer-read-only))
507 :help ,(purecopy "Paste (yank) text most recently cut/copied")))
508 (define-key menu [copy]
509 ;; ns-win.el said: Substitute a Copy function that works better
510 ;; under X (for GNUstep).
511 `(menu-item ,(purecopy "Copy") ,(if (featurep 'ns)
512 'ns-copy-including-secondary
515 :help ,(purecopy "Copy text in region between mark and current position")
516 :keys ,(purecopy (if (featurep 'ns)
517 "\\[ns-copy-including-secondary]"
518 "\\[kill-ring-save]"))))
519 (define-key menu [cut]
520 `(menu-item ,(purecopy "Cut") kill-region
521 :enable (and mark-active (not buffer-read-only))
523 ,(purecopy "Cut (kill) text in region between mark and current position")))
524 ;; ns-win.el said: Separate undo from cut/paste section.
526 (define-key menu [separator-undo] menu-bar-separator))
528 (define-key menu [undo]
529 `(menu-item ,(purecopy "Undo") undo
530 :enable (and (not buffer-read-only)
531 (not (eq t buffer-undo-list))
532 (if (eq last-command 'undo)
533 (listp pending-undo-list)
534 (consp buffer-undo-list)))
535 :help ,(purecopy "Undo last operation")))
539 (defun menu-bar-next-tag-other-window ()
540 "Find the next definition of the tag already specified."
542 (find-tag-other-window nil t))
544 (defun menu-bar-next-tag ()
545 "Find the next definition of the tag already specified."
549 (define-obsolete-function-alias
550 'menu-bar-kill-ring-save 'kill-ring-save "24.1")
552 ;; These are alternative definitions for the cut, paste and copy
553 ;; menu items. Use them if your system expects these to use the clipboard.
555 (put 'clipboard-kill-region 'menu-enable
556 '(and mark-active (not buffer-read-only)))
557 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
558 (put 'clipboard-yank 'menu-enable
559 '(and (or (not (fboundp 'x-selection-exists-p))
560 (x-selection-exists-p)
561 (x-selection-exists-p 'CLIPBOARD))
562 (not buffer-read-only)))
564 (defun clipboard-yank ()
565 "Insert the clipboard contents, or the last stretch of killed text."
567 (let ((x-select-enable-clipboard t))
570 (defun clipboard-kill-ring-save (beg end)
571 "Copy region to kill ring, and save in the X clipboard."
573 (let ((x-select-enable-clipboard t))
574 (kill-ring-save beg end)))
576 (defun clipboard-kill-region (beg end)
577 "Kill the region, and save it in the X clipboard."
579 (let ((x-select-enable-clipboard t))
580 (kill-region beg end)))
582 (defun menu-bar-enable-clipboard ()
583 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
584 Do the same for the keys of the same name."
586 ;; These are Sun server keysyms for the Cut, Copy and Paste keys
587 ;; (also for XFree86 on Sun keyboard):
588 (define-key global-map [f20] 'clipboard-kill-region)
589 (define-key global-map [f16] 'clipboard-kill-ring-save)
590 (define-key global-map [f18] 'clipboard-yank)
592 (define-key global-map [cut] 'clipboard-kill-region)
593 (define-key global-map [copy] 'clipboard-kill-ring-save)
594 (define-key global-map [paste] 'clipboard-yank))
596 ;; The "Options" menu items
598 (defvar menu-bar-custom-menu
599 (let ((menu (make-sparse-keymap "Customize")))
601 (define-key menu [customize-apropos-faces]
602 `(menu-item ,(purecopy "Faces Matching...") customize-apropos-faces
603 :help ,(purecopy "Browse faces matching a regexp or word list")))
604 (define-key menu [customize-apropos-options]
605 `(menu-item ,(purecopy "Options Matching...") customize-apropos-options
606 :help ,(purecopy "Browse options matching a regexp or word list")))
607 (define-key menu [customize-apropos]
608 `(menu-item ,(purecopy "All Settings Matching...") customize-apropos
609 :help ,(purecopy "Browse customizable settings matching a regexp or word list")))
610 (define-key menu [separator-1]
612 (define-key menu [customize-group]
613 `(menu-item ,(purecopy "Specific Group...") customize-group
614 :help ,(purecopy "Customize settings of specific group")))
615 (define-key menu [customize-face]
616 `(menu-item ,(purecopy "Specific Face...") customize-face
617 :help ,(purecopy "Customize attributes of specific face")))
618 (define-key menu [customize-option]
619 `(menu-item ,(purecopy "Specific Option...") customize-option
620 :help ,(purecopy "Customize value of specific option")))
621 (define-key menu [separator-2]
623 (define-key menu [customize-changed-options]
624 `(menu-item ,(purecopy "New Options...") customize-changed-options
625 :help ,(purecopy "Options added or changed in recent Emacs versions")))
626 (define-key menu [customize-saved]
627 `(menu-item ,(purecopy "Saved Options") customize-saved
628 :help ,(purecopy "Customize previously saved options")))
629 (define-key menu [separator-3]
631 (define-key menu [customize-browse]
632 `(menu-item ,(purecopy "Browse Customization Groups") customize-browse
633 :help ,(purecopy "Browse all customization groups")))
634 (define-key menu [customize]
635 `(menu-item ,(purecopy "Top-level Customization Group") customize
636 :help ,(purecopy "The master group called `Emacs'")))
637 (define-key menu [customize-themes]
638 `(menu-item ,(purecopy "Custom Themes") customize-themes
639 :help ,(purecopy "Choose a pre-defined customization theme")))
641 ;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
643 (defmacro menu-bar-make-mm-toggle (fname doc help &optional props)
644 "Make a menu-item for a global minor mode toggle.
645 FNAME is the minor mode's name (variable and function).
646 DOC is the text to use for the menu entry.
647 HELP is the text to use for the tooltip.
648 PROPS are additional properties."
649 `(list 'menu-item (purecopy ,doc) ',fname
650 ,@(mapcar (lambda (p) (list 'quote p)) props)
651 :help (purecopy ,help)
652 :button '(:toggle . (and (default-boundp ',fname)
653 (default-value ',fname)))))
655 (defmacro menu-bar-make-toggle (name variable doc message help &rest body)
657 (defun ,name (&optional interactively)
658 ,(concat "Toggle whether to " (downcase (substring help 0 1))
659 (substring help 1) ".
660 In an interactive call, record this option as a candidate for saving
661 by \"Save Options\" in Custom buffers.")
663 (if ,(if body `(progn . ,body)
665 (custom-load-symbol ',variable)
666 (let ((set (or (get ',variable 'custom-set) 'set-default))
667 (get (or (get ',variable 'custom-get) 'default-value)))
668 (funcall set ',variable (not (funcall get ',variable))))))
669 (message ,message "enabled globally")
670 (message ,message "disabled globally"))
671 ;; The function `customize-mark-as-set' must only be called when
672 ;; a variable is set interactively, as the purpose is to mark it as
673 ;; a candidate for "Save Options", and we do not want to save options
674 ;; the user have already set explicitly in his init file.
675 (if interactively (customize-mark-as-set ',variable)))
676 (list 'menu-item (purecopy ,doc) ',name
677 :help (purecopy ,help)
678 :button '(:toggle . (and (default-boundp ',variable)
679 (default-value ',variable))))))
681 ;; Function for setting/saving default font.
683 (defun menu-set-font ()
684 "Interactively select a font and make it the default."
686 (let ((font (if (fboundp 'x-select-font)
688 (mouse-select-font)))
691 ;; Be careful here: when set-face-attribute is called for the
692 ;; :font attribute, Emacs tries to guess the best matching font
693 ;; by examining the other face attributes (Bug#2476).
694 (set-face-attribute 'default (selected-frame)
699 (let ((font-object (face-attribute 'default :font)))
700 (dolist (f (frame-list))
701 (and (not (eq f (selected-frame)))
702 (display-graphic-p f)
703 (set-face-attribute 'default f :font font-object)))
704 (set-face-attribute 'default t :font font-object))
705 (setq spec (list (list t (face-attr-construct 'default))))
706 (put 'default 'customized-face spec)
707 (custom-push-theme 'theme-face 'default 'user 'set spec)
708 (put 'default 'face-modified nil))))
710 (defun menu-bar-options-save ()
711 "Save current values of Options menu items using Custom."
713 (let ((need-save nil))
714 ;; These are set with menu-bar-make-mm-toggle, which does not
715 ;; put on a customized-value property.
716 (dolist (elt '(line-number-mode column-number-mode size-indication-mode
717 cua-mode show-paren-mode transient-mark-mode
718 blink-cursor-mode display-time-mode display-battery-mode
719 ;; These are set by other functions that don't set
720 ;; the customized state. Having them here has the
721 ;; side-effect that turning them off via X
722 ;; resources acts like having customized them, but
723 ;; that seems harmless.
724 menu-bar-mode tool-bar-mode))
725 ;; FIXME ? It's a little annoying that running this command
726 ;; always loads cua-base, paren, time, and battery, even if they
727 ;; have not been customized in any way. (Due to custom-load-symbol.)
728 (and (customize-mark-to-save elt)
730 ;; These are set with `customize-set-variable'.
731 (dolist (elt '(scroll-bar-mode
732 debug-on-quit debug-on-error
733 ;; Somehow this works, when tool-bar and menu-bar don't.
735 save-place uniquify-buffer-name-style fringe-mode
736 indicate-empty-lines indicate-buffer-boundaries
737 case-fold-search font-use-system-font
738 current-language-environment default-input-method
739 ;; Saving `text-mode-hook' is somewhat questionable,
740 ;; as we might get more than we bargain for, if
741 ;; other code may has added hooks as well.
742 ;; Nonetheless, not saving it would like be confuse
744 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
745 text-mode-hook tool-bar-position))
746 (and (get elt 'customized-value)
747 (customize-mark-to-save elt)
749 (when (get 'default 'customized-face)
750 (put 'default 'saved-face (get 'default 'customized-face))
751 (put 'default 'customized-face nil)
753 ;; Save if we changed anything.
758 ;;; Assemble all the top-level items of the "Options" menu
760 ;; The "Show/Hide" submenu of menu "Options"
762 (defun menu-bar-showhide-fringe-ind-customize ()
763 "Show customization buffer for `indicate-buffer-boundaries'."
765 (customize-variable 'indicate-buffer-boundaries))
767 (defun menu-bar-showhide-fringe-ind-mixed ()
768 "Display top and bottom indicators in opposite fringes, arrows in right."
770 (customize-set-variable 'indicate-buffer-boundaries
771 '((t . right) (top . left))))
773 (defun menu-bar-showhide-fringe-ind-box ()
774 "Display top and bottom indicators in opposite fringes."
776 (customize-set-variable 'indicate-buffer-boundaries
777 '((top . left) (bottom . right))))
779 (defun menu-bar-showhide-fringe-ind-right ()
780 "Display buffer boundaries and arrows in the right fringe."
782 (customize-set-variable 'indicate-buffer-boundaries 'right))
784 (defun menu-bar-showhide-fringe-ind-left ()
785 "Display buffer boundaries and arrows in the left fringe."
787 (customize-set-variable 'indicate-buffer-boundaries 'left))
789 (defun menu-bar-showhide-fringe-ind-none ()
790 "Do not display any buffer boundary indicators."
792 (customize-set-variable 'indicate-buffer-boundaries nil))
794 (defvar menu-bar-showhide-fringe-ind-menu
795 (let ((menu (make-sparse-keymap "Buffer boundaries")))
797 (define-key menu [customize]
798 `(menu-item ,(purecopy "Other (Customize)")
799 menu-bar-showhide-fringe-ind-customize
800 :help ,(purecopy "Additional choices available through Custom buffer")
801 :visible (display-graphic-p)
802 :button (:radio . (not (member indicate-buffer-boundaries
804 ((top . left) (bottom . right))
805 ((t . right) (top . left))))))))
807 (define-key menu [mixed]
808 `(menu-item ,(purecopy "Opposite, Arrows Right") menu-bar-showhide-fringe-ind-mixed
810 ,(purecopy "Show top/bottom indicators in opposite fringes, arrows in right")
811 :visible (display-graphic-p)
812 :button (:radio . (equal indicate-buffer-boundaries
813 '((t . right) (top . left))))))
815 (define-key menu [box]
816 `(menu-item ,(purecopy "Opposite, No Arrows") menu-bar-showhide-fringe-ind-box
817 :help ,(purecopy "Show top/bottom indicators in opposite fringes, no arrows")
818 :visible (display-graphic-p)
819 :button (:radio . (equal indicate-buffer-boundaries
820 '((top . left) (bottom . right))))))
822 (define-key menu [right]
823 `(menu-item ,(purecopy "In Right Fringe") menu-bar-showhide-fringe-ind-right
824 :help ,(purecopy "Show buffer boundaries and arrows in right fringe")
825 :visible (display-graphic-p)
826 :button (:radio . (eq indicate-buffer-boundaries 'right))))
828 (define-key menu [left]
829 `(menu-item ,(purecopy "In Left Fringe") menu-bar-showhide-fringe-ind-left
830 :help ,(purecopy "Show buffer boundaries and arrows in left fringe")
831 :visible (display-graphic-p)
832 :button (:radio . (eq indicate-buffer-boundaries 'left))))
834 (define-key menu [none]
835 `(menu-item ,(purecopy "No Indicators") menu-bar-showhide-fringe-ind-none
836 :help ,(purecopy "Hide all buffer boundary indicators and arrows")
837 :visible (display-graphic-p)
838 :button (:radio . (eq indicate-buffer-boundaries nil))))
841 (defun menu-bar-showhide-fringe-menu-customize ()
842 "Show customization buffer for `fringe-mode'."
844 (customize-variable 'fringe-mode))
846 (defun menu-bar-showhide-fringe-menu-customize-reset ()
847 "Reset the fringe mode: display fringes on both sides of a window."
849 (customize-set-variable 'fringe-mode nil))
851 (defun menu-bar-showhide-fringe-menu-customize-right ()
852 "Display fringes only on the right of each window."
855 (customize-set-variable 'fringe-mode '(0 . nil)))
857 (defun menu-bar-showhide-fringe-menu-customize-left ()
858 "Display fringes only on the left of each window."
861 (customize-set-variable 'fringe-mode '(nil . 0)))
863 (defun menu-bar-showhide-fringe-menu-customize-disable ()
864 "Do not display window fringes."
867 (customize-set-variable 'fringe-mode 0))
869 (defvar menu-bar-showhide-fringe-menu
870 (let ((menu (make-sparse-keymap "Fringe")))
872 (define-key menu [showhide-fringe-ind]
873 `(menu-item ,(purecopy "Buffer Boundaries") ,menu-bar-showhide-fringe-ind-menu
874 :visible (display-graphic-p)
875 :help ,(purecopy "Indicate buffer boundaries in fringe")))
877 (define-key menu [indicate-empty-lines]
878 (menu-bar-make-toggle toggle-indicate-empty-lines indicate-empty-lines
879 "Empty Line Indicators"
880 "Indicating of empty lines %s"
881 "Indicate trailing empty lines in fringe, globally"))
883 (define-key menu [customize]
884 `(menu-item ,(purecopy "Customize Fringe") menu-bar-showhide-fringe-menu-customize
885 :help ,(purecopy "Detailed customization of fringe")
886 :visible (display-graphic-p)))
888 (define-key menu [default]
889 `(menu-item ,(purecopy "Default") menu-bar-showhide-fringe-menu-customize-reset
890 :help ,(purecopy "Default width fringe on both left and right side")
891 :visible (display-graphic-p)
892 :button (:radio . (eq fringe-mode nil))))
894 (define-key menu [right]
895 `(menu-item ,(purecopy "On the Right") menu-bar-showhide-fringe-menu-customize-right
896 :help ,(purecopy "Fringe only on the right side")
897 :visible (display-graphic-p)
898 :button (:radio . (equal fringe-mode '(0 . nil)))))
900 (define-key menu [left]
901 `(menu-item ,(purecopy "On the Left") menu-bar-showhide-fringe-menu-customize-left
902 :help ,(purecopy "Fringe only on the left side")
903 :visible (display-graphic-p)
904 :button (:radio . (equal fringe-mode '(nil . 0)))))
906 (define-key menu [none]
907 `(menu-item ,(purecopy "None") menu-bar-showhide-fringe-menu-customize-disable
908 :help ,(purecopy "Turn off fringe")
909 :visible (display-graphic-p)
910 :button (:radio . (eq fringe-mode 0))))
913 (defun menu-bar-right-scroll-bar ()
914 "Display scroll bars on the right of each window."
916 (customize-set-variable 'scroll-bar-mode 'right))
918 (defun menu-bar-left-scroll-bar ()
919 "Display scroll bars on the left of each window."
921 (customize-set-variable 'scroll-bar-mode 'left))
923 (defun menu-bar-no-scroll-bar ()
924 "Turn off scroll bars."
926 (customize-set-variable 'scroll-bar-mode nil))
928 (defvar menu-bar-showhide-scroll-bar-menu
929 (let ((menu (make-sparse-keymap "Scroll-bar")))
931 (define-key menu [right]
932 `(menu-item ,(purecopy "On the Right")
933 menu-bar-right-scroll-bar
934 :help ,(purecopy "Scroll-bar on the right side")
935 :visible (display-graphic-p)
936 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
937 (frame-parameters))) 'right))))
939 (define-key menu [left]
940 `(menu-item ,(purecopy "On the Left")
941 menu-bar-left-scroll-bar
942 :help ,(purecopy "Scroll-bar on the left side")
943 :visible (display-graphic-p)
944 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
945 (frame-parameters))) 'left))))
947 (define-key menu [none]
948 `(menu-item ,(purecopy "None")
949 menu-bar-no-scroll-bar
950 :help ,(purecopy "Turn off scroll-bar")
951 :visible (display-graphic-p)
952 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
953 (frame-parameters))) nil))))
956 (defun menu-bar-frame-for-menubar ()
957 "Return the frame suitable for updating the menu bar."
958 (or (and (framep menu-updating-frame)
962 (defun menu-bar-positive-p (val)
963 "Return non-nil iff VAL is a positive number."
967 (defun menu-bar-set-tool-bar-position (position)
968 (customize-set-variable 'tool-bar-mode t)
969 (customize-set-variable 'tool-bar-position position))
970 (defun menu-bar-showhide-tool-bar-menu-customize-disable ()
971 "Do not display tool bars."
973 (customize-set-variable 'tool-bar-mode nil))
974 (defun menu-bar-showhide-tool-bar-menu-customize-enable-left ()
975 "Display tool bars on the left side."
977 (menu-bar-set-tool-bar-position 'left))
978 (defun menu-bar-showhide-tool-bar-menu-customize-enable-right ()
979 "Display tool bars on the right side."
981 (menu-bar-set-tool-bar-position 'right))
982 (defun menu-bar-showhide-tool-bar-menu-customize-enable-top ()
983 "Display tool bars on the top side."
985 (menu-bar-set-tool-bar-position 'top))
986 (defun menu-bar-showhide-tool-bar-menu-customize-enable-bottom ()
987 "Display tool bars on the bottom side."
989 (menu-bar-set-tool-bar-position 'bottom))
991 (when (featurep 'move-toolbar)
992 (defvar menu-bar-showhide-tool-bar-menu
993 (let ((menu (make-sparse-keymap "Tool-bar")))
995 (define-key menu [showhide-tool-bar-left]
996 `(menu-item ,(purecopy "On the Left")
997 menu-bar-showhide-tool-bar-menu-customize-enable-left
998 :help ,(purecopy "Tool-bar at the left side")
999 :visible (display-graphic-p)
1001 (:radio . (and tool-bar-mode
1002 (eq (frame-parameter
1003 (menu-bar-frame-for-menubar)
1007 (define-key menu [showhide-tool-bar-right]
1008 `(menu-item ,(purecopy "On the Right")
1009 menu-bar-showhide-tool-bar-menu-customize-enable-right
1010 :help ,(purecopy "Tool-bar at the right side")
1011 :visible (display-graphic-p)
1013 (:radio . (and tool-bar-mode
1014 (eq (frame-parameter
1015 (menu-bar-frame-for-menubar)
1019 (define-key menu [showhide-tool-bar-bottom]
1020 `(menu-item ,(purecopy "On the Bottom")
1021 menu-bar-showhide-tool-bar-menu-customize-enable-bottom
1022 :help ,(purecopy "Tool-bar at the bottom")
1023 :visible (display-graphic-p)
1025 (:radio . (and tool-bar-mode
1026 (eq (frame-parameter
1027 (menu-bar-frame-for-menubar)
1031 (define-key menu [showhide-tool-bar-top]
1032 `(menu-item ,(purecopy "On the Top")
1033 menu-bar-showhide-tool-bar-menu-customize-enable-top
1034 :help ,(purecopy "Tool-bar at the top")
1035 :visible (display-graphic-p)
1037 (:radio . (and tool-bar-mode
1038 (eq (frame-parameter
1039 (menu-bar-frame-for-menubar)
1043 (define-key menu [showhide-tool-bar-none]
1044 `(menu-item ,(purecopy "None")
1045 menu-bar-showhide-tool-bar-menu-customize-disable
1046 :help ,(purecopy "Turn tool-bar off")
1047 :visible (display-graphic-p)
1048 :button (:radio . (eq tool-bar-mode nil))))
1051 (defvar menu-bar-showhide-menu
1052 (let ((menu (make-sparse-keymap "Show/Hide")))
1054 (define-key menu [column-number-mode]
1055 (menu-bar-make-mm-toggle column-number-mode
1057 "Show the current column number in the mode line"))
1059 (define-key menu [line-number-mode]
1060 (menu-bar-make-mm-toggle line-number-mode
1062 "Show the current line number in the mode line"))
1064 (define-key menu [size-indication-mode]
1065 (menu-bar-make-mm-toggle size-indication-mode
1067 "Show the size of the buffer in the mode line"))
1069 (define-key menu [linecolumn-separator]
1072 (define-key menu [showhide-battery]
1073 (menu-bar-make-mm-toggle display-battery-mode
1075 "Display battery status information in mode line"))
1077 (define-key menu [showhide-date-time]
1078 (menu-bar-make-mm-toggle display-time-mode
1079 "Time, Load and Mail"
1080 "Display time, system load averages and \
1081 mail status in mode line"))
1083 (define-key menu [datetime-separator]
1086 (define-key menu [showhide-speedbar]
1087 `(menu-item ,(purecopy "Speedbar") speedbar-frame-mode
1088 :help ,(purecopy "Display a Speedbar quick-navigation frame")
1090 . (and (boundp 'speedbar-frame)
1091 (frame-live-p (symbol-value 'speedbar-frame))
1093 (symbol-value 'speedbar-frame))))))
1095 (define-key menu [showhide-fringe]
1096 `(menu-item ,(purecopy "Fringe") ,menu-bar-showhide-fringe-menu
1097 :visible (display-graphic-p)))
1099 (define-key menu [showhide-scroll-bar]
1100 `(menu-item ,(purecopy "Scroll-bar") ,menu-bar-showhide-scroll-bar-menu
1101 :visible (display-graphic-p)))
1103 (define-key menu [showhide-tooltip-mode]
1104 `(menu-item ,(purecopy "Tooltips") tooltip-mode
1105 :help ,(purecopy "Turn tooltips on/off")
1106 :visible (and (display-graphic-p) (fboundp 'x-show-tip))
1107 :button (:toggle . tooltip-mode)))
1109 (define-key menu [menu-bar-mode]
1110 `(menu-item ,(purecopy "Menu-bar") toggle-menu-bar-mode-from-frame
1111 :help ,(purecopy "Turn menu-bar on/off")
1113 (:toggle . (menu-bar-positive-p
1114 (frame-parameter (menu-bar-frame-for-menubar)
1115 'menu-bar-lines)))))
1117 (if (and (boundp 'menu-bar-showhide-tool-bar-menu)
1118 (keymapp menu-bar-showhide-tool-bar-menu))
1119 (define-key menu [showhide-tool-bar]
1120 `(menu-item ,(purecopy "Tool-bar") ,menu-bar-showhide-tool-bar-menu
1121 :visible (display-graphic-p)))
1122 ;; else not tool bar that can move.
1123 (define-key menu [showhide-tool-bar]
1124 `(menu-item ,(purecopy "Tool-bar") toggle-tool-bar-mode-from-frame
1125 :help ,(purecopy "Turn tool-bar on/off")
1126 :visible (display-graphic-p)
1128 (:toggle . (menu-bar-positive-p
1129 (frame-parameter (menu-bar-frame-for-menubar)
1130 'tool-bar-lines))))))
1133 (defun menu-bar-text-mode-auto-fill ()
1135 (toggle-text-mode-auto-fill)
1136 ;; This is somewhat questionable, as `text-mode-hook'
1137 ;; might have changed outside customize.
1138 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
1139 (customize-mark-as-set 'text-mode-hook))
1142 (defvar menu-bar-line-wrapping-menu
1143 (let ((menu (make-sparse-keymap "Line Wrapping")))
1145 (define-key menu [word-wrap]
1147 ,(purecopy "Word Wrap (Visual Line mode)")
1150 (unless visual-line-mode
1151 (visual-line-mode 1))
1152 (message ,(purecopy "Visual-Line mode enabled")))
1153 :help ,(purecopy "Wrap long lines at word boundaries")
1154 :button (:radio . (and (null truncate-lines)
1155 (not (truncated-partial-width-window-p))
1157 :visible (menu-bar-menu-frame-live-and-visible-p)))
1159 (define-key menu [truncate]
1160 `(menu-item ,(purecopy "Truncate Long Lines")
1163 (if visual-line-mode (visual-line-mode 0))
1164 (setq word-wrap nil)
1165 (toggle-truncate-lines 1))
1166 :help ,(purecopy "Truncate long lines at window edge")
1167 :button (:radio . (or truncate-lines
1168 (truncated-partial-width-window-p)))
1169 :visible (menu-bar-menu-frame-live-and-visible-p)
1170 :enable (not (truncated-partial-width-window-p))))
1172 (define-key menu [window-wrap]
1173 `(menu-item ,(purecopy "Wrap at Window Edge")
1174 (lambda () (interactive)
1175 (if visual-line-mode (visual-line-mode 0))
1176 (setq word-wrap nil)
1177 (if truncate-lines (toggle-truncate-lines -1)))
1178 :help ,(purecopy "Wrap long lines at window edge")
1179 :button (:radio . (and (null truncate-lines)
1180 (not (truncated-partial-width-window-p))
1182 :visible (menu-bar-menu-frame-live-and-visible-p)
1183 :enable (not (truncated-partial-width-window-p))))
1186 (defvar menu-bar-options-menu
1187 (let ((menu (make-sparse-keymap "Options")))
1188 (define-key menu [customize]
1189 `(menu-item ,(purecopy "Customize Emacs") ,menu-bar-custom-menu))
1191 (define-key menu [package]
1192 '(menu-item "Manage Emacs Packages" package-list-packages
1193 :help "Install or uninstall additional Emacs packages"))
1195 (define-key menu [save]
1196 `(menu-item ,(purecopy "Save Options") menu-bar-options-save
1197 :help ,(purecopy "Save options set from the menu above")))
1199 (define-key menu [custom-separator]
1202 (define-key menu [menu-set-font]
1203 `(menu-item ,(purecopy "Set Default Font...") menu-set-font
1204 :visible (display-multi-font-p)
1205 :help ,(purecopy "Select a default font")))
1207 (if (featurep 'system-font-setting)
1208 (define-key menu [menu-system-font]
1209 (menu-bar-make-toggle
1210 toggle-use-system-font font-use-system-font
1212 "Use system font: %s"
1213 "Use the monospaced font defined by the system")))
1215 (define-key menu [showhide]
1216 `(menu-item ,(purecopy "Show/Hide") ,menu-bar-showhide-menu))
1218 (define-key menu [showhide-separator]
1221 (define-key menu [mule]
1222 ;; It is better not to use backquote here,
1223 ;; because that makes a bootstrapping problem
1224 ;; if you need to recompile all the Lisp files using interpreted code.
1225 `(menu-item ,(purecopy "Multilingual Environment") ,mule-menu-keymap
1226 ;; Most of the MULE menu actually does make sense in
1227 ;; unibyte mode, e.g. language selection.
1228 ;; :visible '(default-value 'enable-multibyte-characters)
1230 ;;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
1231 ;;(define-key menu [preferences]
1232 ;; `(menu-item ,(purecopy "Preferences") ,menu-bar-preferences-menu
1233 ;; :help ,(purecopy "Toggle important global options")))
1235 (define-key menu [mule-separator]
1238 (define-key menu [debug-on-quit]
1239 (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
1240 "Enter Debugger on Quit/C-g" "Debug on Quit %s"
1241 "Enter Lisp debugger when C-g is pressed"))
1242 (define-key menu [debug-on-error]
1243 (menu-bar-make-toggle toggle-debug-on-error debug-on-error
1244 "Enter Debugger on Error" "Debug on Error %s"
1245 "Enter Lisp debugger when an error is signaled"))
1246 (define-key menu [debugger-separator]
1249 (define-key menu [blink-cursor-mode]
1250 (menu-bar-make-mm-toggle
1253 "Whether the cursor blinks (Blink Cursor mode)"))
1254 (define-key menu [cursor-separator]
1257 (define-key menu [save-place]
1258 (menu-bar-make-toggle
1259 toggle-save-place-globally save-place
1260 "Save Place in Files between Sessions"
1261 "Saving place in files %s"
1262 "Visit files of previous session when restarting Emacs"
1263 (require 'saveplace)
1264 ;; Do it by name, to avoid a free-variable
1265 ;; warning during byte compilation.
1267 'save-place (not (symbol-value 'save-place)))))
1269 (define-key menu [uniquify]
1270 (menu-bar-make-toggle
1271 toggle-uniquify-buffer-names uniquify-buffer-name-style
1272 "Use Directory Names in Buffer Names"
1273 "Directory name in buffer names (uniquify) %s"
1274 "Uniquify buffer names by adding parent directory names"
1276 (setq uniquify-buffer-name-style
1277 (if (not uniquify-buffer-name-style)
1280 (define-key menu [edit-options-separator]
1282 (define-key menu [cua-mode]
1283 (menu-bar-make-mm-toggle
1285 "Use CUA Keys (Cut/Paste with C-x/C-c/C-v)"
1286 "Use C-z/C-x/C-c/C-v keys for undo/cut/copy/paste"
1287 (:visible (or (not (boundp 'cua-enable-cua-keys))
1288 cua-enable-cua-keys))))
1290 (define-key menu [cua-emulation-mode]
1291 (menu-bar-make-mm-toggle
1293 "Shift movement mark region (CUA)"
1294 "Use shifted movement keys to set and extend the region"
1295 (:visible (and (boundp 'cua-enable-cua-keys)
1296 (not cua-enable-cua-keys)))))
1298 (define-key menu [case-fold-search]
1299 (menu-bar-make-toggle
1300 toggle-case-fold-search case-fold-search
1301 "Ignore Case for Search"
1302 "Case-Insensitive Search %s"
1303 "Ignore letter-case in search commands"))
1305 (define-key menu [auto-fill-mode]
1307 ,(purecopy "Auto Fill in Text Modes")
1308 menu-bar-text-mode-auto-fill
1309 :help ,(purecopy "Automatically fill text while typing (Auto Fill mode)")
1310 :button (:toggle . (if (listp text-mode-hook)
1311 (member 'turn-on-auto-fill text-mode-hook)
1312 (eq 'turn-on-auto-fill text-mode-hook)))))
1314 (define-key menu [line-wrapping]
1315 `(menu-item ,(purecopy "Line Wrapping in This Buffer")
1316 ,menu-bar-line-wrapping-menu))
1319 (define-key menu [highlight-separator]
1321 (define-key menu [highlight-paren-mode]
1322 (menu-bar-make-mm-toggle
1324 "Highlight Matching Parentheses"
1325 "Highlight matching/mismatched parentheses at cursor (Show Paren mode)"))
1326 (define-key menu [transient-mark-mode]
1327 (menu-bar-make-mm-toggle
1329 "Highlight Active Region"
1330 "Make text in active region stand out in color (Transient Mark mode)"
1331 (:enable (not cua-mode))))
1335 ;; The "Tools" menu items
1337 (defun send-mail-item-name ()
1338 (let* ((known-send-mail-commands '((sendmail-user-agent . "sendmail")
1339 (mh-e-user-agent . "MH")
1340 (message-user-agent . "Gnus Message")
1341 (gnus-user-agent . "Gnus")))
1342 (name (assq mail-user-agent known-send-mail-commands)))
1344 (setq name (cdr name))
1345 (setq name (symbol-name mail-user-agent))
1346 (if (string-match "\\(.+\\)-user-agent" name)
1347 (setq name (match-string 1 name))))
1350 (defun read-mail-item-name ()
1351 (let* ((known-rmail-commands '((rmail . "RMAIL")
1354 (known (assq read-mail-command known-rmail-commands)))
1355 (if known (cdr known) (symbol-name read-mail-command))))
1357 (defvar menu-bar-games-menu
1358 (let ((menu (make-sparse-keymap "Games")))
1360 (define-key menu [zone]
1361 `(menu-item ,(purecopy "Zone Out") zone
1362 :help ,(purecopy "Play tricks with Emacs display when Emacs is idle")))
1363 (define-key menu [tetris]
1364 `(menu-item ,(purecopy "Tetris") tetris
1365 :help ,(purecopy "Falling blocks game")))
1366 (define-key menu [solitaire]
1367 `(menu-item ,(purecopy "Solitaire") solitaire
1368 :help ,(purecopy "Get rid of all the stones")))
1369 (define-key menu [snake]
1370 `(menu-item ,(purecopy "Snake") snake
1371 :help ,(purecopy "Move snake around avoiding collisions")))
1372 (define-key menu [pong]
1373 `(menu-item ,(purecopy "Pong") pong
1374 :help ,(purecopy "Bounce the ball to your opponent")))
1375 (define-key menu [mult]
1376 `(menu-item ,(purecopy "Multiplication Puzzle") mpuz
1377 :help ,(purecopy "Exercise brain with multiplication")))
1378 (define-key menu [life]
1379 `(menu-item ,(purecopy "Life") life
1380 :help ,(purecopy "Watch how John Conway's cellular automaton evolves")))
1381 (define-key menu [land]
1382 `(menu-item ,(purecopy "Landmark") landmark
1383 :help ,(purecopy "Watch a neural-network robot learn landmarks")))
1384 (define-key menu [hanoi]
1385 `(menu-item ,(purecopy "Towers of Hanoi") hanoi
1386 :help ,(purecopy "Watch Towers-of-Hanoi puzzle solved by Emacs")))
1387 (define-key menu [gomoku]
1388 `(menu-item ,(purecopy "Gomoku") gomoku
1389 :help ,(purecopy "Mark 5 contiguous squares (like tic-tac-toe)")))
1390 (define-key menu [bubbles]
1391 `(menu-item ,(purecopy "Bubbles") bubbles
1392 :help ,(purecopy "Remove all bubbles using the fewest moves")))
1393 (define-key menu [black-box]
1394 `(menu-item ,(purecopy "Blackbox") blackbox
1395 :help ,(purecopy "Find balls in a black box by shooting rays")))
1396 (define-key menu [adventure]
1397 `(menu-item ,(purecopy "Adventure") dunnet
1398 :help ,(purecopy "Dunnet, a text Adventure game for Emacs")))
1399 (define-key menu [5x5]
1400 `(menu-item ,(purecopy "5x5") 5x5
1401 :help ,(purecopy "Fill in all the squares on a 5x5 board")))
1404 (defvar menu-bar-encryption-decryption-menu
1405 (let ((menu (make-sparse-keymap "Encryption/Decryption")))
1406 (define-key menu [insert-keys]
1407 `(menu-item ,(purecopy "Insert Keys") epa-insert-keys
1408 :help ,(purecopy "Insert public keys after the current point")))
1410 (define-key menu [export-keys]
1411 `(menu-item ,(purecopy "Export Keys") epa-export-keys
1412 :help ,(purecopy "Export public keys to a file")))
1414 (define-key menu [import-keys-region]
1415 `(menu-item ,(purecopy "Import Keys from Region") epa-import-keys-region
1416 :help ,(purecopy "Import public keys from the current region")))
1418 (define-key menu [import-keys]
1419 `(menu-item ,(purecopy "Import Keys from File...") epa-import-keys
1420 :help ,(purecopy "Import public keys from a file")))
1422 (define-key menu [list-keys]
1423 `(menu-item ,(purecopy "List Keys") epa-list-keys
1424 :help ,(purecopy "Browse your public keyring")))
1426 (define-key menu [separator-keys]
1429 (define-key menu [sign-region]
1430 `(menu-item ,(purecopy "Sign Region") epa-sign-region
1431 :help ,(purecopy "Create digital signature of the current region")))
1433 (define-key menu [verify-region]
1434 `(menu-item ,(purecopy "Verify Region") epa-verify-region
1435 :help ,(purecopy "Verify digital signature of the current region")))
1437 (define-key menu [encrypt-region]
1438 `(menu-item ,(purecopy "Encrypt Region") epa-encrypt-region
1439 :help ,(purecopy "Encrypt the current region")))
1441 (define-key menu [decrypt-region]
1442 `(menu-item ,(purecopy "Decrypt Region") epa-decrypt-region
1443 :help ,(purecopy "Decrypt the current region")))
1445 (define-key menu [separator-file]
1448 (define-key menu [sign-file]
1449 `(menu-item ,(purecopy "Sign File...") epa-sign-file
1450 :help ,(purecopy "Create digital signature of a file")))
1452 (define-key menu [verify-file]
1453 `(menu-item ,(purecopy "Verify File...") epa-verify-file
1454 :help ,(purecopy "Verify digital signature of a file")))
1456 (define-key menu [encrypt-file]
1457 `(menu-item ,(purecopy "Encrypt File...") epa-encrypt-file
1458 :help ,(purecopy "Encrypt a file")))
1460 (define-key menu [decrypt-file]
1461 `(menu-item ,(purecopy "Decrypt File...") epa-decrypt-file
1462 :help ,(purecopy "Decrypt a file")))
1466 (defun menu-bar-read-mail ()
1467 "Read mail using `read-mail-command'."
1469 (call-interactively read-mail-command))
1471 (defvar menu-bar-tools-menu
1472 (let ((menu (make-sparse-keymap "Tools")))
1474 (define-key menu [games]
1475 `(menu-item ,(purecopy "Games") ,menu-bar-games-menu))
1477 (define-key menu [separator-games]
1480 (define-key menu [encryption-decryption]
1481 `(menu-item ,(purecopy "Encryption/Decryption") ,menu-bar-encryption-decryption-menu))
1483 (define-key menu [separator-encryption-decryption]
1486 (define-key menu [simple-calculator]
1487 `(menu-item ,(purecopy "Simple Calculator") calculator
1488 :help ,(purecopy "Invoke the Emacs built-in quick calculator")))
1489 (define-key menu [calc]
1490 `(menu-item ,(purecopy "Programmable Calculator") calc
1491 :help ,(purecopy "Invoke the Emacs built-in full scientific calculator")))
1492 (define-key menu [calendar]
1493 `(menu-item ,(purecopy "Calendar") calendar
1494 :help ,(purecopy "Invoke the Emacs built-in calendar")))
1496 (define-key menu [separator-net]
1499 (define-key menu [directory-search]
1500 `(menu-item ,(purecopy "Directory Search") eudc-tools-menu))
1501 (define-key menu [compose-mail]
1502 `(menu-item (format "Send Mail (with %s)" (send-mail-item-name)) compose-mail
1503 :visible (and mail-user-agent (not (eq mail-user-agent 'ignore)))
1504 :help ,(purecopy "Send a mail message")))
1505 (define-key menu [rmail]
1506 `(menu-item (format "Read Mail (with %s)" (read-mail-item-name))
1508 :visible (and read-mail-command
1509 (not (eq read-mail-command 'ignore)))
1510 :help ,(purecopy "Read your mail and reply to it")))
1512 (define-key menu [gnus]
1513 `(menu-item ,(purecopy "Read Net News (Gnus)") gnus
1514 :help ,(purecopy "Read network news groups")))
1516 (define-key menu [separator-vc]
1519 (define-key menu [pcl-cvs]
1520 `(menu-item ,(purecopy "PCL-CVS") cvs-global-menu))
1521 (define-key menu [vc] nil) ;Create the place for the VC menu.
1523 (define-key menu [separator-compare]
1526 (define-key menu [epatch]
1527 `(menu-item ,(purecopy "Apply Patch") menu-bar-epatch-menu))
1528 (define-key menu [ediff-merge]
1529 `(menu-item ,(purecopy "Merge") menu-bar-ediff-merge-menu))
1530 (define-key menu [compare]
1531 `(menu-item ,(purecopy "Compare (Ediff)") menu-bar-ediff-menu))
1533 (define-key menu [separator-spell]
1536 (define-key menu [spell]
1537 `(menu-item ,(purecopy "Spell Checking") ispell-menu-map))
1539 (define-key menu [separator-prog]
1542 (define-key menu [semantic]
1543 `(menu-item ,(purecopy "Source Code Parsers (Semantic)")
1545 :help ,(purecopy "Toggle automatic parsing in source code buffers (Semantic mode)")
1546 :button (:toggle . (bound-and-true-p semantic-mode))))
1548 (define-key menu [ede]
1549 `(menu-item ,(purecopy "Project support (EDE)")
1551 :help ,(purecopy "Toggle the Emacs Development Environment (Global EDE mode)")
1552 :button (:toggle . (bound-and-true-p global-ede-mode))))
1554 (define-key menu [gdb]
1555 `(menu-item ,(purecopy "Debugger (GDB)...") gdb
1556 :help ,(purecopy "Debug a program from within Emacs with GDB")))
1557 (define-key menu [shell-on-region]
1558 `(menu-item ,(purecopy "Shell Command on Region...") shell-command-on-region
1560 :help ,(purecopy "Pass marked region to a shell command")))
1561 (define-key menu [shell]
1562 `(menu-item ,(purecopy "Shell Command...") shell-command
1563 :help ,(purecopy "Invoke a shell command and catch its output")))
1564 (define-key menu [compile]
1565 `(menu-item ,(purecopy "Compile...") compile
1566 :help ,(purecopy "Invoke compiler or Make, view compilation errors")))
1567 (define-key menu [grep]
1568 `(menu-item ,(purecopy "Search Files (Grep)...") grep
1569 :help ,(purecopy "Search files for strings or regexps (with Grep)")))
1572 ;; The "Help" menu items
1574 (defvar menu-bar-describe-menu
1575 (let ((menu (make-sparse-keymap "Describe")))
1577 (define-key menu [mule-diag]
1578 `(menu-item ,(purecopy "Show All of Mule Status") mule-diag
1579 :visible (default-value 'enable-multibyte-characters)
1580 :help ,(purecopy "Display multilingual environment settings")))
1581 (define-key menu [describe-coding-system-briefly]
1582 `(menu-item ,(purecopy "Describe Coding System (Briefly)")
1583 describe-current-coding-system-briefly
1584 :visible (default-value 'enable-multibyte-characters)))
1585 (define-key menu [describe-coding-system]
1586 `(menu-item ,(purecopy "Describe Coding System...") describe-coding-system
1587 :visible (default-value 'enable-multibyte-characters)))
1588 (define-key menu [describe-input-method]
1589 `(menu-item ,(purecopy "Describe Input Method...") describe-input-method
1590 :visible (default-value 'enable-multibyte-characters)
1591 :help ,(purecopy "Keyboard layout for specific input method")))
1592 (define-key menu [describe-language-environment]
1593 `(menu-item ,(purecopy "Describe Language Environment")
1594 ,describe-language-environment-map))
1596 (define-key menu [separator-desc-mule]
1599 (define-key menu [list-keybindings]
1600 `(menu-item ,(purecopy "List Key Bindings") describe-bindings
1601 :help ,(purecopy "Display all current key bindings (keyboard shortcuts)")))
1602 (define-key menu [describe-current-display-table]
1603 `(menu-item ,(purecopy "Describe Display Table") describe-current-display-table
1604 :help ,(purecopy "Describe the current display table")))
1605 (define-key menu [describe-package]
1606 `(menu-item ,(purecopy "Describe Package...") describe-package
1607 :help ,(purecopy "Display documentation of a Lisp package")))
1608 (define-key menu [describe-face]
1609 `(menu-item ,(purecopy "Describe Face...") describe-face
1610 :help ,(purecopy "Display the properties of a face")))
1611 (define-key menu [describe-variable]
1612 `(menu-item ,(purecopy "Describe Variable...") describe-variable
1613 :help ,(purecopy "Display documentation of variable/option")))
1614 (define-key menu [describe-function]
1615 `(menu-item ,(purecopy "Describe Function...") describe-function
1616 :help ,(purecopy "Display documentation of function/command")))
1617 (define-key menu [describe-key-1]
1618 `(menu-item ,(purecopy "Describe Key or Mouse Operation...") describe-key
1619 ;; Users typically don't identify keys and menu items...
1620 :help ,(purecopy "Display documentation of command bound to a \
1621 key, a click, or a menu-item")))
1622 (define-key menu [describe-mode]
1623 `(menu-item ,(purecopy "Describe Buffer Modes") describe-mode
1624 :help ,(purecopy "Describe this buffer's major and minor mode")))
1627 (defun menu-bar-read-lispref ()
1628 "Display the Emacs Lisp Reference manual in Info mode."
1632 (defun menu-bar-read-lispintro ()
1633 "Display the Introduction to Emacs Lisp Programming in Info mode."
1637 (defun search-emacs-glossary ()
1638 "Display the Glossary node of the Emacs manual in Info mode."
1640 (info "(emacs)Glossary"))
1642 (defun emacs-index-search (topic)
1643 "Look up TOPIC in the indices of the Emacs User Manual."
1644 (interactive "sSubject to look up: ")
1648 (defun elisp-index-search (topic)
1649 "Look up TOPIC in the indices of the Emacs Lisp Reference Manual."
1650 (interactive "sSubject to look up: ")
1654 (defvar menu-bar-search-documentation-menu
1655 (let ((menu (make-sparse-keymap "Search Documentation")))
1657 (define-key menu [search-documentation-strings]
1658 `(menu-item ,(purecopy "Search Documentation Strings...") apropos-documentation
1660 ,(purecopy "Find functions and variables whose doc strings match a regexp")))
1661 (define-key menu [find-any-object-by-name]
1662 `(menu-item ,(purecopy "Find Any Object by Name...") apropos
1663 :help ,(purecopy "Find symbols of any kind whose names match a regexp")))
1664 (define-key menu [find-option-by-value]
1665 `(menu-item ,(purecopy "Find Options by Value...") apropos-value
1666 :help ,(purecopy "Find variables whose values match a regexp")))
1667 (define-key menu [find-options-by-name]
1668 `(menu-item ,(purecopy "Find Options by Name...") apropos-variable
1669 :help ,(purecopy "Find variables whose names match a regexp")))
1670 (define-key menu [find-commands-by-name]
1671 `(menu-item ,(purecopy "Find Commands by Name...") apropos-command
1672 :help ,(purecopy "Find commands whose names match a regexp")))
1673 (define-key menu [sep1]
1675 (define-key menu [lookup-command-in-manual]
1676 `(menu-item ,(purecopy "Look Up Command in User Manual...") Info-goto-emacs-command-node
1677 :help ,(purecopy "Display manual section that describes a command")))
1678 (define-key menu [lookup-key-in-manual]
1679 `(menu-item ,(purecopy "Look Up Key in User Manual...") Info-goto-emacs-key-command-node
1680 :help ,(purecopy "Display manual section that describes a key")))
1681 (define-key menu [lookup-subject-in-elisp-manual]
1682 `(menu-item ,(purecopy "Look Up Subject in ELisp Manual...") elisp-index-search
1683 :help ,(purecopy "Find description of a subject in Emacs Lisp manual")))
1684 (define-key menu [lookup-subject-in-emacs-manual]
1685 `(menu-item ,(purecopy "Look Up Subject in User Manual...") emacs-index-search
1686 :help ,(purecopy "Find description of a subject in Emacs User manual")))
1687 (define-key menu [emacs-terminology]
1688 `(menu-item ,(purecopy "Emacs Terminology") search-emacs-glossary
1689 :help ,(purecopy "Display the Glossary section of the Emacs manual")))
1692 (defvar menu-bar-manuals-menu
1693 (let ((menu (make-sparse-keymap "More Manuals")))
1695 (define-key menu [man]
1696 `(menu-item ,(purecopy "Read Man Page...") manual-entry
1697 :help ,(purecopy "Man-page docs for external commands and libraries")))
1698 (define-key menu [sep2]
1700 (define-key menu [order-emacs-manuals]
1701 `(menu-item ,(purecopy "Ordering Manuals") view-order-manuals
1702 :help ,(purecopy "How to order manuals from the Free Software Foundation")))
1703 (define-key menu [lookup-subject-in-all-manuals]
1704 `(menu-item ,(purecopy "Lookup Subject in all Manuals...") info-apropos
1705 :help ,(purecopy "Find description of a subject in all installed manuals")))
1706 (define-key menu [other-manuals]
1707 `(menu-item ,(purecopy "All Other Manuals (Info)") Info-directory
1708 :help ,(purecopy "Read any of the installed manuals")))
1709 (define-key menu [emacs-lisp-reference]
1710 `(menu-item ,(purecopy "Emacs Lisp Reference") menu-bar-read-lispref
1711 :help ,(purecopy "Read the Emacs Lisp Reference manual")))
1712 (define-key menu [emacs-lisp-intro]
1713 `(menu-item ,(purecopy "Introduction to Emacs Lisp") menu-bar-read-lispintro
1714 :help ,(purecopy "Read the Introduction to Emacs Lisp Programming")))
1717 (defun menu-bar-help-extra-packages ()
1718 "Display help about some additional packages available for Emacs."
1720 (let (enable-local-variables)
1721 (view-file (expand-file-name "MORE.STUFF"
1723 (goto-address-mode 1)))
1725 (defun help-with-tutorial-spec-language ()
1726 "Use the Emacs tutorial, specifying which language you want."
1728 (help-with-tutorial t))
1730 (defvar menu-bar-help-menu
1731 (let ((menu (make-sparse-keymap "Help")))
1732 (define-key menu [about-gnu-project]
1733 `(menu-item ,(purecopy "About GNU") describe-gnu-project
1734 :help ,(purecopy "About the GNU System, GNU Project, and GNU/Linux")))
1735 (define-key menu [about-emacs]
1736 `(menu-item ,(purecopy "About Emacs") about-emacs
1737 :help ,(purecopy "Display version number, copyright info, and basic help")))
1738 (define-key menu [sep4]
1740 (define-key menu [describe-no-warranty]
1741 `(menu-item ,(purecopy "(Non)Warranty") describe-no-warranty
1742 :help ,(purecopy "Explain that Emacs has NO WARRANTY")))
1743 (define-key menu [describe-copying]
1744 `(menu-item ,(purecopy "Copying Conditions") describe-copying
1745 :help ,(purecopy "Show the Emacs license (GPL)")))
1746 (define-key menu [getting-new-versions]
1747 `(menu-item ,(purecopy "Getting New Versions") describe-distribution
1748 :help ,(purecopy "How to get the latest version of Emacs")))
1749 (define-key menu [sep2]
1751 (define-key menu [external-packages]
1752 `(menu-item ,(purecopy "Finding Extra Packages") menu-bar-help-extra-packages
1753 :help ,(purecopy "Lisp packages distributed separately for use in Emacs")))
1754 (define-key menu [find-emacs-packages]
1755 `(menu-item ,(purecopy "Search Built-in Packages") finder-by-keyword
1756 :help ,(purecopy "Find built-in packages and features by keyword")))
1757 (define-key menu [more-manuals]
1758 `(menu-item ,(purecopy "More Manuals") ,menu-bar-manuals-menu))
1759 (define-key menu [emacs-manual]
1760 `(menu-item ,(purecopy "Read the Emacs Manual") info-emacs-manual
1761 :help ,(purecopy "Full documentation of Emacs features")))
1762 (define-key menu [describe]
1763 `(menu-item ,(purecopy "Describe") ,menu-bar-describe-menu))
1764 (define-key menu [search-documentation]
1765 `(menu-item ,(purecopy "Search Documentation") ,menu-bar-search-documentation-menu))
1766 (define-key menu [sep1]
1768 (define-key menu [emacs-psychotherapist]
1769 `(menu-item ,(purecopy "Emacs Psychotherapist") doctor
1770 :help ,(purecopy "Our doctor will help you feel better")))
1771 (define-key menu [send-emacs-bug-report]
1772 `(menu-item ,(purecopy "Send Bug Report...") report-emacs-bug
1773 :help ,(purecopy "Send e-mail to Emacs maintainers")))
1774 (define-key menu [emacs-known-problems]
1775 `(menu-item ,(purecopy "Emacs Known Problems") view-emacs-problems
1776 :help ,(purecopy "Read about known problems with Emacs")))
1777 (define-key menu [emacs-news]
1778 `(menu-item ,(purecopy "Emacs News") view-emacs-news
1779 :help ,(purecopy "New features of this version")))
1780 (define-key menu [emacs-faq]
1781 `(menu-item ,(purecopy "Emacs FAQ") view-emacs-FAQ
1782 :help ,(purecopy "Frequently asked (and answered) questions about Emacs")))
1784 (define-key menu [emacs-tutorial-language-specific]
1785 `(menu-item ,(purecopy "Emacs Tutorial (choose language)...")
1786 help-with-tutorial-spec-language
1787 :help ,(purecopy "Learn how to use Emacs (choose a language)")))
1788 (define-key menu [emacs-tutorial]
1789 `(menu-item ,(purecopy "Emacs Tutorial") help-with-tutorial
1790 :help ,(purecopy "Learn how to use Emacs")))
1792 ;; In OS X it's in the app menu already.
1793 ;; FIXME? There already is an "About Emacs" (sans ...) entry in the Help menu.
1795 (not (eq system-type 'darwin))
1796 (define-key menu [info-panel]
1797 `(menu-item ,(purecopy "About Emacs...") ns-do-emacs-info-panel)))
1800 (define-key global-map [menu-bar tools]
1801 (cons (purecopy "Tools") menu-bar-tools-menu))
1802 (define-key global-map [menu-bar buffer]
1803 (cons (purecopy "Buffers") global-buffers-menu-map))
1804 (define-key global-map [menu-bar options]
1805 (cons (purecopy "Options") menu-bar-options-menu))
1806 (define-key global-map [menu-bar edit]
1807 (cons (purecopy "Edit") menu-bar-edit-menu))
1808 (define-key global-map [menu-bar file]
1809 (cons (purecopy "File") menu-bar-file-menu))
1811 ;; Put "Help" menu at the end, or Info at the front.
1812 ;; If running under GNUstep, "Help" is moved and renamed "Info" (see below).
1813 (if (and (featurep 'ns)
1814 (not (eq system-type 'darwin)))
1815 (define-key global-map [menu-bar help-menu]
1816 (cons (purecopy "Info") menu-bar-help-menu))
1817 (define-key-after global-map [menu-bar help-menu]
1818 (cons (purecopy "Help") menu-bar-help-menu)))
1820 (defun menu-bar-menu-frame-live-and-visible-p ()
1821 "Return non-nil if the menu frame is alive and visible.
1822 The menu frame is the frame for which we are updating the menu."
1823 (let ((menu-frame (or menu-updating-frame (selected-frame))))
1824 (and (frame-live-p menu-frame)
1825 (frame-visible-p menu-frame))))
1827 (defun menu-bar-non-minibuffer-window-p ()
1828 "Return non-nil if selected window of the menu frame is not a minibuf window.
1830 See the documentation of `menu-bar-menu-frame-live-and-visible-p'
1831 for the definition of the menu frame."
1832 (let ((menu-frame (or menu-updating-frame (selected-frame))))
1833 (not (window-minibuffer-p (frame-selected-window menu-frame)))))
1835 (defun kill-this-buffer () ; for the menu bar
1836 "Kill the current buffer.
1837 When called in the minibuffer, get out of the minibuffer
1838 using `abort-recursive-edit'."
1840 (if (menu-bar-non-minibuffer-window-p)
1841 (kill-buffer (current-buffer))
1842 (abort-recursive-edit)))
1844 (defun kill-this-buffer-enabled-p ()
1845 "Return non-nil if the `kill-this-buffer' menu item should be enabled."
1846 (or (not (menu-bar-non-minibuffer-window-p))
1848 ;; Instead of looping over entire buffer list, stop once we've
1849 ;; found two "killable" buffers (Bug#8184).
1851 (dolist (buffer (buffer-list))
1852 (unless (string-match-p "^ " (buffer-name buffer))
1855 (throw 'found-2 t))))))))
1857 (put 'dired 'menu-enable '(menu-bar-non-minibuffer-window-p))
1859 ;; Permit deleting frame if it would leave a visible or iconified frame.
1860 (defun delete-frame-enabled-p ()
1861 "Return non-nil if `delete-frame' should be enabled in the menu bar."
1862 (let ((frames (frame-list))
1865 (if (frame-visible-p (car frames))
1866 (setq count (1+ count)))
1867 (setq frames (cdr frames)))
1870 (defcustom yank-menu-length 20
1871 "Maximum length to display in the yank-menu."
1875 (defun menu-bar-update-yank-menu (string old)
1876 (let ((front (car (cdr yank-menu)))
1877 (menu-string (if (<= (length string) yank-menu-length)
1880 (substring string 0 (/ yank-menu-length 2))
1882 (substring string (- (/ yank-menu-length 2)))))))
1883 ;; Don't let the menu string be all dashes
1884 ;; because that has a special meaning in a menu.
1885 (if (string-match "\\`-+\\'" menu-string)
1886 (setq menu-string (concat menu-string " ")))
1887 ;; If we're supposed to be extending an existing string, and that
1888 ;; string really is at the front of the menu, then update it in place.
1889 (if (and old (or (eq old (car front))
1890 (string= old (car front))))
1892 (setcar front string)
1893 (setcar (cdr front) menu-string))
1896 (cons string (cons menu-string 'menu-bar-select-yank))
1898 (if (> (length (cdr yank-menu)) kill-ring-max)
1899 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
1901 (put 'menu-bar-select-yank 'apropos-inhibit t)
1902 (defun menu-bar-select-yank ()
1903 "Insert the stretch of previously-killed text selected from menu.
1904 The menu shows all the killed text sequences stored in `kill-ring'."
1907 (insert last-command-event))
1912 (defcustom buffers-menu-max-size 10
1913 "Maximum number of entries which may appear on the Buffers menu.
1914 If this is 10, then only the ten most-recently-selected buffers are shown.
1915 If this is nil, then all buffers are shown.
1916 A large number or nil slows down menu responsiveness."
1917 :type '(choice integer
1918 (const :tag "All" nil))
1921 (defcustom buffers-menu-buffer-name-length 30
1922 "Maximum length of the buffer name on the Buffers menu.
1923 If this is a number, then buffer names are truncated to this length.
1924 If this is nil, then buffer names are shown in full.
1925 A large number or nil makes the menu too wide."
1926 :type '(choice integer
1927 (const :tag "Full length" nil))
1930 (defcustom buffers-menu-show-directories 'unless-uniquify
1931 "If non-nil, show directories in the Buffers menu for buffers that have them.
1932 The special value `unless-uniquify' means that directories will be shown
1933 unless `uniquify-buffer-name-style' is non-nil (in which case, buffer
1934 names should include enough of a buffer's directory to distinguish it
1935 from other buffers).
1937 Setting this variable directly does not take effect until next time the
1938 Buffers menu is regenerated."
1939 :set (lambda (symbol value)
1941 (menu-bar-update-buffers t))
1942 :initialize 'custom-initialize-default
1943 :type '(choice (const :tag "Never" nil)
1944 (const :tag "Unless uniquify is enabled" unless-uniquify)
1945 (const :tag "Always" t))
1948 (defcustom buffers-menu-show-status t
1949 "If non-nil, show modified/read-only status of buffers in the Buffers menu.
1950 Setting this variable directly does not take effect until next time the
1951 Buffers menu is regenerated."
1952 :set (lambda (symbol value)
1954 (menu-bar-update-buffers t))
1955 :initialize 'custom-initialize-default
1959 (defvar list-buffers-directory nil
1960 "String to display in buffer listings for buffers not visiting a file.")
1961 (make-variable-buffer-local 'list-buffers-directory)
1963 (defun menu-bar-select-buffer ()
1965 (switch-to-buffer last-command-event))
1967 (defun menu-bar-select-frame (frame)
1968 (make-frame-visible frame)
1970 (select-frame frame))
1972 (defun menu-bar-update-buffers-1 (elt)
1973 (let* ((buf (car elt))
1975 (and (if (eq buffers-menu-show-directories 'unless-uniquify)
1976 (or (not (boundp 'uniquify-buffer-name-style))
1977 (null uniquify-buffer-name-style))
1978 buffers-menu-show-directories)
1979 (or (buffer-file-name buf)
1980 (buffer-local-value 'list-buffers-directory buf)))))
1982 (setq file (file-name-directory file)))
1983 (when (and file (> (length file) 20))
1984 (setq file (concat "..." (substring file -17))))
1985 (cons (if buffers-menu-show-status
1986 (let ((mod (if (buffer-modified-p buf) "*" ""))
1987 (ro (if (buffer-local-value 'buffer-read-only buf) "%" "")))
1989 (format "%s %s%s -- %s" (cdr elt) mod ro file)
1990 (format "%s %s%s" (cdr elt) mod ro)))
1992 (format "%s -- %s" (cdr elt) file)
1996 ;; Used to cache the menu entries for commands in the Buffers menu
1997 (defvar menu-bar-buffers-menu-command-entries nil)
1999 (defvar menu-bar-select-buffer-function 'switch-to-buffer
2000 "Function to select the buffer chosen from the `Buffers' menu-bar menu.
2001 It must accept a buffer as its only required argument.")
2003 (defun menu-bar-update-buffers (&optional force)
2004 ;; If user discards the Buffers item, play along.
2005 (and (lookup-key (current-global-map) [menu-bar buffer])
2006 (or force (frame-or-buffer-changed-p))
2007 (let ((buffers (buffer-list))
2008 (frames (frame-list))
2010 ;; If requested, list only the N most recently selected buffers.
2011 (if (and (integerp buffers-menu-max-size)
2012 (> buffers-menu-max-size 1))
2013 (if (> (length buffers) buffers-menu-max-size)
2014 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
2016 ;; Make the menu of buffers proper.
2019 ;; Put into each element of buffer-list
2020 ;; the name for actual display,
2021 ;; perhaps truncated in the middle.
2022 (dolist (buf buffers)
2023 (let ((name (buffer-name buf)))
2024 (unless (eq ?\s (aref name 0))
2025 (push (menu-bar-update-buffers-1
2027 (if (and (integerp buffers-menu-buffer-name-length)
2028 (> (length name) buffers-menu-buffer-name-length))
2031 name 0 (/ buffers-menu-buffer-name-length 2))
2034 name (- (/ buffers-menu-buffer-name-length 2))))
2038 ;; Now make the actual list of items.
2039 (let ((buffers-vec (make-vector (length alist) nil))
2041 (dolist (pair alist)
2044 (nconc (list (car pair)
2048 (funcall menu-bar-select-buffer-function ,(cdr pair))))))
2049 (list buffers-vec))))
2051 ;; Make a Frames menu if we have more than one frame.
2053 (let* ((frames-vec (make-vector (length frames) nil))
2056 (list "Select Frame" frames-vec)))
2058 (dolist (frame frames)
2062 (frame-parameter frame 'name)
2065 (interactive) (menu-bar-select-frame ,frame))))
2067 ;; Put it after the normal buffers
2070 `((frames-separator "--")
2071 (frames menu-item "Frames" ,frames-menu))))))
2073 ;; Add in some normal commands at the end of the menu. We use
2074 ;; the copy cached in `menu-bar-buffers-menu-command-entries'
2075 ;; if it's been set already. Note that we can't use constant
2076 ;; lists for the menu-entries, because the low-level menu-code
2078 (unless menu-bar-buffers-menu-command-entries
2079 (setq menu-bar-buffers-menu-command-entries
2080 (list '(command-separator "--")
2085 :help "Switch to the \"next\" buffer in a cyclic order")
2086 (list 'previous-buffer
2090 :help "Switch to the \"previous\" buffer in a cyclic order")
2091 (list 'select-named-buffer
2093 "Select Named Buffer..."
2095 :help "Prompt for a buffer name, and select that buffer in the current window")
2096 (list 'list-all-buffers
2100 :help "Pop up a window listing all Emacs buffers"
2103 (nconc buffers-menu menu-bar-buffers-menu-command-entries))
2105 ;; We used to "(define-key (current-global-map) [menu-bar buffer]"
2106 ;; but that did not do the right thing when the [menu-bar buffer]
2107 ;; entry above had been moved (e.g. to a parent keymap).
2108 (setcdr global-buffers-menu-map (cons "Select Buffer" buffers-menu)))))
2110 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
2112 (menu-bar-update-buffers)
2114 ;; this version is too slow
2115 ;;(defun format-buffers-menu-line (buffer)
2116 ;; "Returns a string to represent the given buffer in the Buffer menu.
2117 ;;nil means the buffer shouldn't be listed. You can redefine this."
2118 ;; (if (string-match "\\` " (buffer-name buffer))
2120 ;; (with-current-buffer buffer
2121 ;; (let ((size (buffer-size)))
2122 ;; (format "%s%s %-19s %6s %-15s %s"
2123 ;; (if (buffer-modified-p) "*" " ")
2124 ;; (if buffer-read-only "%" " ")
2128 ;; (or (buffer-file-name) ""))))))
2130 ;;; Set up a menu bar menu for the minibuffer.
2132 (dolist (map (list minibuffer-local-map
2133 ;; This shouldn't be necessary, but there's a funny
2134 ;; bug in keymap.c that I don't understand yet. -stef
2135 minibuffer-local-completion-map))
2136 (define-key map [menu-bar minibuf]
2137 (cons (purecopy "Minibuf") (make-sparse-keymap "Minibuf"))))
2139 (let ((map minibuffer-local-completion-map))
2140 (define-key map [menu-bar minibuf ?\?]
2141 `(menu-item ,(purecopy "List Completions") minibuffer-completion-help
2142 :help ,(purecopy "Display all possible completions")))
2143 (define-key map [menu-bar minibuf space]
2144 `(menu-item ,(purecopy "Complete Word") minibuffer-complete-word
2145 :help ,(purecopy "Complete at most one word")))
2146 (define-key map [menu-bar minibuf tab]
2147 `(menu-item ,(purecopy "Complete") minibuffer-complete
2148 :help ,(purecopy "Complete as far as possible"))))
2150 (let ((map minibuffer-local-map))
2151 (define-key map [menu-bar minibuf quit]
2152 `(menu-item ,(purecopy "Quit") abort-recursive-edit
2153 :help ,(purecopy "Abort input and exit minibuffer")))
2154 (define-key map [menu-bar minibuf return]
2155 `(menu-item ,(purecopy "Enter") exit-minibuffer
2156 :key-sequence ,(purecopy "\r")
2157 :help ,(purecopy "Terminate input and exit minibuffer")))
2158 (define-key map [menu-bar minibuf isearch-forward]
2159 `(menu-item ,(purecopy "Isearch History Forward") isearch-forward
2160 :help ,(purecopy "Incrementally search minibuffer history forward")))
2161 (define-key map [menu-bar minibuf isearch-backward]
2162 `(menu-item ,(purecopy "Isearch History Backward") isearch-backward
2163 :help ,(purecopy "Incrementally search minibuffer history backward")))
2164 (define-key map [menu-bar minibuf next]
2165 `(menu-item ,(purecopy "Next History Item") next-history-element
2166 :help ,(purecopy "Put next minibuffer history element in the minibuffer")))
2167 (define-key map [menu-bar minibuf previous]
2168 `(menu-item ,(purecopy "Previous History Item") previous-history-element
2169 :help ,(purecopy "Put previous minibuffer history element in the minibuffer"))))
2171 (define-minor-mode menu-bar-mode
2172 "Toggle display of a menu bar on each frame (Menu Bar mode).
2173 With a prefix argument ARG, enable Menu Bar mode if ARG is
2174 positive, and disable it otherwise. If called from Lisp, enable
2175 Menu Bar mode if ARG is omitted or nil.
2177 This command applies to all frames that exist and frames to be
2178 created in the future."
2181 ;; It's defined in C/cus-start, this stops the d-m-m macro defining it again.
2182 :variable menu-bar-mode
2184 ;; Turn the menu-bars on all frames on or off.
2185 (let ((val (if menu-bar-mode 1 0)))
2186 (dolist (frame (frame-list))
2187 (set-frame-parameter frame 'menu-bar-lines val))
2188 ;; If the user has given `default-frame-alist' a `menu-bar-lines'
2189 ;; parameter, replace it.
2190 (if (assq 'menu-bar-lines default-frame-alist)
2191 (setq default-frame-alist
2192 (cons (cons 'menu-bar-lines val)
2193 (assq-delete-all 'menu-bar-lines
2194 default-frame-alist)))))
2195 ;; Make the message appear when Emacs is idle. We can not call message
2196 ;; directly. The minor-mode message "Menu-bar mode disabled" comes
2197 ;; after this function returns, overwriting any message we do here.
2198 (when (and (called-interactively-p 'interactive) (not menu-bar-mode))
2199 (run-with-idle-timer 0 nil 'message
2200 "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear.")))
2203 ;; (This does not work right unless it comes after the above definition.)
2204 ;; This comment is taken from tool-bar.el near
2205 ;; (put 'tool-bar-mode ...)
2206 ;; We want to pretend the menu bar by standard is on, as this will make
2207 ;; customize consider disabling the menu bar a customization, and save
2208 ;; that. We could do this for real by setting :init-value above, but
2209 ;; that would overwrite disabling the menu bar from X resources.
2210 (put 'menu-bar-mode 'standard-value '(t))
2212 (defun toggle-menu-bar-mode-from-frame (&optional arg)
2213 "Toggle menu bar on or off, based on the status of the current frame.
2214 See `menu-bar-mode' for more information."
2215 (interactive (list (or current-prefix-arg 'toggle)))
2216 (if (eq arg 'toggle)
2218 (if (menu-bar-positive-p
2219 (frame-parameter (menu-bar-frame-for-menubar) 'menu-bar-lines))
2221 (menu-bar-mode arg)))
2223 (declare-function x-menu-bar-open "term/x-win" (&optional frame))
2224 (declare-function w32-menu-bar-open "term/w32-win" (&optional frame))
2226 (defun menu-bar-open (&optional frame)
2227 "Start key navigation of the menu bar in FRAME.
2229 This function decides which method to use to access the menu
2230 depending on FRAME's terminal device. On X displays, it calls
2231 `x-menu-bar-open'; on Windows, `w32-menu-bar-open' otherwise it
2232 calls `tmm-menubar'.
2234 If FRAME is nil or not given, use the selected frame."
2236 (let ((type (framep (or frame (selected-frame)))))
2238 ((eq type 'x) (x-menu-bar-open frame))
2239 ((eq type 'w32) (w32-menu-bar-open frame))
2240 (t (with-selected-frame (or frame (selected-frame))
2243 (global-set-key [f10] 'menu-bar-open)
2247 ;;; menu-bar.el ends here