1 ;;; menu-bar.el --- define a default menu bar
3 ;; Copyright (C) 1993-1995, 2000-2012 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 platform 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 (set-frame-font (if (fboundp 'x-select-font)
691 (defun menu-bar-options-save ()
692 "Save current values of Options menu items using Custom."
694 (let ((need-save nil))
695 ;; These are set with menu-bar-make-mm-toggle, which does not
696 ;; put on a customized-value property.
697 (dolist (elt '(line-number-mode column-number-mode size-indication-mode
698 cua-mode show-paren-mode transient-mark-mode
699 blink-cursor-mode display-time-mode display-battery-mode
700 ;; These are set by other functions that don't set
701 ;; the customized state. Having them here has the
702 ;; side-effect that turning them off via X
703 ;; resources acts like having customized them, but
704 ;; that seems harmless.
705 menu-bar-mode tool-bar-mode))
706 ;; FIXME ? It's a little annoying that running this command
707 ;; always loads cua-base, paren, time, and battery, even if they
708 ;; have not been customized in any way. (Due to custom-load-symbol.)
709 (and (customize-mark-to-save elt)
711 ;; These are set with `customize-set-variable'.
712 (dolist (elt '(scroll-bar-mode
713 debug-on-quit debug-on-error
714 ;; Somehow this works, when tool-bar and menu-bar don't.
716 save-place uniquify-buffer-name-style fringe-mode
717 indicate-empty-lines indicate-buffer-boundaries
718 case-fold-search font-use-system-font
719 current-language-environment default-input-method
720 ;; Saving `text-mode-hook' is somewhat questionable,
721 ;; as we might get more than we bargain for, if
722 ;; other code may has added hooks as well.
723 ;; Nonetheless, not saving it would like be confuse
725 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
726 text-mode-hook tool-bar-position))
727 (and (get elt 'customized-value)
728 (customize-mark-to-save elt)
730 (when (get 'default 'customized-face)
731 (put 'default 'saved-face (get 'default 'customized-face))
732 (put 'default 'customized-face nil)
734 ;; Save if we changed anything.
739 ;;; Assemble all the top-level items of the "Options" menu
741 ;; The "Show/Hide" submenu of menu "Options"
743 (defun menu-bar-showhide-fringe-ind-customize ()
744 "Show customization buffer for `indicate-buffer-boundaries'."
746 (customize-variable 'indicate-buffer-boundaries))
748 (defun menu-bar-showhide-fringe-ind-mixed ()
749 "Display top and bottom indicators in opposite fringes, arrows in right."
751 (customize-set-variable 'indicate-buffer-boundaries
752 '((t . right) (top . left))))
754 (defun menu-bar-showhide-fringe-ind-box ()
755 "Display top and bottom indicators in opposite fringes."
757 (customize-set-variable 'indicate-buffer-boundaries
758 '((top . left) (bottom . right))))
760 (defun menu-bar-showhide-fringe-ind-right ()
761 "Display buffer boundaries and arrows in the right fringe."
763 (customize-set-variable 'indicate-buffer-boundaries 'right))
765 (defun menu-bar-showhide-fringe-ind-left ()
766 "Display buffer boundaries and arrows in the left fringe."
768 (customize-set-variable 'indicate-buffer-boundaries 'left))
770 (defun menu-bar-showhide-fringe-ind-none ()
771 "Do not display any buffer boundary indicators."
773 (customize-set-variable 'indicate-buffer-boundaries nil))
775 (defvar menu-bar-showhide-fringe-ind-menu
776 (let ((menu (make-sparse-keymap "Buffer boundaries")))
778 (define-key menu [customize]
779 `(menu-item ,(purecopy "Other (Customize)")
780 menu-bar-showhide-fringe-ind-customize
781 :help ,(purecopy "Additional choices available through Custom buffer")
782 :visible (display-graphic-p)
783 :button (:radio . (not (member indicate-buffer-boundaries
785 ((top . left) (bottom . right))
786 ((t . right) (top . left))))))))
788 (define-key menu [mixed]
789 `(menu-item ,(purecopy "Opposite, Arrows Right") menu-bar-showhide-fringe-ind-mixed
791 ,(purecopy "Show top/bottom indicators in opposite fringes, arrows in right")
792 :visible (display-graphic-p)
793 :button (:radio . (equal indicate-buffer-boundaries
794 '((t . right) (top . left))))))
796 (define-key menu [box]
797 `(menu-item ,(purecopy "Opposite, No Arrows") menu-bar-showhide-fringe-ind-box
798 :help ,(purecopy "Show top/bottom indicators in opposite fringes, no arrows")
799 :visible (display-graphic-p)
800 :button (:radio . (equal indicate-buffer-boundaries
801 '((top . left) (bottom . right))))))
803 (define-key menu [right]
804 `(menu-item ,(purecopy "In Right Fringe") menu-bar-showhide-fringe-ind-right
805 :help ,(purecopy "Show buffer boundaries and arrows in right fringe")
806 :visible (display-graphic-p)
807 :button (:radio . (eq indicate-buffer-boundaries 'right))))
809 (define-key menu [left]
810 `(menu-item ,(purecopy "In Left Fringe") menu-bar-showhide-fringe-ind-left
811 :help ,(purecopy "Show buffer boundaries and arrows in left fringe")
812 :visible (display-graphic-p)
813 :button (:radio . (eq indicate-buffer-boundaries 'left))))
815 (define-key menu [none]
816 `(menu-item ,(purecopy "No Indicators") menu-bar-showhide-fringe-ind-none
817 :help ,(purecopy "Hide all buffer boundary indicators and arrows")
818 :visible (display-graphic-p)
819 :button (:radio . (eq indicate-buffer-boundaries nil))))
822 (defun menu-bar-showhide-fringe-menu-customize ()
823 "Show customization buffer for `fringe-mode'."
825 (customize-variable 'fringe-mode))
827 (defun menu-bar-showhide-fringe-menu-customize-reset ()
828 "Reset the fringe mode: display fringes on both sides of a window."
830 (customize-set-variable 'fringe-mode nil))
832 (defun menu-bar-showhide-fringe-menu-customize-right ()
833 "Display fringes only on the right of each window."
836 (customize-set-variable 'fringe-mode '(0 . nil)))
838 (defun menu-bar-showhide-fringe-menu-customize-left ()
839 "Display fringes only on the left of each window."
842 (customize-set-variable 'fringe-mode '(nil . 0)))
844 (defun menu-bar-showhide-fringe-menu-customize-disable ()
845 "Do not display window fringes."
848 (customize-set-variable 'fringe-mode 0))
850 (defvar menu-bar-showhide-fringe-menu
851 (let ((menu (make-sparse-keymap "Fringe")))
853 (define-key menu [showhide-fringe-ind]
854 `(menu-item ,(purecopy "Buffer Boundaries") ,menu-bar-showhide-fringe-ind-menu
855 :visible (display-graphic-p)
856 :help ,(purecopy "Indicate buffer boundaries in fringe")))
858 (define-key menu [indicate-empty-lines]
859 (menu-bar-make-toggle toggle-indicate-empty-lines indicate-empty-lines
860 "Empty Line Indicators"
861 "Indicating of empty lines %s"
862 "Indicate trailing empty lines in fringe, globally"))
864 (define-key menu [customize]
865 `(menu-item ,(purecopy "Customize Fringe") menu-bar-showhide-fringe-menu-customize
866 :help ,(purecopy "Detailed customization of fringe")
867 :visible (display-graphic-p)))
869 (define-key menu [default]
870 `(menu-item ,(purecopy "Default") menu-bar-showhide-fringe-menu-customize-reset
871 :help ,(purecopy "Default width fringe on both left and right side")
872 :visible (display-graphic-p)
873 :button (:radio . (eq fringe-mode nil))))
875 (define-key menu [right]
876 `(menu-item ,(purecopy "On the Right") menu-bar-showhide-fringe-menu-customize-right
877 :help ,(purecopy "Fringe only on the right side")
878 :visible (display-graphic-p)
879 :button (:radio . (equal fringe-mode '(0 . nil)))))
881 (define-key menu [left]
882 `(menu-item ,(purecopy "On the Left") menu-bar-showhide-fringe-menu-customize-left
883 :help ,(purecopy "Fringe only on the left side")
884 :visible (display-graphic-p)
885 :button (:radio . (equal fringe-mode '(nil . 0)))))
887 (define-key menu [none]
888 `(menu-item ,(purecopy "None") menu-bar-showhide-fringe-menu-customize-disable
889 :help ,(purecopy "Turn off fringe")
890 :visible (display-graphic-p)
891 :button (:radio . (eq fringe-mode 0))))
894 (defun menu-bar-right-scroll-bar ()
895 "Display scroll bars on the right of each window."
897 (customize-set-variable 'scroll-bar-mode 'right))
899 (defun menu-bar-left-scroll-bar ()
900 "Display scroll bars on the left of each window."
902 (customize-set-variable 'scroll-bar-mode 'left))
904 (defun menu-bar-no-scroll-bar ()
905 "Turn off scroll bars."
907 (customize-set-variable 'scroll-bar-mode nil))
909 (defvar menu-bar-showhide-scroll-bar-menu
910 (let ((menu (make-sparse-keymap "Scroll-bar")))
912 (define-key menu [right]
913 `(menu-item ,(purecopy "On the Right")
914 menu-bar-right-scroll-bar
915 :help ,(purecopy "Scroll-bar on the right side")
916 :visible (display-graphic-p)
917 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
918 (frame-parameters))) 'right))))
920 (define-key menu [left]
921 `(menu-item ,(purecopy "On the Left")
922 menu-bar-left-scroll-bar
923 :help ,(purecopy "Scroll-bar on the left side")
924 :visible (display-graphic-p)
925 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
926 (frame-parameters))) 'left))))
928 (define-key menu [none]
929 `(menu-item ,(purecopy "None")
930 menu-bar-no-scroll-bar
931 :help ,(purecopy "Turn off scroll-bar")
932 :visible (display-graphic-p)
933 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
934 (frame-parameters))) nil))))
937 (defun menu-bar-frame-for-menubar ()
938 "Return the frame suitable for updating the menu bar."
939 (or (and (framep menu-updating-frame)
943 (defun menu-bar-positive-p (val)
944 "Return non-nil iff VAL is a positive number."
948 (defun menu-bar-set-tool-bar-position (position)
949 (customize-set-variable 'tool-bar-mode t)
950 (customize-set-variable 'tool-bar-position position))
951 (defun menu-bar-showhide-tool-bar-menu-customize-disable ()
952 "Do not display tool bars."
954 (customize-set-variable 'tool-bar-mode nil))
955 (defun menu-bar-showhide-tool-bar-menu-customize-enable-left ()
956 "Display tool bars on the left side."
958 (menu-bar-set-tool-bar-position 'left))
959 (defun menu-bar-showhide-tool-bar-menu-customize-enable-right ()
960 "Display tool bars on the right side."
962 (menu-bar-set-tool-bar-position 'right))
963 (defun menu-bar-showhide-tool-bar-menu-customize-enable-top ()
964 "Display tool bars on the top side."
966 (menu-bar-set-tool-bar-position 'top))
967 (defun menu-bar-showhide-tool-bar-menu-customize-enable-bottom ()
968 "Display tool bars on the bottom side."
970 (menu-bar-set-tool-bar-position 'bottom))
972 (when (featurep 'move-toolbar)
973 (defvar menu-bar-showhide-tool-bar-menu
974 (let ((menu (make-sparse-keymap "Tool-bar")))
976 (define-key menu [showhide-tool-bar-left]
977 `(menu-item ,(purecopy "On the Left")
978 menu-bar-showhide-tool-bar-menu-customize-enable-left
979 :help ,(purecopy "Tool-bar at the left side")
980 :visible (display-graphic-p)
982 (:radio . (and tool-bar-mode
984 (menu-bar-frame-for-menubar)
988 (define-key menu [showhide-tool-bar-right]
989 `(menu-item ,(purecopy "On the Right")
990 menu-bar-showhide-tool-bar-menu-customize-enable-right
991 :help ,(purecopy "Tool-bar at the right side")
992 :visible (display-graphic-p)
994 (:radio . (and tool-bar-mode
996 (menu-bar-frame-for-menubar)
1000 (define-key menu [showhide-tool-bar-bottom]
1001 `(menu-item ,(purecopy "On the Bottom")
1002 menu-bar-showhide-tool-bar-menu-customize-enable-bottom
1003 :help ,(purecopy "Tool-bar at the bottom")
1004 :visible (display-graphic-p)
1006 (:radio . (and tool-bar-mode
1007 (eq (frame-parameter
1008 (menu-bar-frame-for-menubar)
1012 (define-key menu [showhide-tool-bar-top]
1013 `(menu-item ,(purecopy "On the Top")
1014 menu-bar-showhide-tool-bar-menu-customize-enable-top
1015 :help ,(purecopy "Tool-bar at the top")
1016 :visible (display-graphic-p)
1018 (:radio . (and tool-bar-mode
1019 (eq (frame-parameter
1020 (menu-bar-frame-for-menubar)
1024 (define-key menu [showhide-tool-bar-none]
1025 `(menu-item ,(purecopy "None")
1026 menu-bar-showhide-tool-bar-menu-customize-disable
1027 :help ,(purecopy "Turn tool-bar off")
1028 :visible (display-graphic-p)
1029 :button (:radio . (eq tool-bar-mode nil))))
1032 (defvar menu-bar-showhide-menu
1033 (let ((menu (make-sparse-keymap "Show/Hide")))
1035 (define-key menu [column-number-mode]
1036 (menu-bar-make-mm-toggle column-number-mode
1038 "Show the current column number in the mode line"))
1040 (define-key menu [line-number-mode]
1041 (menu-bar-make-mm-toggle line-number-mode
1043 "Show the current line number in the mode line"))
1045 (define-key menu [size-indication-mode]
1046 (menu-bar-make-mm-toggle size-indication-mode
1048 "Show the size of the buffer in the mode line"))
1050 (define-key menu [linecolumn-separator]
1053 (define-key menu [showhide-battery]
1054 (menu-bar-make-mm-toggle display-battery-mode
1056 "Display battery status information in mode line"))
1058 (define-key menu [showhide-date-time]
1059 (menu-bar-make-mm-toggle display-time-mode
1060 "Time, Load and Mail"
1061 "Display time, system load averages and \
1062 mail status in mode line"))
1064 (define-key menu [datetime-separator]
1067 (define-key menu [showhide-speedbar]
1068 `(menu-item ,(purecopy "Speedbar") speedbar-frame-mode
1069 :help ,(purecopy "Display a Speedbar quick-navigation frame")
1071 . (and (boundp 'speedbar-frame)
1072 (frame-live-p (symbol-value 'speedbar-frame))
1074 (symbol-value 'speedbar-frame))))))
1076 (define-key menu [showhide-fringe]
1077 `(menu-item ,(purecopy "Fringe") ,menu-bar-showhide-fringe-menu
1078 :visible (display-graphic-p)))
1080 (define-key menu [showhide-scroll-bar]
1081 `(menu-item ,(purecopy "Scroll-bar") ,menu-bar-showhide-scroll-bar-menu
1082 :visible (display-graphic-p)))
1084 (define-key menu [showhide-tooltip-mode]
1085 `(menu-item ,(purecopy "Tooltips") tooltip-mode
1086 :help ,(purecopy "Turn tooltips on/off")
1087 :visible (and (display-graphic-p) (fboundp 'x-show-tip))
1088 :button (:toggle . tooltip-mode)))
1090 (define-key menu [menu-bar-mode]
1091 `(menu-item ,(purecopy "Menu-bar") toggle-menu-bar-mode-from-frame
1092 :help ,(purecopy "Turn menu-bar on/off")
1094 (:toggle . (menu-bar-positive-p
1095 (frame-parameter (menu-bar-frame-for-menubar)
1096 'menu-bar-lines)))))
1098 (if (and (boundp 'menu-bar-showhide-tool-bar-menu)
1099 (keymapp menu-bar-showhide-tool-bar-menu))
1100 (define-key menu [showhide-tool-bar]
1101 `(menu-item ,(purecopy "Tool-bar") ,menu-bar-showhide-tool-bar-menu
1102 :visible (display-graphic-p)))
1103 ;; else not tool bar that can move.
1104 (define-key menu [showhide-tool-bar]
1105 `(menu-item ,(purecopy "Tool-bar") toggle-tool-bar-mode-from-frame
1106 :help ,(purecopy "Turn tool-bar on/off")
1107 :visible (display-graphic-p)
1109 (:toggle . (menu-bar-positive-p
1110 (frame-parameter (menu-bar-frame-for-menubar)
1111 'tool-bar-lines))))))
1114 (defun menu-bar-text-mode-auto-fill ()
1116 (toggle-text-mode-auto-fill)
1117 ;; This is somewhat questionable, as `text-mode-hook'
1118 ;; might have changed outside customize.
1119 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
1120 (customize-mark-as-set 'text-mode-hook))
1123 (defvar menu-bar-line-wrapping-menu
1124 (let ((menu (make-sparse-keymap "Line Wrapping")))
1126 (define-key menu [word-wrap]
1128 ,(purecopy "Word Wrap (Visual Line mode)")
1131 (unless visual-line-mode
1132 (visual-line-mode 1))
1133 (message ,(purecopy "Visual-Line mode enabled")))
1134 :help ,(purecopy "Wrap long lines at word boundaries")
1135 :button (:radio . (and (null truncate-lines)
1136 (not (truncated-partial-width-window-p))
1138 :visible (menu-bar-menu-frame-live-and-visible-p)))
1140 (define-key menu [truncate]
1141 `(menu-item ,(purecopy "Truncate Long Lines")
1144 (if visual-line-mode (visual-line-mode 0))
1145 (setq word-wrap nil)
1146 (toggle-truncate-lines 1))
1147 :help ,(purecopy "Truncate long lines at window edge")
1148 :button (:radio . (or truncate-lines
1149 (truncated-partial-width-window-p)))
1150 :visible (menu-bar-menu-frame-live-and-visible-p)
1151 :enable (not (truncated-partial-width-window-p))))
1153 (define-key menu [window-wrap]
1154 `(menu-item ,(purecopy "Wrap at Window Edge")
1155 (lambda () (interactive)
1156 (if visual-line-mode (visual-line-mode 0))
1157 (setq word-wrap nil)
1158 (if truncate-lines (toggle-truncate-lines -1)))
1159 :help ,(purecopy "Wrap long lines at window edge")
1160 :button (:radio . (and (null truncate-lines)
1161 (not (truncated-partial-width-window-p))
1163 :visible (menu-bar-menu-frame-live-and-visible-p)
1164 :enable (not (truncated-partial-width-window-p))))
1167 (defvar menu-bar-options-menu
1168 (let ((menu (make-sparse-keymap "Options")))
1169 (define-key menu [customize]
1170 `(menu-item ,(purecopy "Customize Emacs") ,menu-bar-custom-menu))
1172 (define-key menu [package]
1173 '(menu-item "Manage Emacs Packages" package-list-packages
1174 :help "Install or uninstall additional Emacs packages"))
1176 (define-key menu [save]
1177 `(menu-item ,(purecopy "Save Options") menu-bar-options-save
1178 :help ,(purecopy "Save options set from the menu above")))
1180 (define-key menu [custom-separator]
1183 (define-key menu [menu-set-font]
1184 `(menu-item ,(purecopy "Set Default Font...") menu-set-font
1185 :visible (display-multi-font-p)
1186 :help ,(purecopy "Select a default font")))
1188 (if (featurep 'system-font-setting)
1189 (define-key menu [menu-system-font]
1190 (menu-bar-make-toggle
1191 toggle-use-system-font font-use-system-font
1193 "Use system font: %s"
1194 "Use the monospaced font defined by the system")))
1196 (define-key menu [showhide]
1197 `(menu-item ,(purecopy "Show/Hide") ,menu-bar-showhide-menu))
1199 (define-key menu [showhide-separator]
1202 (define-key menu [mule]
1203 ;; It is better not to use backquote here,
1204 ;; because that makes a bootstrapping problem
1205 ;; if you need to recompile all the Lisp files using interpreted code.
1206 `(menu-item ,(purecopy "Multilingual Environment") ,mule-menu-keymap
1207 ;; Most of the MULE menu actually does make sense in
1208 ;; unibyte mode, e.g. language selection.
1209 ;; :visible '(default-value 'enable-multibyte-characters)
1211 ;;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
1212 ;;(define-key menu [preferences]
1213 ;; `(menu-item ,(purecopy "Preferences") ,menu-bar-preferences-menu
1214 ;; :help ,(purecopy "Toggle important global options")))
1216 (define-key menu [mule-separator]
1219 (define-key menu [debug-on-quit]
1220 (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
1221 "Enter Debugger on Quit/C-g" "Debug on Quit %s"
1222 "Enter Lisp debugger when C-g is pressed"))
1223 (define-key menu [debug-on-error]
1224 (menu-bar-make-toggle toggle-debug-on-error debug-on-error
1225 "Enter Debugger on Error" "Debug on Error %s"
1226 "Enter Lisp debugger when an error is signaled"))
1227 (define-key menu [debugger-separator]
1230 (define-key menu [blink-cursor-mode]
1231 (menu-bar-make-mm-toggle
1234 "Whether the cursor blinks (Blink Cursor mode)"))
1235 (define-key menu [cursor-separator]
1238 (define-key menu [save-place]
1239 (menu-bar-make-toggle
1240 toggle-save-place-globally save-place
1241 "Save Place in Files between Sessions"
1242 "Saving place in files %s"
1243 "Visit files of previous session when restarting Emacs"
1244 (require 'saveplace)
1245 ;; Do it by name, to avoid a free-variable
1246 ;; warning during byte compilation.
1248 'save-place (not (symbol-value 'save-place)))))
1250 (define-key menu [uniquify]
1251 (menu-bar-make-toggle
1252 toggle-uniquify-buffer-names uniquify-buffer-name-style
1253 "Use Directory Names in Buffer Names"
1254 "Directory name in buffer names (uniquify) %s"
1255 "Uniquify buffer names by adding parent directory names"
1257 (setq uniquify-buffer-name-style
1258 (if (not uniquify-buffer-name-style)
1261 (define-key menu [edit-options-separator]
1263 (define-key menu [cua-mode]
1264 (menu-bar-make-mm-toggle
1266 "Use CUA Keys (Cut/Paste with C-x/C-c/C-v)"
1267 "Use C-z/C-x/C-c/C-v keys for undo/cut/copy/paste"
1268 (:visible (or (not (boundp 'cua-enable-cua-keys))
1269 cua-enable-cua-keys))))
1271 (define-key menu [cua-emulation-mode]
1272 (menu-bar-make-mm-toggle
1274 "Shift movement mark region (CUA)"
1275 "Use shifted movement keys to set and extend the region"
1276 (:visible (and (boundp 'cua-enable-cua-keys)
1277 (not cua-enable-cua-keys)))))
1279 (define-key menu [case-fold-search]
1280 (menu-bar-make-toggle
1281 toggle-case-fold-search case-fold-search
1282 "Ignore Case for Search"
1283 "Case-Insensitive Search %s"
1284 "Ignore letter-case in search commands"))
1286 (define-key menu [auto-fill-mode]
1288 ,(purecopy "Auto Fill in Text Modes")
1289 menu-bar-text-mode-auto-fill
1290 :help ,(purecopy "Automatically fill text while typing (Auto Fill mode)")
1291 :button (:toggle . (if (listp text-mode-hook)
1292 (member 'turn-on-auto-fill text-mode-hook)
1293 (eq 'turn-on-auto-fill text-mode-hook)))))
1295 (define-key menu [line-wrapping]
1296 `(menu-item ,(purecopy "Line Wrapping in This Buffer")
1297 ,menu-bar-line-wrapping-menu))
1300 (define-key menu [highlight-separator]
1302 (define-key menu [highlight-paren-mode]
1303 (menu-bar-make-mm-toggle
1305 "Highlight Matching Parentheses"
1306 "Highlight matching/mismatched parentheses at cursor (Show Paren mode)"))
1307 (define-key menu [transient-mark-mode]
1308 (menu-bar-make-mm-toggle
1310 "Highlight Active Region"
1311 "Make text in active region stand out in color (Transient Mark mode)"
1312 (:enable (not cua-mode))))
1316 ;; The "Tools" menu items
1318 (defun send-mail-item-name ()
1319 (let* ((known-send-mail-commands '((sendmail-user-agent . "sendmail")
1320 (mh-e-user-agent . "MH")
1321 (message-user-agent . "Gnus Message")
1322 (gnus-user-agent . "Gnus")))
1323 (name (assq mail-user-agent known-send-mail-commands)))
1325 (setq name (cdr name))
1326 (setq name (symbol-name mail-user-agent))
1327 (if (string-match "\\(.+\\)-user-agent" name)
1328 (setq name (match-string 1 name))))
1331 (defun read-mail-item-name ()
1332 (let* ((known-rmail-commands '((rmail . "RMAIL")
1335 (known (assq read-mail-command known-rmail-commands)))
1336 (if known (cdr known) (symbol-name read-mail-command))))
1338 (defvar menu-bar-games-menu
1339 (let ((menu (make-sparse-keymap "Games")))
1341 (define-key menu [zone]
1342 `(menu-item ,(purecopy "Zone Out") zone
1343 :help ,(purecopy "Play tricks with Emacs display when Emacs is idle")))
1344 (define-key menu [tetris]
1345 `(menu-item ,(purecopy "Tetris") tetris
1346 :help ,(purecopy "Falling blocks game")))
1347 (define-key menu [solitaire]
1348 `(menu-item ,(purecopy "Solitaire") solitaire
1349 :help ,(purecopy "Get rid of all the stones")))
1350 (define-key menu [snake]
1351 `(menu-item ,(purecopy "Snake") snake
1352 :help ,(purecopy "Move snake around avoiding collisions")))
1353 (define-key menu [pong]
1354 `(menu-item ,(purecopy "Pong") pong
1355 :help ,(purecopy "Bounce the ball to your opponent")))
1356 (define-key menu [mult]
1357 `(menu-item ,(purecopy "Multiplication Puzzle") mpuz
1358 :help ,(purecopy "Exercise brain with multiplication")))
1359 (define-key menu [life]
1360 `(menu-item ,(purecopy "Life") life
1361 :help ,(purecopy "Watch how John Conway's cellular automaton evolves")))
1362 (define-key menu [land]
1363 `(menu-item ,(purecopy "Landmark") landmark
1364 :help ,(purecopy "Watch a neural-network robot learn landmarks")))
1365 (define-key menu [hanoi]
1366 `(menu-item ,(purecopy "Towers of Hanoi") hanoi
1367 :help ,(purecopy "Watch Towers-of-Hanoi puzzle solved by Emacs")))
1368 (define-key menu [gomoku]
1369 `(menu-item ,(purecopy "Gomoku") gomoku
1370 :help ,(purecopy "Mark 5 contiguous squares (like tic-tac-toe)")))
1371 (define-key menu [bubbles]
1372 `(menu-item ,(purecopy "Bubbles") bubbles
1373 :help ,(purecopy "Remove all bubbles using the fewest moves")))
1374 (define-key menu [black-box]
1375 `(menu-item ,(purecopy "Blackbox") blackbox
1376 :help ,(purecopy "Find balls in a black box by shooting rays")))
1377 (define-key menu [adventure]
1378 `(menu-item ,(purecopy "Adventure") dunnet
1379 :help ,(purecopy "Dunnet, a text Adventure game for Emacs")))
1380 (define-key menu [5x5]
1381 `(menu-item ,(purecopy "5x5") 5x5
1382 :help ,(purecopy "Fill in all the squares on a 5x5 board")))
1385 (defvar menu-bar-encryption-decryption-menu
1386 (let ((menu (make-sparse-keymap "Encryption/Decryption")))
1387 (define-key menu [insert-keys]
1388 `(menu-item ,(purecopy "Insert Keys") epa-insert-keys
1389 :help ,(purecopy "Insert public keys after the current point")))
1391 (define-key menu [export-keys]
1392 `(menu-item ,(purecopy "Export Keys") epa-export-keys
1393 :help ,(purecopy "Export public keys to a file")))
1395 (define-key menu [import-keys-region]
1396 `(menu-item ,(purecopy "Import Keys from Region") epa-import-keys-region
1397 :help ,(purecopy "Import public keys from the current region")))
1399 (define-key menu [import-keys]
1400 `(menu-item ,(purecopy "Import Keys from File...") epa-import-keys
1401 :help ,(purecopy "Import public keys from a file")))
1403 (define-key menu [list-keys]
1404 `(menu-item ,(purecopy "List Keys") epa-list-keys
1405 :help ,(purecopy "Browse your public keyring")))
1407 (define-key menu [separator-keys]
1410 (define-key menu [sign-region]
1411 `(menu-item ,(purecopy "Sign Region") epa-sign-region
1412 :help ,(purecopy "Create digital signature of the current region")))
1414 (define-key menu [verify-region]
1415 `(menu-item ,(purecopy "Verify Region") epa-verify-region
1416 :help ,(purecopy "Verify digital signature of the current region")))
1418 (define-key menu [encrypt-region]
1419 `(menu-item ,(purecopy "Encrypt Region") epa-encrypt-region
1420 :help ,(purecopy "Encrypt the current region")))
1422 (define-key menu [decrypt-region]
1423 `(menu-item ,(purecopy "Decrypt Region") epa-decrypt-region
1424 :help ,(purecopy "Decrypt the current region")))
1426 (define-key menu [separator-file]
1429 (define-key menu [sign-file]
1430 `(menu-item ,(purecopy "Sign File...") epa-sign-file
1431 :help ,(purecopy "Create digital signature of a file")))
1433 (define-key menu [verify-file]
1434 `(menu-item ,(purecopy "Verify File...") epa-verify-file
1435 :help ,(purecopy "Verify digital signature of a file")))
1437 (define-key menu [encrypt-file]
1438 `(menu-item ,(purecopy "Encrypt File...") epa-encrypt-file
1439 :help ,(purecopy "Encrypt a file")))
1441 (define-key menu [decrypt-file]
1442 `(menu-item ,(purecopy "Decrypt File...") epa-decrypt-file
1443 :help ,(purecopy "Decrypt a file")))
1447 (defun menu-bar-read-mail ()
1448 "Read mail using `read-mail-command'."
1450 (call-interactively read-mail-command))
1452 (defvar menu-bar-tools-menu
1453 (let ((menu (make-sparse-keymap "Tools")))
1455 (define-key menu [games]
1456 `(menu-item ,(purecopy "Games") ,menu-bar-games-menu))
1458 (define-key menu [separator-games]
1461 (define-key menu [encryption-decryption]
1462 `(menu-item ,(purecopy "Encryption/Decryption") ,menu-bar-encryption-decryption-menu))
1464 (define-key menu [separator-encryption-decryption]
1467 (define-key menu [simple-calculator]
1468 `(menu-item ,(purecopy "Simple Calculator") calculator
1469 :help ,(purecopy "Invoke the Emacs built-in quick calculator")))
1470 (define-key menu [calc]
1471 `(menu-item ,(purecopy "Programmable Calculator") calc
1472 :help ,(purecopy "Invoke the Emacs built-in full scientific calculator")))
1473 (define-key menu [calendar]
1474 `(menu-item ,(purecopy "Calendar") calendar
1475 :help ,(purecopy "Invoke the Emacs built-in calendar")))
1477 (define-key menu [separator-net]
1480 (define-key menu [directory-search]
1481 `(menu-item ,(purecopy "Directory Search") eudc-tools-menu))
1482 (define-key menu [compose-mail]
1483 `(menu-item (format "Send Mail (with %s)" (send-mail-item-name)) compose-mail
1484 :visible (and mail-user-agent (not (eq mail-user-agent 'ignore)))
1485 :help ,(purecopy "Send a mail message")))
1486 (define-key menu [rmail]
1487 `(menu-item (format "Read Mail (with %s)" (read-mail-item-name))
1489 :visible (and read-mail-command
1490 (not (eq read-mail-command 'ignore)))
1491 :help ,(purecopy "Read your mail and reply to it")))
1493 (define-key menu [gnus]
1494 `(menu-item ,(purecopy "Read Net News (Gnus)") gnus
1495 :help ,(purecopy "Read network news groups")))
1497 (define-key menu [separator-vc]
1500 (define-key menu [pcl-cvs]
1501 `(menu-item ,(purecopy "PCL-CVS") cvs-global-menu))
1502 (define-key menu [vc] nil) ;Create the place for the VC menu.
1504 (define-key menu [separator-compare]
1507 (define-key menu [epatch]
1508 `(menu-item ,(purecopy "Apply Patch") menu-bar-epatch-menu))
1509 (define-key menu [ediff-merge]
1510 `(menu-item ,(purecopy "Merge") menu-bar-ediff-merge-menu))
1511 (define-key menu [compare]
1512 `(menu-item ,(purecopy "Compare (Ediff)") menu-bar-ediff-menu))
1514 (define-key menu [separator-spell]
1517 (define-key menu [spell]
1518 `(menu-item ,(purecopy "Spell Checking") ispell-menu-map))
1520 (define-key menu [separator-prog]
1523 (define-key menu [semantic]
1524 `(menu-item ,(purecopy "Source Code Parsers (Semantic)")
1526 :help ,(purecopy "Toggle automatic parsing in source code buffers (Semantic mode)")
1527 :button (:toggle . (bound-and-true-p semantic-mode))))
1529 (define-key menu [ede]
1530 `(menu-item ,(purecopy "Project support (EDE)")
1532 :help ,(purecopy "Toggle the Emacs Development Environment (Global EDE mode)")
1533 :button (:toggle . (bound-and-true-p global-ede-mode))))
1535 (define-key menu [gdb]
1536 `(menu-item ,(purecopy "Debugger (GDB)...") gdb
1537 :help ,(purecopy "Debug a program from within Emacs with GDB")))
1538 (define-key menu [shell-on-region]
1539 `(menu-item ,(purecopy "Shell Command on Region...") shell-command-on-region
1541 :help ,(purecopy "Pass marked region to a shell command")))
1542 (define-key menu [shell]
1543 `(menu-item ,(purecopy "Shell Command...") shell-command
1544 :help ,(purecopy "Invoke a shell command and catch its output")))
1545 (define-key menu [compile]
1546 `(menu-item ,(purecopy "Compile...") compile
1547 :help ,(purecopy "Invoke compiler or Make, view compilation errors")))
1548 (define-key menu [grep]
1549 `(menu-item ,(purecopy "Search Files (Grep)...") grep
1550 :help ,(purecopy "Search files for strings or regexps (with Grep)")))
1553 ;; The "Help" menu items
1555 (defvar menu-bar-describe-menu
1556 (let ((menu (make-sparse-keymap "Describe")))
1558 (define-key menu [mule-diag]
1559 `(menu-item ,(purecopy "Show All of Mule Status") mule-diag
1560 :visible (default-value 'enable-multibyte-characters)
1561 :help ,(purecopy "Display multilingual environment settings")))
1562 (define-key menu [describe-coding-system-briefly]
1563 `(menu-item ,(purecopy "Describe Coding System (Briefly)")
1564 describe-current-coding-system-briefly
1565 :visible (default-value 'enable-multibyte-characters)))
1566 (define-key menu [describe-coding-system]
1567 `(menu-item ,(purecopy "Describe Coding System...") describe-coding-system
1568 :visible (default-value 'enable-multibyte-characters)))
1569 (define-key menu [describe-input-method]
1570 `(menu-item ,(purecopy "Describe Input Method...") describe-input-method
1571 :visible (default-value 'enable-multibyte-characters)
1572 :help ,(purecopy "Keyboard layout for specific input method")))
1573 (define-key menu [describe-language-environment]
1574 `(menu-item ,(purecopy "Describe Language Environment")
1575 ,describe-language-environment-map))
1577 (define-key menu [separator-desc-mule]
1580 (define-key menu [list-keybindings]
1581 `(menu-item ,(purecopy "List Key Bindings") describe-bindings
1582 :help ,(purecopy "Display all current key bindings (keyboard shortcuts)")))
1583 (define-key menu [describe-current-display-table]
1584 `(menu-item ,(purecopy "Describe Display Table") describe-current-display-table
1585 :help ,(purecopy "Describe the current display table")))
1586 (define-key menu [describe-package]
1587 `(menu-item ,(purecopy "Describe Package...") describe-package
1588 :help ,(purecopy "Display documentation of a Lisp package")))
1589 (define-key menu [describe-face]
1590 `(menu-item ,(purecopy "Describe Face...") describe-face
1591 :help ,(purecopy "Display the properties of a face")))
1592 (define-key menu [describe-variable]
1593 `(menu-item ,(purecopy "Describe Variable...") describe-variable
1594 :help ,(purecopy "Display documentation of variable/option")))
1595 (define-key menu [describe-function]
1596 `(menu-item ,(purecopy "Describe Function...") describe-function
1597 :help ,(purecopy "Display documentation of function/command")))
1598 (define-key menu [describe-key-1]
1599 `(menu-item ,(purecopy "Describe Key or Mouse Operation...") describe-key
1600 ;; Users typically don't identify keys and menu items...
1601 :help ,(purecopy "Display documentation of command bound to a \
1602 key, a click, or a menu-item")))
1603 (define-key menu [describe-mode]
1604 `(menu-item ,(purecopy "Describe Buffer Modes") describe-mode
1605 :help ,(purecopy "Describe this buffer's major and minor mode")))
1608 (defun menu-bar-read-lispref ()
1609 "Display the Emacs Lisp Reference manual in Info mode."
1613 (defun menu-bar-read-lispintro ()
1614 "Display the Introduction to Emacs Lisp Programming in Info mode."
1618 (defun search-emacs-glossary ()
1619 "Display the Glossary node of the Emacs manual in Info mode."
1621 (info "(emacs)Glossary"))
1623 (defun emacs-index-search (topic)
1624 "Look up TOPIC in the indices of the Emacs User Manual."
1625 (interactive "sSubject to look up: ")
1629 (defun elisp-index-search (topic)
1630 "Look up TOPIC in the indices of the Emacs Lisp Reference Manual."
1631 (interactive "sSubject to look up: ")
1635 (defvar menu-bar-search-documentation-menu
1636 (let ((menu (make-sparse-keymap "Search Documentation")))
1638 (define-key menu [search-documentation-strings]
1639 `(menu-item ,(purecopy "Search Documentation Strings...") apropos-documentation
1641 ,(purecopy "Find functions and variables whose doc strings match a regexp")))
1642 (define-key menu [find-any-object-by-name]
1643 `(menu-item ,(purecopy "Find Any Object by Name...") apropos
1644 :help ,(purecopy "Find symbols of any kind whose names match a regexp")))
1645 (define-key menu [find-option-by-value]
1646 `(menu-item ,(purecopy "Find Options by Value...") apropos-value
1647 :help ,(purecopy "Find variables whose values match a regexp")))
1648 (define-key menu [find-options-by-name]
1649 `(menu-item ,(purecopy "Find Options by Name...") apropos-variable
1650 :help ,(purecopy "Find variables whose names match a regexp")))
1651 (define-key menu [find-commands-by-name]
1652 `(menu-item ,(purecopy "Find Commands by Name...") apropos-command
1653 :help ,(purecopy "Find commands whose names match a regexp")))
1654 (define-key menu [sep1]
1656 (define-key menu [lookup-command-in-manual]
1657 `(menu-item ,(purecopy "Look Up Command in User Manual...") Info-goto-emacs-command-node
1658 :help ,(purecopy "Display manual section that describes a command")))
1659 (define-key menu [lookup-key-in-manual]
1660 `(menu-item ,(purecopy "Look Up Key in User Manual...") Info-goto-emacs-key-command-node
1661 :help ,(purecopy "Display manual section that describes a key")))
1662 (define-key menu [lookup-subject-in-elisp-manual]
1663 `(menu-item ,(purecopy "Look Up Subject in ELisp Manual...") elisp-index-search
1664 :help ,(purecopy "Find description of a subject in Emacs Lisp manual")))
1665 (define-key menu [lookup-subject-in-emacs-manual]
1666 `(menu-item ,(purecopy "Look Up Subject in User Manual...") emacs-index-search
1667 :help ,(purecopy "Find description of a subject in Emacs User manual")))
1668 (define-key menu [emacs-terminology]
1669 `(menu-item ,(purecopy "Emacs Terminology") search-emacs-glossary
1670 :help ,(purecopy "Display the Glossary section of the Emacs manual")))
1673 (defvar menu-bar-manuals-menu
1674 (let ((menu (make-sparse-keymap "More Manuals")))
1676 (define-key menu [man]
1677 `(menu-item ,(purecopy "Read Man Page...") manual-entry
1678 :help ,(purecopy "Man-page docs for external commands and libraries")))
1679 (define-key menu [sep2]
1681 (define-key menu [order-emacs-manuals]
1682 `(menu-item ,(purecopy "Ordering Manuals") view-order-manuals
1683 :help ,(purecopy "How to order manuals from the Free Software Foundation")))
1684 (define-key menu [lookup-subject-in-all-manuals]
1685 `(menu-item ,(purecopy "Lookup Subject in all Manuals...") info-apropos
1686 :help ,(purecopy "Find description of a subject in all installed manuals")))
1687 (define-key menu [other-manuals]
1688 `(menu-item ,(purecopy "All Other Manuals (Info)") Info-directory
1689 :help ,(purecopy "Read any of the installed manuals")))
1690 (define-key menu [emacs-lisp-reference]
1691 `(menu-item ,(purecopy "Emacs Lisp Reference") menu-bar-read-lispref
1692 :help ,(purecopy "Read the Emacs Lisp Reference manual")))
1693 (define-key menu [emacs-lisp-intro]
1694 `(menu-item ,(purecopy "Introduction to Emacs Lisp") menu-bar-read-lispintro
1695 :help ,(purecopy "Read the Introduction to Emacs Lisp Programming")))
1698 (defun menu-bar-help-extra-packages ()
1699 "Display help about some additional packages available for Emacs."
1701 (let (enable-local-variables)
1702 (view-file (expand-file-name "MORE.STUFF"
1704 (goto-address-mode 1)))
1706 (defun help-with-tutorial-spec-language ()
1707 "Use the Emacs tutorial, specifying which language you want."
1709 (help-with-tutorial t))
1711 (defvar menu-bar-help-menu
1712 (let ((menu (make-sparse-keymap "Help")))
1713 (define-key menu [about-gnu-project]
1714 `(menu-item ,(purecopy "About GNU") describe-gnu-project
1715 :help ,(purecopy "About the GNU System, GNU Project, and GNU/Linux")))
1716 (define-key menu [about-emacs]
1717 `(menu-item ,(purecopy "About Emacs") about-emacs
1718 :help ,(purecopy "Display version number, copyright info, and basic help")))
1719 (define-key menu [sep4]
1721 (define-key menu [describe-no-warranty]
1722 `(menu-item ,(purecopy "(Non)Warranty") describe-no-warranty
1723 :help ,(purecopy "Explain that Emacs has NO WARRANTY")))
1724 (define-key menu [describe-copying]
1725 `(menu-item ,(purecopy "Copying Conditions") describe-copying
1726 :help ,(purecopy "Show the Emacs license (GPL)")))
1727 (define-key menu [getting-new-versions]
1728 `(menu-item ,(purecopy "Getting New Versions") describe-distribution
1729 :help ,(purecopy "How to get the latest version of Emacs")))
1730 (define-key menu [sep2]
1732 (define-key menu [external-packages]
1733 `(menu-item ,(purecopy "Finding Extra Packages") menu-bar-help-extra-packages
1734 :help ,(purecopy "Lisp packages distributed separately for use in Emacs")))
1735 (define-key menu [find-emacs-packages]
1736 `(menu-item ,(purecopy "Search Built-in Packages") finder-by-keyword
1737 :help ,(purecopy "Find built-in packages and features by keyword")))
1738 (define-key menu [more-manuals]
1739 `(menu-item ,(purecopy "More Manuals") ,menu-bar-manuals-menu))
1740 (define-key menu [emacs-manual]
1741 `(menu-item ,(purecopy "Read the Emacs Manual") info-emacs-manual
1742 :help ,(purecopy "Full documentation of Emacs features")))
1743 (define-key menu [describe]
1744 `(menu-item ,(purecopy "Describe") ,menu-bar-describe-menu))
1745 (define-key menu [search-documentation]
1746 `(menu-item ,(purecopy "Search Documentation") ,menu-bar-search-documentation-menu))
1747 (define-key menu [sep1]
1749 (define-key menu [emacs-psychotherapist]
1750 `(menu-item ,(purecopy "Emacs Psychotherapist") doctor
1751 :help ,(purecopy "Our doctor will help you feel better")))
1752 (define-key menu [send-emacs-bug-report]
1753 `(menu-item ,(purecopy "Send Bug Report...") report-emacs-bug
1754 :help ,(purecopy "Send e-mail to Emacs maintainers")))
1755 (define-key menu [emacs-known-problems]
1756 `(menu-item ,(purecopy "Emacs Known Problems") view-emacs-problems
1757 :help ,(purecopy "Read about known problems with Emacs")))
1758 (define-key menu [emacs-news]
1759 `(menu-item ,(purecopy "Emacs News") view-emacs-news
1760 :help ,(purecopy "New features of this version")))
1761 (define-key menu [emacs-faq]
1762 `(menu-item ,(purecopy "Emacs FAQ") view-emacs-FAQ
1763 :help ,(purecopy "Frequently asked (and answered) questions about Emacs")))
1765 (define-key menu [emacs-tutorial-language-specific]
1766 `(menu-item ,(purecopy "Emacs Tutorial (choose language)...")
1767 help-with-tutorial-spec-language
1768 :help ,(purecopy "Learn how to use Emacs (choose a language)")))
1769 (define-key menu [emacs-tutorial]
1770 `(menu-item ,(purecopy "Emacs Tutorial") help-with-tutorial
1771 :help ,(purecopy "Learn how to use Emacs")))
1773 ;; In OS X it's in the app menu already.
1774 ;; FIXME? There already is an "About Emacs" (sans ...) entry in the Help menu.
1776 (not (eq system-type 'darwin))
1777 (define-key menu [info-panel]
1778 `(menu-item ,(purecopy "About Emacs...") ns-do-emacs-info-panel)))
1781 (define-key global-map [menu-bar tools]
1782 (cons (purecopy "Tools") menu-bar-tools-menu))
1783 (define-key global-map [menu-bar buffer]
1784 (cons (purecopy "Buffers") global-buffers-menu-map))
1785 (define-key global-map [menu-bar options]
1786 (cons (purecopy "Options") menu-bar-options-menu))
1787 (define-key global-map [menu-bar edit]
1788 (cons (purecopy "Edit") menu-bar-edit-menu))
1789 (define-key global-map [menu-bar file]
1790 (cons (purecopy "File") menu-bar-file-menu))
1792 ;; Put "Help" menu at the end, or Info at the front.
1793 ;; If running under GNUstep, "Help" is moved and renamed "Info" (see below).
1794 (if (and (featurep 'ns)
1795 (not (eq system-type 'darwin)))
1796 (define-key global-map [menu-bar help-menu]
1797 (cons (purecopy "Info") menu-bar-help-menu))
1798 (define-key-after global-map [menu-bar help-menu]
1799 (cons (purecopy "Help") menu-bar-help-menu)))
1801 (defun menu-bar-menu-frame-live-and-visible-p ()
1802 "Return non-nil if the menu frame is alive and visible.
1803 The menu frame is the frame for which we are updating the menu."
1804 (let ((menu-frame (or menu-updating-frame (selected-frame))))
1805 (and (frame-live-p menu-frame)
1806 (frame-visible-p menu-frame))))
1808 (defun menu-bar-non-minibuffer-window-p ()
1809 "Return non-nil if selected window of the menu frame is not a minibuf window.
1811 See the documentation of `menu-bar-menu-frame-live-and-visible-p'
1812 for the definition of the menu frame."
1813 (let ((menu-frame (or menu-updating-frame (selected-frame))))
1814 (not (window-minibuffer-p (frame-selected-window menu-frame)))))
1816 (defun kill-this-buffer () ; for the menu bar
1817 "Kill the current buffer.
1818 When called in the minibuffer, get out of the minibuffer
1819 using `abort-recursive-edit'."
1821 (if (menu-bar-non-minibuffer-window-p)
1822 (kill-buffer (current-buffer))
1823 (abort-recursive-edit)))
1825 (defun kill-this-buffer-enabled-p ()
1826 "Return non-nil if the `kill-this-buffer' menu item should be enabled."
1827 (or (not (menu-bar-non-minibuffer-window-p))
1829 ;; Instead of looping over entire buffer list, stop once we've
1830 ;; found two "killable" buffers (Bug#8184).
1832 (dolist (buffer (buffer-list))
1833 (unless (string-match-p "^ " (buffer-name buffer))
1836 (throw 'found-2 t))))))))
1838 (put 'dired 'menu-enable '(menu-bar-non-minibuffer-window-p))
1840 ;; Permit deleting frame if it would leave a visible or iconified frame.
1841 (defun delete-frame-enabled-p ()
1842 "Return non-nil if `delete-frame' should be enabled in the menu bar."
1843 (let ((frames (frame-list))
1846 (if (frame-visible-p (car frames))
1847 (setq count (1+ count)))
1848 (setq frames (cdr frames)))
1851 (defcustom yank-menu-length 20
1852 "Maximum length to display in the yank-menu."
1856 (defun menu-bar-update-yank-menu (string old)
1857 (let ((front (car (cdr yank-menu)))
1858 (menu-string (if (<= (length string) yank-menu-length)
1861 (substring string 0 (/ yank-menu-length 2))
1863 (substring string (- (/ yank-menu-length 2)))))))
1864 ;; Don't let the menu string be all dashes
1865 ;; because that has a special meaning in a menu.
1866 (if (string-match "\\`-+\\'" menu-string)
1867 (setq menu-string (concat menu-string " ")))
1868 ;; If we're supposed to be extending an existing string, and that
1869 ;; string really is at the front of the menu, then update it in place.
1870 (if (and old (or (eq old (car front))
1871 (string= old (car front))))
1873 (setcar front string)
1874 (setcar (cdr front) menu-string))
1877 (cons string (cons menu-string 'menu-bar-select-yank))
1879 (if (> (length (cdr yank-menu)) kill-ring-max)
1880 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
1882 (put 'menu-bar-select-yank 'apropos-inhibit t)
1883 (defun menu-bar-select-yank ()
1884 "Insert the stretch of previously-killed text selected from menu.
1885 The menu shows all the killed text sequences stored in `kill-ring'."
1888 (insert last-command-event))
1893 (defcustom buffers-menu-max-size 10
1894 "Maximum number of entries which may appear on the Buffers menu.
1895 If this is 10, then only the ten most-recently-selected buffers are shown.
1896 If this is nil, then all buffers are shown.
1897 A large number or nil slows down menu responsiveness."
1898 :type '(choice integer
1899 (const :tag "All" nil))
1902 (defcustom buffers-menu-buffer-name-length 30
1903 "Maximum length of the buffer name on the Buffers menu.
1904 If this is a number, then buffer names are truncated to this length.
1905 If this is nil, then buffer names are shown in full.
1906 A large number or nil makes the menu too wide."
1907 :type '(choice integer
1908 (const :tag "Full length" nil))
1911 (defcustom buffers-menu-show-directories 'unless-uniquify
1912 "If non-nil, show directories in the Buffers menu for buffers that have them.
1913 The special value `unless-uniquify' means that directories will be shown
1914 unless `uniquify-buffer-name-style' is non-nil (in which case, buffer
1915 names should include enough of a buffer's directory to distinguish it
1916 from other buffers).
1918 Setting this variable directly does not take effect until next time the
1919 Buffers menu is regenerated."
1920 :set (lambda (symbol value)
1922 (menu-bar-update-buffers t))
1923 :initialize 'custom-initialize-default
1924 :type '(choice (const :tag "Never" nil)
1925 (const :tag "Unless uniquify is enabled" unless-uniquify)
1926 (const :tag "Always" t))
1929 (defcustom buffers-menu-show-status t
1930 "If non-nil, show modified/read-only status of buffers in the Buffers menu.
1931 Setting this variable directly does not take effect until next time the
1932 Buffers menu is regenerated."
1933 :set (lambda (symbol value)
1935 (menu-bar-update-buffers t))
1936 :initialize 'custom-initialize-default
1940 (defvar list-buffers-directory nil
1941 "String to display in buffer listings for buffers not visiting a file.")
1942 (make-variable-buffer-local 'list-buffers-directory)
1944 (defun menu-bar-select-buffer ()
1946 (switch-to-buffer last-command-event))
1948 (defun menu-bar-select-frame (frame)
1949 (make-frame-visible frame)
1951 (select-frame frame))
1953 (defun menu-bar-update-buffers-1 (elt)
1954 (let* ((buf (car elt))
1956 (and (if (eq buffers-menu-show-directories 'unless-uniquify)
1957 (or (not (boundp 'uniquify-buffer-name-style))
1958 (null uniquify-buffer-name-style))
1959 buffers-menu-show-directories)
1960 (or (buffer-file-name buf)
1961 (buffer-local-value 'list-buffers-directory buf)))))
1963 (setq file (file-name-directory file)))
1964 (when (and file (> (length file) 20))
1965 (setq file (concat "..." (substring file -17))))
1966 (cons (if buffers-menu-show-status
1967 (let ((mod (if (buffer-modified-p buf) "*" ""))
1968 (ro (if (buffer-local-value 'buffer-read-only buf) "%" "")))
1970 (format "%s %s%s -- %s" (cdr elt) mod ro file)
1971 (format "%s %s%s" (cdr elt) mod ro)))
1973 (format "%s -- %s" (cdr elt) file)
1977 ;; Used to cache the menu entries for commands in the Buffers menu
1978 (defvar menu-bar-buffers-menu-command-entries nil)
1980 (defvar menu-bar-select-buffer-function 'switch-to-buffer
1981 "Function to select the buffer chosen from the `Buffers' menu-bar menu.
1982 It must accept a buffer as its only required argument.")
1984 (defun menu-bar-update-buffers (&optional force)
1985 ;; If user discards the Buffers item, play along.
1986 (and (lookup-key (current-global-map) [menu-bar buffer])
1987 (or force (frame-or-buffer-changed-p))
1988 (let ((buffers (buffer-list))
1989 (frames (frame-list))
1991 ;; If requested, list only the N most recently selected buffers.
1992 (if (and (integerp buffers-menu-max-size)
1993 (> buffers-menu-max-size 1))
1994 (if (> (length buffers) buffers-menu-max-size)
1995 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
1997 ;; Make the menu of buffers proper.
2000 ;; Put into each element of buffer-list
2001 ;; the name for actual display,
2002 ;; perhaps truncated in the middle.
2003 (dolist (buf buffers)
2004 (let ((name (buffer-name buf)))
2005 (unless (eq ?\s (aref name 0))
2006 (push (menu-bar-update-buffers-1
2008 (if (and (integerp buffers-menu-buffer-name-length)
2009 (> (length name) buffers-menu-buffer-name-length))
2012 name 0 (/ buffers-menu-buffer-name-length 2))
2015 name (- (/ buffers-menu-buffer-name-length 2))))
2019 ;; Now make the actual list of items.
2020 (let ((buffers-vec (make-vector (length alist) nil))
2022 (dolist (pair alist)
2025 (nconc (list (car pair)
2029 (funcall menu-bar-select-buffer-function ,(cdr pair))))))
2030 (list buffers-vec))))
2032 ;; Make a Frames menu if we have more than one frame.
2034 (let* ((frames-vec (make-vector (length frames) nil))
2037 (list "Select Frame" frames-vec)))
2039 (dolist (frame frames)
2043 (frame-parameter frame 'name)
2046 (interactive) (menu-bar-select-frame ,frame))))
2048 ;; Put it after the normal buffers
2051 `((frames-separator "--")
2052 (frames menu-item "Frames" ,frames-menu))))))
2054 ;; Add in some normal commands at the end of the menu. We use
2055 ;; the copy cached in `menu-bar-buffers-menu-command-entries'
2056 ;; if it's been set already. Note that we can't use constant
2057 ;; lists for the menu-entries, because the low-level menu-code
2059 (unless menu-bar-buffers-menu-command-entries
2060 (setq menu-bar-buffers-menu-command-entries
2061 (list '(command-separator "--")
2066 :help "Switch to the \"next\" buffer in a cyclic order")
2067 (list 'previous-buffer
2071 :help "Switch to the \"previous\" buffer in a cyclic order")
2072 (list 'select-named-buffer
2074 "Select Named Buffer..."
2076 :help "Prompt for a buffer name, and select that buffer in the current window")
2077 (list 'list-all-buffers
2081 :help "Pop up a window listing all Emacs buffers"
2084 (nconc buffers-menu menu-bar-buffers-menu-command-entries))
2086 ;; We used to "(define-key (current-global-map) [menu-bar buffer]"
2087 ;; but that did not do the right thing when the [menu-bar buffer]
2088 ;; entry above had been moved (e.g. to a parent keymap).
2089 (setcdr global-buffers-menu-map (cons "Select Buffer" buffers-menu)))))
2091 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
2093 (menu-bar-update-buffers)
2095 ;; this version is too slow
2096 ;;(defun format-buffers-menu-line (buffer)
2097 ;; "Returns a string to represent the given buffer in the Buffer menu.
2098 ;;nil means the buffer shouldn't be listed. You can redefine this."
2099 ;; (if (string-match "\\` " (buffer-name buffer))
2101 ;; (with-current-buffer buffer
2102 ;; (let ((size (buffer-size)))
2103 ;; (format "%s%s %-19s %6s %-15s %s"
2104 ;; (if (buffer-modified-p) "*" " ")
2105 ;; (if buffer-read-only "%" " ")
2109 ;; (or (buffer-file-name) ""))))))
2111 ;;; Set up a menu bar menu for the minibuffer.
2113 (dolist (map (list minibuffer-local-map
2114 ;; This shouldn't be necessary, but there's a funny
2115 ;; bug in keymap.c that I don't understand yet. -stef
2116 minibuffer-local-completion-map))
2117 (define-key map [menu-bar minibuf]
2118 (cons (purecopy "Minibuf") (make-sparse-keymap "Minibuf"))))
2120 (let ((map minibuffer-local-completion-map))
2121 (define-key map [menu-bar minibuf ?\?]
2122 `(menu-item ,(purecopy "List Completions") minibuffer-completion-help
2123 :help ,(purecopy "Display all possible completions")))
2124 (define-key map [menu-bar minibuf space]
2125 `(menu-item ,(purecopy "Complete Word") minibuffer-complete-word
2126 :help ,(purecopy "Complete at most one word")))
2127 (define-key map [menu-bar minibuf tab]
2128 `(menu-item ,(purecopy "Complete") minibuffer-complete
2129 :help ,(purecopy "Complete as far as possible"))))
2131 (let ((map minibuffer-local-map))
2132 (define-key map [menu-bar minibuf quit]
2133 `(menu-item ,(purecopy "Quit") abort-recursive-edit
2134 :help ,(purecopy "Abort input and exit minibuffer")))
2135 (define-key map [menu-bar minibuf return]
2136 `(menu-item ,(purecopy "Enter") exit-minibuffer
2137 :key-sequence ,(purecopy "\r")
2138 :help ,(purecopy "Terminate input and exit minibuffer")))
2139 (define-key map [menu-bar minibuf isearch-forward]
2140 `(menu-item ,(purecopy "Isearch History Forward") isearch-forward
2141 :help ,(purecopy "Incrementally search minibuffer history forward")))
2142 (define-key map [menu-bar minibuf isearch-backward]
2143 `(menu-item ,(purecopy "Isearch History Backward") isearch-backward
2144 :help ,(purecopy "Incrementally search minibuffer history backward")))
2145 (define-key map [menu-bar minibuf next]
2146 `(menu-item ,(purecopy "Next History Item") next-history-element
2147 :help ,(purecopy "Put next minibuffer history element in the minibuffer")))
2148 (define-key map [menu-bar minibuf previous]
2149 `(menu-item ,(purecopy "Previous History Item") previous-history-element
2150 :help ,(purecopy "Put previous minibuffer history element in the minibuffer"))))
2152 (define-minor-mode menu-bar-mode
2153 "Toggle display of a menu bar on each frame (Menu Bar mode).
2154 With a prefix argument ARG, enable Menu Bar mode if ARG is
2155 positive, and disable it otherwise. If called from Lisp, enable
2156 Menu Bar mode if ARG is omitted or nil.
2158 This command applies to all frames that exist and frames to be
2159 created in the future."
2162 ;; It's defined in C/cus-start, this stops the d-m-m macro defining it again.
2163 :variable menu-bar-mode
2165 ;; Turn the menu-bars on all frames on or off.
2166 (let ((val (if menu-bar-mode 1 0)))
2167 (dolist (frame (frame-list))
2168 (set-frame-parameter frame 'menu-bar-lines val))
2169 ;; If the user has given `default-frame-alist' a `menu-bar-lines'
2170 ;; parameter, replace it.
2171 (if (assq 'menu-bar-lines default-frame-alist)
2172 (setq default-frame-alist
2173 (cons (cons 'menu-bar-lines val)
2174 (assq-delete-all 'menu-bar-lines
2175 default-frame-alist)))))
2176 ;; Make the message appear when Emacs is idle. We can not call message
2177 ;; directly. The minor-mode message "Menu-bar mode disabled" comes
2178 ;; after this function returns, overwriting any message we do here.
2179 (when (and (called-interactively-p 'interactive) (not menu-bar-mode))
2180 (run-with-idle-timer 0 nil 'message
2181 "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear.")))
2184 ;; (This does not work right unless it comes after the above definition.)
2185 ;; This comment is taken from tool-bar.el near
2186 ;; (put 'tool-bar-mode ...)
2187 ;; We want to pretend the menu bar by standard is on, as this will make
2188 ;; customize consider disabling the menu bar a customization, and save
2189 ;; that. We could do this for real by setting :init-value above, but
2190 ;; that would overwrite disabling the menu bar from X resources.
2191 (put 'menu-bar-mode 'standard-value '(t))
2193 (defun toggle-menu-bar-mode-from-frame (&optional arg)
2194 "Toggle menu bar on or off, based on the status of the current frame.
2195 See `menu-bar-mode' for more information."
2196 (interactive (list (or current-prefix-arg 'toggle)))
2197 (if (eq arg 'toggle)
2199 (if (menu-bar-positive-p
2200 (frame-parameter (menu-bar-frame-for-menubar) 'menu-bar-lines))
2202 (menu-bar-mode arg)))
2204 (declare-function x-menu-bar-open "term/x-win" (&optional frame))
2205 (declare-function w32-menu-bar-open "term/w32-win" (&optional frame))
2207 (defun menu-bar-open (&optional frame)
2208 "Start key navigation of the menu bar in FRAME.
2210 This function decides which method to use to access the menu
2211 depending on FRAME's terminal device. On X displays, it calls
2212 `x-menu-bar-open'; on Windows, `w32-menu-bar-open' otherwise it
2213 calls `tmm-menubar'.
2215 If FRAME is nil or not given, use the selected frame."
2217 (let ((type (framep (or frame (selected-frame)))))
2219 ((eq type 'x) (x-menu-bar-open frame))
2220 ((eq type 'w32) (w32-menu-bar-open frame))
2221 (t (with-selected-frame (or frame (selected-frame))
2224 (global-set-key [f10] 'menu-bar-open)
2228 ;;; menu-bar.el ends here