1 ;;; menu-bar.el --- define a default menu bar
3 ;; Copyright (C) 1993, 1994, 1995, 2000, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
8 ;; 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 ;; Don't clobber an existing menu-bar keymap, to preserve any menu-bar key
32 ;; definitions made in loaddefs.el.
33 (or (lookup-key global-map
[menu-bar
])
34 (define-key global-map
[menu-bar
] (make-sparse-keymap "menu-bar")))
35 (defvar menu-bar-help-menu
(make-sparse-keymap "Help"))
37 ;; Force Help item to come last, after the major mode's own items.
38 ;; The symbol used to be called `help', but that gets confused with the
40 (setq menu-bar-final-items
'(help-menu))
42 (define-key global-map
[menu-bar help-menu
] (cons (purecopy "Help") menu-bar-help-menu
))
43 (defvar menu-bar-tools-menu
(make-sparse-keymap "Tools"))
44 (define-key global-map
[menu-bar tools
] (cons (purecopy "Tools") menu-bar-tools-menu
))
45 ;; This definition is just to show what this looks like.
46 ;; It gets modified in place when menu-bar-update-buffers is called.
47 (defvar global-buffers-menu-map
(make-sparse-keymap "Buffers"))
48 (define-key global-map
[menu-bar buffer
]
49 (cons (purecopy "Buffers") global-buffers-menu-map
))
50 (defvar menu-bar-options-menu
(make-sparse-keymap "Options"))
51 (define-key global-map
[menu-bar options
]
52 (cons (purecopy "Options") menu-bar-options-menu
))
53 (defvar menu-bar-edit-menu
(make-sparse-keymap "Edit"))
54 (define-key global-map
[menu-bar edit
] (cons (purecopy "Edit") menu-bar-edit-menu
))
55 (defvar menu-bar-file-menu
(make-sparse-keymap "File"))
56 (define-key global-map
[menu-bar file
] (cons (purecopy "File") menu-bar-file-menu
))
58 ;; Only declared obsolete (and only made a proper alias) in 23.3.
59 (define-obsolete-variable-alias 'menu-bar-files-menu
'menu-bar-file-menu
"22.1")
61 ;; This is referenced by some code below; it is defined in uniquify.el
62 (defvar uniquify-buffer-name-style
)
64 ;; From emulation/cua-base.el; used below
65 (defvar cua-enable-cua-keys
)
68 ;; The "File" menu items
69 (define-key menu-bar-file-menu
[exit-emacs
]
70 `(menu-item ,(purecopy "Quit") save-buffers-kill-terminal
71 :help
,(purecopy "Save unsaved buffers, then exit")))
73 (define-key menu-bar-file-menu
[separator-exit
]
76 ;; Don't use delete-frame as event name because that is a special
78 (define-key menu-bar-file-menu
[delete-this-frame
]
79 `(menu-item ,(purecopy "Delete Frame") delete-frame
80 :visible
(fboundp 'delete-frame
)
81 :enable
(delete-frame-enabled-p)
82 :help
,(purecopy "Delete currently selected frame")))
83 (define-key menu-bar-file-menu
[make-frame-on-display
]
84 `(menu-item ,(purecopy "New Frame on Display...") make-frame-on-display
85 :visible
(fboundp 'make-frame-on-display
)
86 :help
,(purecopy "Open a new frame on another display")))
87 (define-key menu-bar-file-menu
[make-frame
]
88 `(menu-item ,(purecopy "New Frame") make-frame-command
89 :visible
(fboundp 'make-frame-command
)
90 :help
,(purecopy "Open a new frame")))
92 (define-key menu-bar-file-menu
[one-window
]
93 `(menu-item ,(purecopy "Remove Splits") delete-other-windows
94 :enable
(not (one-window-p t nil
))
95 :help
,(purecopy "Selected window grows to fill the whole frame")))
97 (define-key menu-bar-file-menu
[split-window
]
98 `(menu-item ,(purecopy "Split Window") split-window-vertically
99 :enable
(and (menu-bar-menu-frame-live-and-visible-p)
100 (menu-bar-non-minibuffer-window-p))
101 :help
,(purecopy "Split selected window in two windows")))
103 (define-key menu-bar-file-menu
[separator-window
]
106 (define-key menu-bar-file-menu
[ps-print-region
]
107 `(menu-item ,(purecopy "Postscript Print Region (B+W)") ps-print-region
109 :help
,(purecopy "Pretty-print marked region in black and white to PostScript printer")))
110 (define-key menu-bar-file-menu
[ps-print-buffer
]
111 `(menu-item ,(purecopy "Postscript Print Buffer (B+W)") ps-print-buffer
112 :enable
(menu-bar-menu-frame-live-and-visible-p)
113 :help
,(purecopy "Pretty-print current buffer in black and white to PostScript printer")))
114 (define-key menu-bar-file-menu
[ps-print-region-faces
]
115 `(menu-item ,(purecopy "Postscript Print Region") ps-print-region-with-faces
117 :help
,(purecopy "Pretty-print marked region to PostScript printer")))
118 (define-key menu-bar-file-menu
[ps-print-buffer-faces
]
119 `(menu-item ,(purecopy "Postscript Print Buffer") ps-print-buffer-with-faces
120 :enable
(menu-bar-menu-frame-live-and-visible-p)
121 :help
,(purecopy "Pretty-print current buffer to PostScript printer")))
122 (define-key menu-bar-file-menu
[print-region
]
123 `(menu-item ,(purecopy "Print Region") print-region
125 :help
,(purecopy "Print region between mark and current position")))
126 (define-key menu-bar-file-menu
[print-buffer
]
127 `(menu-item ,(purecopy "Print Buffer") print-buffer
128 :enable
(menu-bar-menu-frame-live-and-visible-p)
129 :help
,(purecopy "Print current buffer with page headings")))
131 (define-key menu-bar-file-menu
[separator-print
]
134 (define-key menu-bar-file-menu
[recover-session
]
135 `(menu-item ,(purecopy "Recover Crashed Session") recover-session
136 :enable
(and auto-save-list-file-prefix
138 (file-name-directory auto-save-list-file-prefix
))
140 (file-name-directory auto-save-list-file-prefix
)
144 (file-name-nondirectory
145 auto-save-list-file-prefix
)))
147 :help
,(purecopy "Recover edits from a crashed session")))
148 (define-key menu-bar-file-menu
[revert-buffer
]
149 `(menu-item ,(purecopy "Revert Buffer") revert-buffer
150 :enable
(or revert-buffer-function
151 revert-buffer-insert-file-contents-function
152 (and buffer-file-number
153 (or (buffer-modified-p)
154 (not (verify-visited-file-modtime
155 (current-buffer))))))
156 :help
,(purecopy "Re-read current buffer from its file")))
157 (define-key menu-bar-file-menu
[write-file
]
158 `(menu-item ,(purecopy "Save As...") write-file
159 :enable
(and (menu-bar-menu-frame-live-and-visible-p)
160 (menu-bar-non-minibuffer-window-p))
161 :help
,(purecopy "Write current buffer to another file")))
162 (define-key menu-bar-file-menu
[save-buffer
]
163 `(menu-item ,(purecopy "Save") save-buffer
164 :enable
(and (buffer-modified-p)
166 (menu-bar-non-minibuffer-window-p))
167 :help
,(purecopy "Save current buffer to its file")))
169 (define-key menu-bar-file-menu
[separator-save
]
172 (defun menu-find-file-existing ()
173 "Edit the existing file FILENAME."
175 (let* ((mustmatch (not (and (fboundp 'x-uses-old-gtk-dialog
)
176 (x-uses-old-gtk-dialog))))
177 (filename (car (find-file-read-args "Find file: " mustmatch
))))
179 (find-file-existing filename
)
180 (find-file filename
))))
183 (define-key menu-bar-file-menu
[kill-buffer
]
184 `(menu-item ,(purecopy "Close") kill-this-buffer
185 :enable
(kill-this-buffer-enabled-p)
186 :help
,(purecopy "Discard (kill) current buffer")))
187 (define-key menu-bar-file-menu
[insert-file
]
188 `(menu-item ,(purecopy "Insert File...") insert-file
189 :enable
(menu-bar-non-minibuffer-window-p)
190 :help
,(purecopy "Insert another file into current buffer")))
191 (define-key menu-bar-file-menu
[dired]
192 `(menu-item ,(purecopy "Open Directory...") dired
193 :enable (menu-bar-non-minibuffer-window-p)
194 :help ,(purecopy "Read a directory, to operate on its files")))
195 (define-key menu-bar-file-menu [open-file]
196 `(menu-item ,(purecopy "Open File...") menu-find-file-existing
197 :enable (menu-bar-non-minibuffer-window-p)
198 :help ,(purecopy "Read an existing file into an Emacs buffer")))
199 (define-key menu-bar-file-menu [new-file]
200 `(menu-item ,(purecopy "Visit New File...") find-file
201 :enable (menu-bar-non-minibuffer-window-p)
202 :help ,(purecopy "Specify a new file's name, to edit the file")))
205 ;; The "Edit" menu items
207 ;; The "Edit->Search" submenu
208 (defvar menu-bar-last-search-type nil
209 "Type of last non-incremental search command called from the menu.")
211 (defun nonincremental-repeat-search-forward ()
212 "Search forward for the previous search string or regexp."
215 ((and (eq menu-bar-last-search-type 'string)
217 (search-forward (car search-ring)))
218 ((and (eq menu-bar-last-search-type 'regexp)
220 (re-search-forward (car regexp-search-ring)))
222 (error "No previous search"))))
224 (defun nonincremental-repeat-search-backward ()
225 "Search backward for the previous search string or regexp."
228 ((and (eq menu-bar-last-search-type 'string)
230 (search-backward (car search-ring)))
231 ((and (eq menu-bar-last-search-type 'regexp)
233 (re-search-backward (car regexp-search-ring)))
235 (error "No previous search"))))
237 (defun nonincremental-search-forward (string)
238 "Read a string and search for it nonincrementally."
239 (interactive "sSearch for string: ")
240 (setq menu-bar-last-search-type 'string)
241 (if (equal string "")
242 (search-forward (car search-ring))
243 (isearch-update-ring string nil)
244 (search-forward string)))
246 (defun nonincremental-search-backward (string)
247 "Read a string and search backward for it nonincrementally."
248 (interactive "sSearch for string: ")
249 (setq menu-bar-last-search-type 'string)
250 (if (equal string "")
251 (search-backward (car search-ring))
252 (isearch-update-ring string nil)
253 (search-backward string)))
255 (defun nonincremental-re-search-forward (string)
256 "Read a regular expression and search for it nonincrementally."
257 (interactive "sSearch for regexp: ")
258 (setq menu-bar-last-search-type 'regexp)
259 (if (equal string "")
260 (re-search-forward (car regexp-search-ring))
261 (isearch-update-ring string t)
262 (re-search-forward string)))
264 (defun nonincremental-re-search-backward (string)
265 "Read a regular expression and search backward for it nonincrementally."
266 (interactive "sSearch for regexp: ")
267 (setq menu-bar-last-search-type 'regexp)
268 (if (equal string "")
269 (re-search-backward (car regexp-search-ring))
270 (isearch-update-ring string t)
271 (re-search-backward string)))
273 (defvar menu-bar-search-menu (make-sparse-keymap "Search"))
275 ;; The Edit->Search->Incremental Search menu
276 (defvar menu-bar-i-search-menu
277 (make-sparse-keymap "Incremental Search"))
279 (define-key menu-bar-i-search-menu [isearch-backward-regexp]
280 `(menu-item ,(purecopy "Backward Regexp...") isearch-backward-regexp
281 :help ,(purecopy "Search backwards for a regular expression as you type it")))
282 (define-key menu-bar-i-search-menu [isearch-forward-regexp]
283 `(menu-item ,(purecopy "Forward Regexp...") isearch-forward-regexp
284 :help ,(purecopy "Search forward for a regular expression as you type it")))
285 (define-key menu-bar-i-search-menu [isearch-backward]
286 `(menu-item ,(purecopy "Backward String...") isearch-backward
287 :help ,(purecopy "Search backwards for a string as you type it")))
288 (define-key menu-bar-i-search-menu [isearch-forward]
289 `(menu-item ,(purecopy "Forward String...") isearch-forward
290 :help ,(purecopy "Search forward for a string as you type it")))
292 (define-key menu-bar-search-menu [i-search]
293 `(menu-item ,(purecopy "Incremental Search") ,menu-bar-i-search-menu))
294 (define-key menu-bar-search-menu [separator-tag-isearch]
297 (define-key menu-bar-search-menu [tags-continue]
298 `(menu-item ,(purecopy "Continue Tags Search") tags-loop-continue
299 :help ,(purecopy "Continue last tags search operation")))
300 (define-key menu-bar-search-menu [tags-srch]
301 `(menu-item ,(purecopy "Search Tagged Files...") tags-search
302 :help ,(purecopy "Search for a regexp in all tagged files")))
303 (define-key menu-bar-search-menu [separator-tag-search]
306 (define-key menu-bar-search-menu [repeat-search-back]
307 `(menu-item ,(purecopy "Repeat Backwards") nonincremental-repeat-search-backward
308 :enable (or (and (eq menu-bar-last-search-type 'string)
310 (and (eq menu-bar-last-search-type 'regexp)
312 :help ,(purecopy "Repeat last search backwards")))
313 (define-key menu-bar-search-menu [repeat-search-fwd]
314 `(menu-item ,(purecopy "Repeat Forward") nonincremental-repeat-search-forward
315 :enable (or (and (eq menu-bar-last-search-type 'string)
317 (and (eq menu-bar-last-search-type 'regexp)
319 :help ,(purecopy "Repeat last search forward")))
320 (define-key menu-bar-search-menu [separator-repeat-search]
323 (define-key menu-bar-search-menu [re-search-backward]
324 `(menu-item ,(purecopy "Regexp Backwards...") nonincremental-re-search-backward
325 :help ,(purecopy "Search backwards for a regular expression")))
326 (define-key menu-bar-search-menu [re-search-forward]
327 `(menu-item ,(purecopy "Regexp Forward...") nonincremental-re-search-forward
328 :help ,(purecopy "Search forward for a regular expression")))
330 (define-key menu-bar-search-menu [search-backward]
331 `(menu-item ,(purecopy "String Backwards...") nonincremental-search-backward
332 :help ,(purecopy "Search backwards for a string")))
333 (define-key menu-bar-search-menu [search-forward]
334 `(menu-item ,(purecopy "String Forward...") nonincremental-search-forward
335 :help ,(purecopy "Search forward for a string")))
337 ;; The Edit->Replace submenu
339 (defvar menu-bar-replace-menu (make-sparse-keymap "Replace"))
341 (define-key menu-bar-replace-menu [tags-repl-continue]
342 `(menu-item ,(purecopy "Continue Replace") tags-loop-continue
343 :help ,(purecopy "Continue last tags replace operation")))
344 (define-key menu-bar-replace-menu [tags-repl]
345 `(menu-item ,(purecopy "Replace in Tagged Files...") tags-query-replace
346 :help ,(purecopy "Interactively replace a regexp in all tagged files")))
347 (define-key menu-bar-replace-menu [separator-replace-tags]
350 (define-key menu-bar-replace-menu [query-replace-regexp]
351 `(menu-item ,(purecopy "Replace Regexp...") query-replace-regexp
352 :enable (not buffer-read-only)
353 :help ,(purecopy "Replace regular expression interactively, ask about each occurrence")))
354 (define-key menu-bar-replace-menu [query-replace]
355 `(menu-item ,(purecopy "Replace String...") query-replace
356 :enable (not buffer-read-only)
357 :help ,(purecopy "Replace string interactively, ask about each occurrence")))
359 ;;; Assemble the top-level Edit menu items.
360 (define-key menu-bar-edit-menu [props]
361 `(menu-item ,(purecopy "Text Properties") facemenu-menu))
363 (define-key menu-bar-edit-menu [fill]
364 `(menu-item ,(purecopy "Fill") fill-region
365 :enable (and mark-active (not buffer-read-only))
367 ,(purecopy "Fill text in region to fit between left and right margin")))
369 (define-key menu-bar-edit-menu [separator-bookmark]
372 (define-key menu-bar-edit-menu [bookmark]
373 `(menu-item ,(purecopy "Bookmarks") menu-bar-bookmark-map))
375 (defvar menu-bar-goto-menu (make-sparse-keymap "Go To"))
377 (define-key menu-bar-goto-menu [set-tags-name]
378 `(menu-item ,(purecopy "Set Tags File Name...") visit-tags-table
379 :help ,(purecopy "Tell Tags commands which tag table file to use")))
381 (define-key menu-bar-goto-menu [separator-tag-file]
384 (define-key menu-bar-goto-menu [apropos-tags]
385 `(menu-item ,(purecopy "Tags Apropos...") tags-apropos
386 :help ,(purecopy "Find function/variables whose names match regexp")))
387 (define-key menu-bar-goto-menu [next-tag-otherw]
388 `(menu-item ,(purecopy "Next Tag in Other Window")
389 menu-bar-next-tag-other-window
390 :enable (and (boundp 'tags-location-ring)
391 (not (ring-empty-p tags-location-ring)))
392 :help ,(purecopy "Find next function/variable matching last tag name in another window")))
394 (defun menu-bar-next-tag-other-window ()
395 "Find the next definition of the tag already specified."
397 (find-tag-other-window nil t))
399 (defun menu-bar-next-tag ()
400 "Find the next definition of the tag already specified."
404 (define-key menu-bar-goto-menu [next-tag]
405 `(menu-item ,(purecopy "Find Next Tag")
407 :enable (and (boundp 'tags-location-ring)
408 (not (ring-empty-p tags-location-ring)))
409 :help ,(purecopy "Find next function/variable matching last tag name")))
410 (define-key menu-bar-goto-menu [find-tag-otherw]
411 `(menu-item ,(purecopy "Find Tag in Other Window...") find-tag-other-window
412 :help ,(purecopy "Find function/variable definition in another window")))
413 (define-key menu-bar-goto-menu [find-tag]
414 `(menu-item ,(purecopy "Find Tag...") find-tag
415 :help ,(purecopy "Find definition of function or variable")))
417 (define-key menu-bar-goto-menu [separator-tags]
420 (define-key menu-bar-goto-menu [end-of-buf]
421 `(menu-item ,(purecopy "Goto End of Buffer") end-of-buffer))
422 (define-key menu-bar-goto-menu [beg-of-buf]
423 `(menu-item ,(purecopy "Goto Beginning of Buffer") beginning-of-buffer))
424 (define-key menu-bar-goto-menu [go-to-pos]
425 `(menu-item ,(purecopy "Goto Buffer Position...") goto-char
426 :help ,(purecopy "Read a number N and go to buffer position N")))
427 (define-key menu-bar-goto-menu [go-to-line]
428 `(menu-item ,(purecopy "Goto Line...") goto-line
429 :help ,(purecopy "Read a line number and go to that line")))
431 (define-key menu-bar-edit-menu [goto]
432 `(menu-item ,(purecopy "Go To") ,menu-bar-goto-menu))
434 (define-key menu-bar-edit-menu [replace]
435 `(menu-item ,(purecopy "Replace") ,menu-bar-replace-menu))
437 (define-key menu-bar-edit-menu [search]
438 `(menu-item ,(purecopy "Search") ,menu-bar-search-menu))
440 (define-key menu-bar-edit-menu [separator-search]
443 (define-key menu-bar-edit-menu [mark-whole-buffer]
444 `(menu-item ,(purecopy "Select All") mark-whole-buffer
445 :help ,(purecopy "Mark the whole buffer for a subsequent cut/copy")))
446 (define-key menu-bar-edit-menu [clear]
447 `(menu-item ,(purecopy "Clear") delete-region
448 :enable (and mark-active
449 (not buffer-read-only)
450 (not (mouse-region-match)))
452 ,(purecopy "Delete the text in region between mark and current position")))
453 (defvar yank-menu (cons (purecopy "Select Yank") nil))
454 (fset 'yank-menu (cons 'keymap yank-menu))
455 (define-key menu-bar-edit-menu [paste-from-menu]
456 `(menu-item ,(purecopy "Paste from Kill Menu") yank-menu
457 :enable (and (cdr yank-menu) (not buffer-read-only))
458 :help ,(purecopy "Choose a string from the kill ring and paste it")))
459 (define-key menu-bar-edit-menu [paste]
460 `(menu-item ,(purecopy "Paste") yank
462 ;; Emacs compiled --without-x doesn't have
463 ;; x-selection-exists-p.
464 (and (fboundp 'x-selection-exists-p)
465 (x-selection-exists-p))
467 (not buffer-read-only))
468 :help ,(purecopy "Paste (yank) text most recently cut/copied")))
469 (define-key menu-bar-edit-menu [copy]
470 `(menu-item ,(purecopy "Copy") menu-bar-kill-ring-save
472 :help ,(purecopy "Copy text in region between mark and current position")
473 :keys ,(purecopy "\\[kill-ring-save]")))
474 (define-key menu-bar-edit-menu [cut]
475 `(menu-item ,(purecopy "Cut") kill-region
476 :enable (and mark-active (not buffer-read-only))
478 ,(purecopy "Cut (kill) text in region between mark and current position")))
479 (define-key menu-bar-edit-menu [undo]
480 `(menu-item ,(purecopy "Undo") undo
481 :enable (and (not buffer-read-only)
482 (not (eq t buffer-undo-list))
483 (if (eq last-command 'undo)
484 (listp pending-undo-list)
485 (consp buffer-undo-list)))
486 :help ,(purecopy "Undo last operation")))
489 (defun menu-bar-kill-ring-save (beg end)
491 (if (mouse-region-match)
492 (message "Selecting a region with the mouse does `copy' automatically")
493 (kill-ring-save beg end)))
495 ;; These are alternative definitions for the cut, paste and copy
496 ;; menu items. Use them if your system expects these to use the clipboard.
498 (put 'clipboard-kill-region 'menu-enable
499 '(and mark-active (not buffer-read-only)))
500 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
501 (put 'clipboard-yank 'menu-enable
502 '(and (or (not (fboundp 'x-selection-exists-p))
503 (x-selection-exists-p)
504 (x-selection-exists-p 'CLIPBOARD))
505 (not buffer-read-only)))
507 (defun clipboard-yank ()
508 "Insert the clipboard contents, or the last stretch of killed text."
510 (let ((x-select-enable-clipboard t))
513 (defun clipboard-kill-ring-save (beg end)
514 "Copy region to kill ring, and save in the X clipboard."
516 (let ((x-select-enable-clipboard t))
517 (kill-ring-save beg end)))
519 (defun clipboard-kill-region (beg end)
520 "Kill the region, and save it in the X clipboard."
522 (let ((x-select-enable-clipboard t))
523 (kill-region beg end)))
525 (defun menu-bar-enable-clipboard ()
526 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
527 Do the same for the keys of the same name."
529 ;; We can't use constant list structure here because it becomes pure,
530 ;; and because it gets modified with cache data.
531 (define-key menu-bar-edit-menu [paste]
532 (cons "Paste" (cons "Paste text from clipboard" 'clipboard-yank)))
533 (define-key menu-bar-edit-menu [copy]
534 (cons "Copy" (cons "Copy text in region to the clipboard"
535 'clipboard-kill-ring-save)))
536 (define-key menu-bar-edit-menu [cut]
537 (cons "Cut" (cons "Delete text in region and copy it to the clipboard"
538 'clipboard-kill-region)))
540 ;; These are Sun server keysyms for the Cut, Copy and Paste keys
541 ;; (also for XFree86 on Sun keyboard):
542 (define-key global-map [f20] 'clipboard-kill-region)
543 (define-key global-map [f16] 'clipboard-kill-ring-save)
544 (define-key global-map [f18] 'clipboard-yank)
546 (define-key global-map [cut] 'clipboard-kill-region)
547 (define-key global-map [copy] 'clipboard-kill-ring-save)
548 (define-key global-map [paste] 'clipboard-yank))
550 ;; The "Options" menu items
552 (defvar menu-bar-custom-menu (make-sparse-keymap "Customize"))
554 (define-key menu-bar-custom-menu [customize-apropos-groups]
555 `(menu-item ,(purecopy "Groups Matching Regexp...") customize-apropos-groups
556 :help ,(purecopy "Browse groups whose names match regexp")))
557 (define-key menu-bar-custom-menu [customize-apropos-faces]
558 `(menu-item ,(purecopy "Faces Matching Regexp...") customize-apropos-faces
559 :help ,(purecopy "Browse faces whose names match regexp")))
560 (define-key menu-bar-custom-menu [customize-apropos-options]
561 `(menu-item ,(purecopy "Options Matching Regexp...") customize-apropos-options
562 :help ,(purecopy "Browse options whose names match regexp")))
563 (define-key menu-bar-custom-menu [customize-apropos]
564 `(menu-item ,(purecopy "Settings Matching Regexp...") customize-apropos
565 :help ,(purecopy "Browse customizable settings whose names match regexp")))
566 (define-key menu-bar-custom-menu [separator-1]
568 (define-key menu-bar-custom-menu [customize-group]
569 `(menu-item ,(purecopy "Specific Group...") customize-group
570 :help ,(purecopy "Customize settings of specific group")))
571 (define-key menu-bar-custom-menu [customize-face]
572 `(menu-item ,(purecopy "Specific Face...") customize-face
573 :help ,(purecopy "Customize attributes of specific face")))
574 (define-key menu-bar-custom-menu [customize-option]
575 `(menu-item ,(purecopy "Specific Option...") customize-option
576 :help ,(purecopy "Customize value of specific option")))
577 (define-key menu-bar-custom-menu [separator-2]
579 (define-key menu-bar-custom-menu [customize-changed-options]
580 `(menu-item ,(purecopy "New Options...") customize-changed-options
581 :help ,(purecopy "Options added or changed in recent Emacs versions")))
582 (define-key menu-bar-custom-menu [customize-saved]
583 `(menu-item ,(purecopy "Saved Options") customize-saved
584 :help ,(purecopy "Customize previously saved options")))
585 (define-key menu-bar-custom-menu [separator-3]
587 (define-key menu-bar-custom-menu [customize-browse]
588 `(menu-item ,(purecopy "Browse Customization Groups") customize-browse
589 :help ,(purecopy "Browse all customization groups")))
590 (define-key menu-bar-custom-menu [customize]
591 `(menu-item ,(purecopy "Top-level Customization Group") customize
592 :help ,(purecopy "The master group called `Emacs'")))
594 ;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
596 (defmacro menu-bar-make-mm-toggle (fname doc help &optional props)
597 "Make a menu-item for a global minor mode toggle.
598 FNAME is the minor mode's name (variable and function).
599 DOC is the text to use for the menu entry.
600 HELP is the text to use for the tooltip.
601 PROPS are additional properties."
602 `(list 'menu-item (purecopy ,doc) ',fname
603 ,@(mapcar (lambda (p) (list 'quote p)) props)
604 :help (purecopy ,help)
605 :button '(:toggle . (and (default-boundp ',fname)
606 (default-value ',fname)))))
608 (defmacro menu-bar-make-toggle (name variable doc message help &rest body)
610 (defun ,name (&optional interactively)
611 ,(concat "Toggle whether to " (downcase (substring help 0 1))
612 (substring help 1) ".
613 In an interactive call, record this option as a candidate for saving
614 by \"Save Options\" in Custom buffers.")
616 (if ,(if body `(progn . ,body)
618 (custom-load-symbol ',variable)
619 (let ((set (or (get ',variable 'custom-set) 'set-default))
620 (get (or (get ',variable 'custom-get) 'default-value)))
621 (funcall set ',variable (not (funcall get ',variable))))))
622 (message ,message "enabled globally")
623 (message ,message "disabled globally"))
624 ;; The function `customize-mark-as-set' must only be called when
625 ;; a variable is set interactively, as the purpose is to mark it as
626 ;; a candidate for "Save Options", and we do not want to save options
627 ;; the user have already set explicitly in his init file.
628 (if interactively (customize-mark-as-set ',variable)))
629 (list 'menu-item (purecopy ,doc) ',name
630 :help (purecopy ,help)
631 :button '(:toggle . (and (default-boundp ',variable)
632 (default-value ',variable))))))
634 ;; Function for setting/saving default font.
636 (defun menu-set-font ()
637 "Interactively select a font and make it the default."
639 (let ((font (if (fboundp 'x-select-font)
641 (mouse-select-font)))
644 ;; Be careful here: when set-face-attribute is called for the
645 ;; :font attribute, Emacs tries to guess the best matching font
646 ;; by examining the other face attributes (Bug#2476).
647 (set-face-attribute 'default (selected-frame)
652 (let ((font-object (face-attribute 'default :font)))
653 (dolist (f (frame-list))
654 (and (not (eq f (selected-frame)))
655 (display-graphic-p f)
656 (set-face-attribute 'default f :font font-object)))
657 (set-face-attribute 'default t :font font-object))
658 (setq spec (list (list t (face-attr-construct 'default))))
659 (put 'default 'customized-face spec)
660 (custom-push-theme 'theme-face 'default 'user 'set spec)
661 (put 'default 'face-modified nil))))
665 ;;; Assemble all the top-level items of the "Options" menu
666 (define-key menu-bar-options-menu [customize]
667 `(menu-item ,(purecopy "Customize Emacs") ,menu-bar-custom-menu))
669 (defun menu-bar-options-save ()
670 "Save current values of Options menu items using Custom."
672 (let ((need-save nil))
673 ;; These are set with menu-bar-make-mm-toggle, which does not
674 ;; put on a customized-value property.
675 (dolist (elt '(line-number-mode column-number-mode size-indication-mode
676 cua-mode show-paren-mode transient-mark-mode
677 blink-cursor-mode display-time-mode display-battery-mode
678 ;; These are set by other functions that don't set
679 ;; the customized state. Having them here has the
680 ;; side-effect that turning them off via X
681 ;; resources acts like having customized them, but
682 ;; that seems harmless.
683 menu-bar-mode tool-bar-mode))
684 ;; FIXME ? It's a little annoying that running this command
685 ;; always loads cua-base, paren, time, and battery, even if they
686 ;; have not been customized in any way. (Due to custom-load-symbol.)
687 (and (customize-mark-to-save elt)
689 ;; These are set with `customize-set-variable'.
690 (dolist (elt '(scroll-bar-mode
691 debug-on-quit debug-on-error
692 ;; Somehow this works, when tool-bar and menu-bar don't.
694 save-place uniquify-buffer-name-style fringe-mode
695 indicate-empty-lines indicate-buffer-boundaries
696 case-fold-search font-use-system-font
697 current-language-environment default-input-method
698 ;; Saving `text-mode-hook' is somewhat questionable,
699 ;; as we might get more than we bargain for, if
700 ;; other code may has added hooks as well.
701 ;; Nonetheless, not saving it would like be confuse
703 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
705 (and (get elt 'customized-value)
706 (customize-mark-to-save elt)
708 (when (get 'default 'customized-face)
709 (put 'default 'saved-face (get 'default 'customized-face))
710 (put 'default 'customized-face nil)
712 ;; Save if we changed anything.
716 (define-key menu-bar-options-menu [save]
717 `(menu-item ,(purecopy "Save Options") menu-bar-options-save
718 :help ,(purecopy "Save options set from the menu above")))
720 (define-key menu-bar-options-menu [custom-separator]
723 (define-key menu-bar-options-menu [menu-set-font]
724 `(menu-item ,(purecopy "Set Default Font...") menu-set-font
725 :visible (display-multi-font-p)
726 :help ,(purecopy "Select a default font")))
728 (if (featurep 'system-font-setting)
729 (define-key menu-bar-options-menu [menu-system-font]
730 (menu-bar-make-toggle toggle-use-system-font font-use-system-font
732 "Use system font: %s"
733 "Use the monospaced font defined by the system")))
736 ;; The "Show/Hide" submenu of menu "Options"
738 (defvar menu-bar-showhide-menu (make-sparse-keymap "Show/Hide"))
740 (define-key menu-bar-showhide-menu [column-number-mode]
741 (menu-bar-make-mm-toggle column-number-mode
743 "Show the current column number in the mode line"))
745 (define-key menu-bar-showhide-menu [line-number-mode]
746 (menu-bar-make-mm-toggle line-number-mode
748 "Show the current line number in the mode line"))
750 (define-key menu-bar-showhide-menu [size-indication-mode]
751 (menu-bar-make-mm-toggle size-indication-mode
753 "Show the size of the buffer in the mode line"))
755 (define-key menu-bar-showhide-menu [linecolumn-separator]
758 (define-key menu-bar-showhide-menu [showhide-battery]
759 (menu-bar-make-mm-toggle display-battery-mode
761 "Display battery status information in mode line"))
763 (define-key menu-bar-showhide-menu [showhide-date-time]
764 (menu-bar-make-mm-toggle display-time-mode
765 "Time, Load and Mail"
766 "Display time, system load averages and \
767 mail status in mode line"))
769 (define-key menu-bar-showhide-menu [datetime-separator]
772 (define-key menu-bar-showhide-menu [showhide-speedbar]
773 `(menu-item ,(purecopy "Speedbar") speedbar-frame-mode
774 :help ,(purecopy "Display a Speedbar quick-navigation frame")
776 . (and (boundp 'speedbar-frame)
777 (frame-live-p (symbol-value 'speedbar-frame))
779 (symbol-value 'speedbar-frame))))))
781 (defvar menu-bar-showhide-fringe-menu (make-sparse-keymap "Fringe"))
783 (defvar menu-bar-showhide-fringe-ind-menu
784 (make-sparse-keymap "Buffer boundaries"))
786 (defun menu-bar-showhide-fringe-ind-customize ()
787 "Show customization buffer for `indicate-buffer-boundaries'."
789 (customize-variable 'indicate-buffer-boundaries))
791 (define-key menu-bar-showhide-fringe-ind-menu [customize]
792 `(menu-item ,(purecopy "Other (Customize)")
793 menu-bar-showhide-fringe-ind-customize
794 :help ,(purecopy "Additional choices available through Custom buffer")
795 :visible (display-graphic-p)
796 :button (:radio . (not (member indicate-buffer-boundaries
798 ((top . left) (bottom . right))
799 ((t . right) (top . left))))))))
801 (defun menu-bar-showhide-fringe-ind-mixed ()
802 "Display top and bottom indicators in opposite fringes, arrows in right."
804 (customize-set-variable 'indicate-buffer-boundaries
805 '((t . right) (top . left))))
807 (define-key menu-bar-showhide-fringe-ind-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 (defun menu-bar-showhide-fringe-ind-box ()
816 "Display top and bottom indicators in opposite fringes."
818 (customize-set-variable 'indicate-buffer-boundaries
819 '((top . left) (bottom . right))))
821 (define-key menu-bar-showhide-fringe-ind-menu [box]
822 `(menu-item ,(purecopy "Opposite, No Arrows") menu-bar-showhide-fringe-ind-box
823 :help ,(purecopy "Show top/bottom indicators in opposite fringes, no arrows")
824 :visible (display-graphic-p)
825 :button (:radio . (equal indicate-buffer-boundaries
826 '((top . left) (bottom . right))))))
828 (defun menu-bar-showhide-fringe-ind-right ()
829 "Display buffer boundaries and arrows in the right fringe."
831 (customize-set-variable 'indicate-buffer-boundaries 'right))
833 (define-key menu-bar-showhide-fringe-ind-menu [right]
834 `(menu-item ,(purecopy "In Right Fringe") menu-bar-showhide-fringe-ind-right
835 :help ,(purecopy "Show buffer boundaries and arrows in right fringe")
836 :visible (display-graphic-p)
837 :button (:radio . (eq indicate-buffer-boundaries 'right))))
839 (defun menu-bar-showhide-fringe-ind-left ()
840 "Display buffer boundaries and arrows in the left fringe."
842 (customize-set-variable 'indicate-buffer-boundaries 'left))
844 (define-key menu-bar-showhide-fringe-ind-menu [left]
845 `(menu-item ,(purecopy "In Left Fringe") menu-bar-showhide-fringe-ind-left
846 :help ,(purecopy "Show buffer boundaries and arrows in left fringe")
847 :visible (display-graphic-p)
848 :button (:radio . (eq indicate-buffer-boundaries 'left))))
850 (defun menu-bar-showhide-fringe-ind-none ()
851 "Do not display any buffer boundary indicators."
853 (customize-set-variable 'indicate-buffer-boundaries nil))
855 (define-key menu-bar-showhide-fringe-ind-menu [none]
856 `(menu-item ,(purecopy "No Indicators") menu-bar-showhide-fringe-ind-none
857 :help ,(purecopy "Hide all buffer boundary indicators and arrows")
858 :visible (display-graphic-p)
859 :button (:radio . (eq indicate-buffer-boundaries nil))))
861 (define-key menu-bar-showhide-fringe-menu [showhide-fringe-ind]
862 `(menu-item ,(purecopy "Buffer Boundaries") ,menu-bar-showhide-fringe-ind-menu
863 :visible (display-graphic-p)
864 :help ,(purecopy "Indicate buffer boundaries in fringe")))
866 (define-key menu-bar-showhide-fringe-menu [indicate-empty-lines]
867 (menu-bar-make-toggle toggle-indicate-empty-lines indicate-empty-lines
868 "Empty Line Indicators"
869 "Indicating of empty lines %s"
870 "Indicate trailing empty lines in fringe, globally"))
872 (defun menu-bar-showhide-fringe-menu-customize ()
873 "Show customization buffer for `fringe-mode'."
875 (customize-variable 'fringe-mode))
877 (define-key menu-bar-showhide-fringe-menu [customize]
878 `(menu-item ,(purecopy "Customize Fringe") menu-bar-showhide-fringe-menu-customize
879 :help ,(purecopy "Detailed customization of fringe")
880 :visible (display-graphic-p)))
882 (defun menu-bar-showhide-fringe-menu-customize-reset ()
883 "Reset the fringe mode: display fringes on both sides of a window."
885 (customize-set-variable 'fringe-mode nil))
887 (define-key menu-bar-showhide-fringe-menu [default]
888 `(menu-item ,(purecopy "Default") menu-bar-showhide-fringe-menu-customize-reset
889 :help ,(purecopy "Default width fringe on both left and right side")
890 :visible (display-graphic-p)
891 :button (:radio . (eq fringe-mode nil))))
893 (defun menu-bar-showhide-fringe-menu-customize-right ()
894 "Display fringes only on the right of each window."
897 (customize-set-variable 'fringe-mode '(0 . nil)))
899 (define-key menu-bar-showhide-fringe-menu [right]
900 `(menu-item ,(purecopy "On the Right") menu-bar-showhide-fringe-menu-customize-right
901 :help ,(purecopy "Fringe only on the right side")
902 :visible (display-graphic-p)
903 :button (:radio . (equal fringe-mode '(0 . nil)))))
905 (defun menu-bar-showhide-fringe-menu-customize-left ()
906 "Display fringes only on the left of each window."
909 (customize-set-variable 'fringe-mode '(nil . 0)))
911 (define-key menu-bar-showhide-fringe-menu [left]
912 `(menu-item ,(purecopy "On the Left") menu-bar-showhide-fringe-menu-customize-left
913 :help ,(purecopy "Fringe only on the left side")
914 :visible (display-graphic-p)
915 :button (:radio . (equal fringe-mode '(nil . 0)))))
917 (defun menu-bar-showhide-fringe-menu-customize-disable ()
918 "Do not display window fringes."
921 (customize-set-variable 'fringe-mode 0))
923 (define-key menu-bar-showhide-fringe-menu [none]
924 `(menu-item ,(purecopy "None") menu-bar-showhide-fringe-menu-customize-disable
925 :help ,(purecopy "Turn off fringe")
926 :visible (display-graphic-p)
927 :button (:radio . (eq fringe-mode 0))))
929 (define-key menu-bar-showhide-menu [showhide-fringe]
930 `(menu-item ,(purecopy "Fringe") ,menu-bar-showhide-fringe-menu
931 :visible (display-graphic-p)))
933 (defvar menu-bar-showhide-scroll-bar-menu (make-sparse-keymap "Scroll-bar"))
935 (define-key menu-bar-showhide-scroll-bar-menu [right]
936 `(menu-item ,(purecopy "On the Right")
937 menu-bar-right-scroll-bar
938 :help ,(purecopy "Scroll-bar on the right side")
939 :visible (display-graphic-p)
940 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
941 (frame-parameters))) 'right))))
942 (defun menu-bar-right-scroll-bar ()
943 "Display scroll bars on the right of each window."
945 (customize-set-variable 'scroll-bar-mode 'right))
947 (define-key menu-bar-showhide-scroll-bar-menu [left]
948 `(menu-item ,(purecopy "On the Left")
949 menu-bar-left-scroll-bar
950 :help ,(purecopy "Scroll-bar on the left side")
951 :visible (display-graphic-p)
952 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
953 (frame-parameters))) 'left))))
955 (defun menu-bar-left-scroll-bar ()
956 "Display scroll bars on the left of each window."
958 (customize-set-variable 'scroll-bar-mode 'left))
960 (define-key menu-bar-showhide-scroll-bar-menu [none]
961 `(menu-item ,(purecopy "None")
962 menu-bar-no-scroll-bar
963 :help ,(purecopy "Turn off scroll-bar")
964 :visible (display-graphic-p)
965 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
966 (frame-parameters))) nil))))
968 (defun menu-bar-no-scroll-bar ()
969 "Turn off scroll bars."
971 (customize-set-variable 'scroll-bar-mode nil))
973 (define-key menu-bar-showhide-menu [showhide-scroll-bar]
974 `(menu-item ,(purecopy "Scroll-bar") ,menu-bar-showhide-scroll-bar-menu
975 :visible (display-graphic-p)))
977 (define-key menu-bar-showhide-menu [showhide-tooltip-mode]
978 `(menu-item ,(purecopy "Tooltips") tooltip-mode
979 :help ,(purecopy "Turn tooltips on/off")
980 :visible (and (display-graphic-p) (fboundp 'x-show-tip))
981 :button (:toggle . tooltip-mode)))
983 (defun menu-bar-frame-for-menubar ()
984 "Return the frame suitable for updating the menu bar."
985 (or (and (framep menu-updating-frame)
989 (defun menu-bar-positive-p (val)
990 "Return non-nil iff VAL is a positive number."
994 (define-key menu-bar-showhide-menu [menu-bar-mode]
995 `(menu-item ,(purecopy "Menu-bar") toggle-menu-bar-mode-from-frame
996 :help ,(purecopy "Turn menu-bar on/off")
998 (:toggle . (menu-bar-positive-p
999 (frame-parameter (menu-bar-frame-for-menubar)
1000 'menu-bar-lines)))))
1002 (define-key menu-bar-showhide-menu [showhide-tool-bar]
1003 `(menu-item ,(purecopy "Tool-bar") toggle-tool-bar-mode-from-frame
1004 :help ,(purecopy "Turn tool-bar on/off")
1005 :visible (display-graphic-p)
1007 (:toggle . (menu-bar-positive-p
1008 (frame-parameter (menu-bar-frame-for-menubar)
1009 'tool-bar-lines)))))
1011 (define-key menu-bar-options-menu [showhide]
1012 `(menu-item ,(purecopy "Show/Hide") ,menu-bar-showhide-menu))
1014 (define-key menu-bar-options-menu [showhide-separator]
1017 (define-key menu-bar-options-menu [mule]
1018 ;; It is better not to use backquote here,
1019 ;; because that makes a bootstrapping problem
1020 ;; if you need to recompile all the Lisp files using interpreted code.
1021 `(menu-item ,(purecopy "Mule (Multilingual Environment)") ,mule-menu-keymap
1022 ;; Most of the MULE menu actually does make sense in unibyte mode,
1023 ;; e.g. language selection.
1024 ;;; :visible '(default-value 'enable-multibyte-characters)
1026 ;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
1027 ;(define-key menu-bar-options-menu [preferences]
1028 ; `(menu-item ,(purecopy "Preferences") ,menu-bar-preferences-menu
1029 ; :help ,(purecopy "Toggle important global options")))
1031 (define-key menu-bar-options-menu [mule-separator]
1034 (define-key menu-bar-options-menu [debug-on-quit]
1035 (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
1036 "Enter Debugger on Quit/C-g" "Debug on Quit %s"
1037 "Enter Lisp debugger when C-g is pressed"))
1038 (define-key menu-bar-options-menu [debug-on-error]
1039 (menu-bar-make-toggle toggle-debug-on-error debug-on-error
1040 "Enter Debugger on Error" "Debug on Error %s"
1041 "Enter Lisp debugger when an error is signaled"))
1042 (define-key menu-bar-options-menu [debugger-separator]
1045 (define-key menu-bar-options-menu [blink-cursor-mode]
1046 (menu-bar-make-mm-toggle blink-cursor-mode
1048 "Whether the cursor blinks (Blink Cursor mode)"))
1049 (define-key menu-bar-options-menu [cursor-separator]
1052 (define-key menu-bar-options-menu [save-place]
1053 (menu-bar-make-toggle toggle-save-place-globally save-place
1054 "Save Place in Files between Sessions"
1055 "Saving place in files %s"
1056 "Visit files of previous session when restarting Emacs"
1057 (require 'saveplace)
1058 ;; Do it by name, to avoid a free-variable
1059 ;; warning during byte compilation.
1061 'save-place (not (symbol-value 'save-place)))))
1063 (define-key menu-bar-options-menu [uniquify]
1064 (menu-bar-make-toggle toggle-uniquify-buffer-names uniquify-buffer-name-style
1065 "Use Directory Names in Buffer Names"
1066 "Directory name in buffer names (uniquify) %s"
1067 "Uniquify buffer names by adding parent directory names"
1069 (setq uniquify-buffer-name-style
1070 (if (not uniquify-buffer-name-style)
1073 (define-key menu-bar-options-menu [edit-options-separator]
1075 (define-key menu-bar-options-menu [cua-mode]
1076 (menu-bar-make-mm-toggle cua-mode
1077 "C-x/C-c/C-v Cut and Paste (CUA)"
1078 "Use C-z/C-x/C-c/C-v keys for undo/cut/copy/paste"
1079 (:visible (or (not (boundp 'cua-enable-cua-keys))
1080 cua-enable-cua-keys))))
1082 (define-key menu-bar-options-menu [cua-emulation-mode]
1083 (menu-bar-make-mm-toggle cua-mode
1084 "Shift movement mark region (CUA)"
1085 "Use shifted movement keys to set and extend the region."
1086 (:visible (and (boundp 'cua-enable-cua-keys)
1087 (not cua-enable-cua-keys)))))
1089 (define-key menu-bar-options-menu [case-fold-search]
1090 (menu-bar-make-toggle toggle-case-fold-search case-fold-search
1091 "Case-Insensitive Search"
1092 "Case-Insensitive Search %s"
1093 "Ignore letter-case in search commands"))
1095 (defun menu-bar-text-mode-auto-fill ()
1097 (toggle-text-mode-auto-fill)
1098 ;; This is somewhat questionable, as `text-mode-hook'
1099 ;; might have changed outside customize.
1100 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
1101 (customize-mark-as-set 'text-mode-hook))
1103 (define-key menu-bar-options-menu [auto-fill-mode]
1104 `(menu-item ,(purecopy "Auto Fill in Text Modes")
1105 menu-bar-text-mode-auto-fill
1106 :help ,(purecopy "Automatically fill text while typing (Auto Fill mode)")
1107 :button (:toggle . (if (listp text-mode-hook)
1108 (member 'turn-on-auto-fill text-mode-hook)
1109 (eq 'turn-on-auto-fill text-mode-hook)))))
1112 (defvar menu-bar-line-wrapping-menu (make-sparse-keymap "Line Wrapping"))
1114 (define-key menu-bar-line-wrapping-menu [word-wrap]
1115 `(menu-item ,(purecopy "Word Wrap (Visual Line mode)")
1118 (unless visual-line-mode
1119 (visual-line-mode 1))
1120 (message ,(purecopy "Visual-Line mode enabled")))
1121 :help ,(purecopy "Wrap long lines at word boundaries")
1122 :button (:radio . (and (null truncate-lines)
1123 (not (truncated-partial-width-window-p))
1125 :visible (menu-bar-menu-frame-live-and-visible-p)))
1127 (define-key menu-bar-line-wrapping-menu [truncate]
1128 `(menu-item ,(purecopy "Truncate Long Lines")
1131 (if visual-line-mode (visual-line-mode 0))
1132 (setq word-wrap nil)
1133 (toggle-truncate-lines 1))
1134 :help ,(purecopy "Truncate long lines at window edge")
1135 :button (:radio . (or truncate-lines
1136 (truncated-partial-width-window-p)))
1137 :visible (menu-bar-menu-frame-live-and-visible-p)
1138 :enable (not (truncated-partial-width-window-p))))
1140 (define-key menu-bar-line-wrapping-menu [window-wrap]
1141 `(menu-item ,(purecopy "Wrap at Window Edge")
1142 (lambda () (interactive)
1143 (if visual-line-mode (visual-line-mode 0))
1144 (setq word-wrap nil)
1145 (if truncate-lines (toggle-truncate-lines -1)))
1146 :help ,(purecopy "Wrap long lines at window edge")
1147 :button (:radio . (and (null truncate-lines)
1148 (not (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-bar-options-menu [line-wrapping]
1154 `(menu-item ,(purecopy "Line Wrapping in this Buffer") ,menu-bar-line-wrapping-menu))
1157 (define-key menu-bar-options-menu [highlight-separator]
1159 (define-key menu-bar-options-menu [highlight-paren-mode]
1160 (menu-bar-make-mm-toggle show-paren-mode
1161 "Paren Match Highlighting"
1162 "Highlight matching/mismatched parentheses at cursor (Show Paren mode)"))
1163 (define-key menu-bar-options-menu [transient-mark-mode]
1164 (menu-bar-make-mm-toggle transient-mark-mode
1165 "Active Region Highlighting"
1166 "Make text in active region stand out in color (Transient Mark mode)"
1167 (:enable (not cua-mode))))
1170 ;; The "Tools" menu items
1172 (defun send-mail-item-name ()
1173 (let* ((known-send-mail-commands '((sendmail-user-agent . "sendmail")
1174 (mh-e-user-agent . "MH")
1175 (message-user-agent . "Gnus Message")
1176 (gnus-user-agent . "Gnus")))
1177 (name (assq mail-user-agent known-send-mail-commands)))
1179 (setq name (cdr name))
1180 (setq name (symbol-name mail-user-agent))
1181 (if (string-match "\\(.+\\)-user-agent" name)
1182 (setq name (match-string 1 name))))
1185 (defun read-mail-item-name ()
1186 (let* ((known-rmail-commands '((rmail . "RMAIL")
1189 (known (assq read-mail-command known-rmail-commands)))
1190 (if known (cdr known) (symbol-name read-mail-command))))
1192 (defvar menu-bar-games-menu (make-sparse-keymap "Games"))
1194 (define-key menu-bar-tools-menu [games]
1195 `(menu-item ,(purecopy "Games") ,menu-bar-games-menu))
1197 (define-key menu-bar-tools-menu [separator-games]
1200 (define-key menu-bar-games-menu [zone]
1201 `(menu-item ,(purecopy "Zone Out") zone
1202 :help ,(purecopy "Play tricks with Emacs display when Emacs is idle")))
1203 (define-key menu-bar-games-menu [tetris]
1204 `(menu-item ,(purecopy "Tetris") tetris
1205 :help ,(purecopy "Falling blocks game")))
1206 (define-key menu-bar-games-menu [solitaire]
1207 `(menu-item ,(purecopy "Solitaire") solitaire
1208 :help ,(purecopy "Get rid of all the stones")))
1209 (define-key menu-bar-games-menu [snake]
1210 `(menu-item ,(purecopy "Snake") snake
1211 :help ,(purecopy "Move snake around avoiding collisions")))
1212 (define-key menu-bar-games-menu [pong]
1213 `(menu-item ,(purecopy "Pong") pong
1214 :help ,(purecopy "Bounce the ball to your opponent")))
1215 (define-key menu-bar-games-menu [mult]
1216 `(menu-item ,(purecopy "Multiplication Puzzle") mpuz
1217 :help ,(purecopy "Exercise brain with multiplication")))
1218 (define-key menu-bar-games-menu [life]
1219 `(menu-item ,(purecopy "Life") life
1220 :help ,(purecopy "Watch how John Conway's cellular automaton evolves")))
1221 (define-key menu-bar-games-menu [land]
1222 `(menu-item ,(purecopy "Landmark") landmark
1223 :help ,(purecopy "Watch a neural-network robot learn landmarks")))
1224 (define-key menu-bar-games-menu [hanoi]
1225 `(menu-item ,(purecopy "Towers of Hanoi") hanoi
1226 :help ,(purecopy "Watch Towers-of-Hanoi puzzle solved by Emacs")))
1227 (define-key menu-bar-games-menu [gomoku]
1228 `(menu-item ,(purecopy "Gomoku") gomoku
1229 :help ,(purecopy "Mark 5 contiguous squares (like tic-tac-toe)")))
1230 (define-key menu-bar-games-menu [bubbles]
1231 `(menu-item ,(purecopy "Bubbles") bubbles
1232 :help ,(purecopy "Remove all bubbles using the fewest moves")))
1233 (define-key menu-bar-games-menu [black-box]
1234 `(menu-item ,(purecopy "Blackbox") blackbox
1235 :help ,(purecopy "Find balls in a black box by shooting rays")))
1236 (define-key menu-bar-games-menu [adventure]
1237 `(menu-item ,(purecopy "Adventure") dunnet
1238 :help ,(purecopy "Dunnet, a text Adventure game for Emacs")))
1239 (define-key menu-bar-games-menu [5x5]
1240 `(menu-item ,(purecopy "5x5") 5x5
1241 :help ,(purecopy "Fill in all the squares on a 5x5 board")))
1243 (defvar menu-bar-encryption-decryption-menu
1244 (make-sparse-keymap "Encryption/Decryption"))
1246 (define-key menu-bar-tools-menu [encryption-decryption]
1247 `(menu-item ,(purecopy "Encryption/Decryption") ,menu-bar-encryption-decryption-menu))
1249 (define-key menu-bar-tools-menu [separator-encryption-decryption]
1252 (define-key menu-bar-encryption-decryption-menu [insert-keys]
1253 `(menu-item ,(purecopy "Insert Keys") epa-insert-keys
1254 :help ,(purecopy "Insert public keys after the current point")))
1256 (define-key menu-bar-encryption-decryption-menu [export-keys]
1257 `(menu-item ,(purecopy "Export Keys") epa-export-keys
1258 :help ,(purecopy "Export public keys to a file")))
1260 (define-key menu-bar-encryption-decryption-menu [import-keys-region]
1261 `(menu-item ,(purecopy "Import Keys from Region") epa-import-keys-region
1262 :help ,(purecopy "Import public keys from the current region")))
1264 (define-key menu-bar-encryption-decryption-menu [import-keys]
1265 `(menu-item ,(purecopy "Import Keys from File...") epa-import-keys
1266 :help ,(purecopy "Import public keys from a file")))
1268 (define-key menu-bar-encryption-decryption-menu [list-keys]
1269 `(menu-item ,(purecopy "List Keys") epa-list-keys
1270 :help ,(purecopy "Browse your public keyring")))
1272 (define-key menu-bar-encryption-decryption-menu [separator-keys]
1275 (define-key menu-bar-encryption-decryption-menu [sign-region]
1276 `(menu-item ,(purecopy "Sign Region") epa-sign-region
1277 :help ,(purecopy "Create digital signature of the current region")))
1279 (define-key menu-bar-encryption-decryption-menu [verify-region]
1280 `(menu-item ,(purecopy "Verify Region") epa-verify-region
1281 :help ,(purecopy "Verify digital signature of the current region")))
1283 (define-key menu-bar-encryption-decryption-menu [encrypt-region]
1284 `(menu-item ,(purecopy "Encrypt Region") epa-encrypt-region
1285 :help ,(purecopy "Encrypt the current region")))
1287 (define-key menu-bar-encryption-decryption-menu [decrypt-region]
1288 `(menu-item ,(purecopy "Decrypt Region") epa-decrypt-region
1289 :help ,(purecopy "Decrypt the current region")))
1291 (define-key menu-bar-encryption-decryption-menu [separator-file]
1294 (define-key menu-bar-encryption-decryption-menu [sign-file]
1295 `(menu-item ,(purecopy "Sign File...") epa-sign-file
1296 :help ,(purecopy "Create digital signature of a file")))
1298 (define-key menu-bar-encryption-decryption-menu [verify-file]
1299 `(menu-item ,(purecopy "Verify File...") epa-verify-file
1300 :help ,(purecopy "Verify digital signature of a file")))
1302 (define-key menu-bar-encryption-decryption-menu [encrypt-file]
1303 `(menu-item ,(purecopy "Encrypt File...") epa-encrypt-file
1304 :help ,(purecopy "Encrypt a file")))
1306 (define-key menu-bar-encryption-decryption-menu [decrypt-file]
1307 `(menu-item ,(purecopy "Decrypt File...") epa-decrypt-file
1308 :help ,(purecopy "Decrypt a file")))
1310 (define-key menu-bar-tools-menu [simple-calculator]
1311 `(menu-item ,(purecopy "Simple Calculator") calculator
1312 :help ,(purecopy "Invoke the Emacs built-in quick calculator")))
1313 (define-key menu-bar-tools-menu [calc]
1314 `(menu-item ,(purecopy "Programmable Calculator") calc
1315 :help ,(purecopy "Invoke the Emacs built-in full scientific calculator")))
1316 (define-key menu-bar-tools-menu [calendar]
1317 `(menu-item ,(purecopy "Calendar") calendar
1318 :help ,(purecopy "Invoke the Emacs built-in calendar")))
1320 (define-key menu-bar-tools-menu [separator-net]
1323 (define-key menu-bar-tools-menu [directory-search]
1324 `(menu-item ,(purecopy "Directory Search") eudc-tools-menu))
1325 (define-key menu-bar-tools-menu [compose-mail]
1326 `(menu-item (format "Send Mail (with %s)" (send-mail-item-name)) compose-mail
1327 :visible (and mail-user-agent (not (eq mail-user-agent 'ignore)))
1328 :help ,(purecopy "Send a mail message")))
1329 (define-key menu-bar-tools-menu [rmail]
1330 `(menu-item (format "Read Mail (with %s)" (read-mail-item-name))
1332 :visible (and read-mail-command
1333 (not (eq read-mail-command 'ignore)))
1334 :help ,(purecopy "Read your mail and reply to it")))
1336 (defun menu-bar-read-mail ()
1337 "Read mail using `read-mail-command'."
1339 (call-interactively read-mail-command))
1341 (define-key menu-bar-tools-menu [gnus]
1342 `(menu-item ,(purecopy "Read Net News (Gnus)") gnus
1343 :help ,(purecopy "Read network news groups")))
1345 (define-key menu-bar-tools-menu [separator-vc]
1348 (define-key menu-bar-tools-menu [pcl-cvs]
1349 `(menu-item ,(purecopy "PCL-CVS") cvs-global-menu))
1350 (define-key menu-bar-tools-menu [vc] nil) ;Create the place for the VC menu.
1352 (define-key menu-bar-tools-menu [separator-compare]
1355 (define-key menu-bar-tools-menu [epatch]
1356 `(menu-item ,(purecopy "Apply Patch") menu-bar-epatch-menu))
1357 (define-key menu-bar-tools-menu [ediff-merge]
1358 `(menu-item ,(purecopy "Merge") menu-bar-ediff-merge-menu))
1359 (define-key menu-bar-tools-menu [compare]
1360 `(menu-item ,(purecopy "Compare (Ediff)") menu-bar-ediff-menu))
1362 (define-key menu-bar-tools-menu [separator-spell]
1365 (define-key menu-bar-tools-menu [spell]
1366 `(menu-item ,(purecopy "Spell Checking") ispell-menu-map))
1368 (define-key menu-bar-tools-menu [separator-prog]
1371 (define-key menu-bar-tools-menu [semantic]
1372 `(menu-item ,(purecopy "Source Code Parsers (Semantic)")
1374 :help ,(purecopy "Toggle automatic parsing in source code buffers (Semantic mode)")
1375 :button (:toggle . (bound-and-true-p semantic-mode))))
1377 (define-key menu-bar-tools-menu [ede]
1378 `(menu-item ,(purecopy "Project support (EDE)")
1380 :help ,(purecopy "Toggle the Emacs Development Environment (Global EDE mode)")
1381 :button (:toggle . (bound-and-true-p global-ede-mode))))
1383 (define-key menu-bar-tools-menu [gdb]
1384 `(menu-item ,(purecopy "Debugger (GDB)...") gdb
1385 :help ,(purecopy "Debug a program from within Emacs with GDB")))
1386 (define-key menu-bar-tools-menu [shell-on-region]
1387 `(menu-item ,(purecopy "Shell Command on Region...") shell-command-on-region
1389 :help ,(purecopy "Pass marked region to a shell command")))
1390 (define-key menu-bar-tools-menu [shell]
1391 `(menu-item ,(purecopy "Shell Command...") shell-command
1392 :help ,(purecopy "Invoke a shell command and catch its output")))
1393 (define-key menu-bar-tools-menu [compile]
1394 `(menu-item ,(purecopy "Compile...") compile
1395 :help ,(purecopy "Invoke compiler or Make, view compilation errors")))
1396 (define-key menu-bar-tools-menu [grep]
1397 `(menu-item ,(purecopy "Search Files (Grep)...") grep
1398 :help ,(purecopy "Search files for strings or regexps (with Grep)")))
1401 ;; The "Help" menu items
1403 (defvar menu-bar-describe-menu (make-sparse-keymap "Describe"))
1405 (define-key menu-bar-describe-menu [mule-diag]
1406 `(menu-item ,(purecopy "Show All of Mule Status") mule-diag
1407 :visible (default-value 'enable-multibyte-characters)
1408 :help ,(purecopy "Display multilingual environment settings")))
1409 (define-key menu-bar-describe-menu [describe-coding-system-briefly]
1410 `(menu-item ,(purecopy "Describe Coding System (Briefly)")
1411 describe-current-coding-system-briefly
1412 :visible (default-value 'enable-multibyte-characters)))
1413 (define-key menu-bar-describe-menu [describe-coding-system]
1414 `(menu-item ,(purecopy "Describe Coding System...") describe-coding-system
1415 :visible (default-value 'enable-multibyte-characters)))
1416 (define-key menu-bar-describe-menu [describe-input-method]
1417 `(menu-item ,(purecopy "Describe Input Method...") describe-input-method
1418 :visible (default-value 'enable-multibyte-characters)
1419 :help ,(purecopy "Keyboard layout for specific input method")))
1420 (define-key menu-bar-describe-menu [describe-language-environment]
1421 `(menu-item ,(purecopy "Describe Language Environment")
1422 ,describe-language-environment-map))
1424 (define-key menu-bar-describe-menu [separator-desc-mule]
1427 (define-key menu-bar-describe-menu [list-keybindings]
1428 `(menu-item ,(purecopy "List Key Bindings") describe-bindings
1429 :help ,(purecopy "Display all current key bindings (keyboard shortcuts)")))
1430 (define-key menu-bar-describe-menu [describe-current-display-table]
1431 `(menu-item ,(purecopy "Describe Display Table") describe-current-display-table
1432 :help ,(purecopy "Describe the current display table")))
1433 (define-key menu-bar-describe-menu [describe-face]
1434 `(menu-item ,(purecopy "Describe Face...") describe-face
1435 :help ,(purecopy "Display the properties of a face")))
1436 (define-key menu-bar-describe-menu [describe-variable]
1437 `(menu-item ,(purecopy "Describe Variable...") describe-variable
1438 :help ,(purecopy "Display documentation of variable/option")))
1439 (define-key menu-bar-describe-menu [describe-function]
1440 `(menu-item ,(purecopy "Describe Function...") describe-function
1441 :help ,(purecopy "Display documentation of function/command")))
1442 (define-key menu-bar-describe-menu [describe-key-1]
1443 `(menu-item ,(purecopy "Describe Key or Mouse Operation...") describe-key
1444 ;; Users typically don't identify keys and menu items...
1445 :help ,(purecopy "Display documentation of command bound to a \
1446 key, a click, or a menu-item")))
1447 (define-key menu-bar-describe-menu [describe-mode]
1448 `(menu-item ,(purecopy "Describe Buffer Modes") describe-mode
1449 :help ,(purecopy "Describe this buffer's major and minor mode")))
1451 (defvar menu-bar-search-documentation-menu
1452 (make-sparse-keymap "Search Documentation"))
1453 (defun menu-bar-read-lispref ()
1454 "Display the Emacs Lisp Reference manual in Info mode."
1458 (defun menu-bar-read-lispintro ()
1459 "Display the Introduction to Emacs Lisp Programming in Info mode."
1463 (defun search-emacs-glossary ()
1464 "Display the Glossary node of the Emacs manual in Info mode."
1466 (info "(emacs)Glossary"))
1468 (defun emacs-index-search (topic)
1469 "Look up TOPIC in the indices of the Emacs User Manual."
1470 (interactive "sSubject to look up: ")
1474 (defun elisp-index-search (topic)
1475 "Look up TOPIC in the indices of the Emacs Lisp Reference Manual."
1476 (interactive "sSubject to look up: ")
1480 (define-key menu-bar-search-documentation-menu [search-documentation-strings]
1481 `(menu-item ,(purecopy "Search Documentation Strings...") apropos-documentation
1483 ,(purecopy "Find functions and variables whose doc strings match a regexp")))
1484 (define-key menu-bar-search-documentation-menu [find-any-object-by-name]
1485 `(menu-item ,(purecopy "Find Any Object by Name...") apropos
1486 :help ,(purecopy "Find symbols of any kind whose names match a regexp")))
1487 (define-key menu-bar-search-documentation-menu [find-option-by-value]
1488 `(menu-item ,(purecopy "Find Options by Value...") apropos-value
1489 :help ,(purecopy "Find variables whose values match a regexp")))
1490 (define-key menu-bar-search-documentation-menu [find-options-by-name]
1491 `(menu-item ,(purecopy "Find Options by Name...") apropos-variable
1492 :help ,(purecopy "Find variables whose names match a regexp")))
1493 (define-key menu-bar-search-documentation-menu [find-commands-by-name]
1494 `(menu-item ,(purecopy "Find Commands by Name...") apropos-command
1495 :help ,(purecopy "Find commands whose names match a regexp")))
1496 (define-key menu-bar-search-documentation-menu [sep1]
1498 (define-key menu-bar-search-documentation-menu [lookup-command-in-manual]
1499 `(menu-item ,(purecopy "Look Up Command in User Manual...") Info-goto-emacs-command-node
1500 :help ,(purecopy "Display manual section that describes a command")))
1501 (define-key menu-bar-search-documentation-menu [lookup-key-in-manual]
1502 `(menu-item ,(purecopy "Look Up Key in User Manual...") Info-goto-emacs-key-command-node
1503 :help ,(purecopy "Display manual section that describes a key")))
1504 (define-key menu-bar-search-documentation-menu [lookup-subject-in-elisp-manual]
1505 `(menu-item ,(purecopy "Look Up Subject in ELisp Manual...") elisp-index-search
1506 :help ,(purecopy "Find description of a subject in Emacs Lisp manual")))
1507 (define-key menu-bar-search-documentation-menu [lookup-subject-in-emacs-manual]
1508 `(menu-item ,(purecopy "Look Up Subject in User Manual...") emacs-index-search
1509 :help ,(purecopy "Find description of a subject in Emacs User manual")))
1510 (define-key menu-bar-search-documentation-menu [emacs-terminology]
1511 `(menu-item ,(purecopy "Emacs Terminology") search-emacs-glossary
1512 :help ,(purecopy "Display the Glossary section of the Emacs manual")))
1514 (defvar menu-bar-manuals-menu (make-sparse-keymap "More Manuals"))
1516 (define-key menu-bar-manuals-menu [man]
1517 `(menu-item ,(purecopy "Read Man Page...") manual-entry
1518 :help ,(purecopy "Man-page docs for external commands and libraries")))
1519 (define-key menu-bar-manuals-menu [sep2]
1521 (define-key menu-bar-manuals-menu [order-emacs-manuals]
1522 `(menu-item ,(purecopy "Ordering Manuals") view-order-manuals
1523 :help ,(purecopy "How to order manuals from the Free Software Foundation")))
1524 (define-key menu-bar-manuals-menu [lookup-subject-in-all-manuals]
1525 `(menu-item ,(purecopy "Lookup Subject in all Manuals...") info-apropos
1526 :help ,(purecopy "Find description of a subject in all installed manuals")))
1527 (define-key menu-bar-manuals-menu [other-manuals]
1528 `(menu-item ,(purecopy "All Other Manuals (Info)") Info-directory
1529 :help ,(purecopy "Read any of the installed manuals")))
1530 (define-key menu-bar-manuals-menu [emacs-lisp-reference]
1531 `(menu-item ,(purecopy "Emacs Lisp Reference") menu-bar-read-lispref
1532 :help ,(purecopy "Read the Emacs Lisp Reference manual")))
1533 (define-key menu-bar-manuals-menu [emacs-lisp-intro]
1534 `(menu-item ,(purecopy "Introduction to Emacs Lisp") menu-bar-read-lispintro
1535 :help ,(purecopy "Read the Introduction to Emacs Lisp Programming")))
1537 (define-key menu-bar-help-menu [about-gnu-project]
1538 `(menu-item ,(purecopy "About GNU") describe-gnu-project
1539 :help ,(purecopy "About the GNU System, GNU Project, and GNU/Linux")))
1540 (define-key menu-bar-help-menu [about-emacs]
1541 `(menu-item ,(purecopy "About Emacs") about-emacs
1542 :help ,(purecopy "Display version number, copyright info, and basic help")))
1543 (define-key menu-bar-help-menu [sep4]
1545 (define-key menu-bar-help-menu [describe-no-warranty]
1546 `(menu-item ,(purecopy "(Non)Warranty") describe-no-warranty
1547 :help ,(purecopy "Explain that Emacs has NO WARRANTY")))
1548 (define-key menu-bar-help-menu [describe-copying]
1549 `(menu-item ,(purecopy "Copying Conditions") describe-copying
1550 :help ,(purecopy "Show the Emacs license (GPL)")))
1551 (define-key menu-bar-help-menu [getting-new-versions]
1552 `(menu-item ,(purecopy "Getting New Versions") describe-distribution
1553 :help ,(purecopy "How to get the latest version of Emacs")))
1554 (defun menu-bar-help-extra-packages ()
1555 "Display help about some additional packages available for Emacs."
1557 (let (enable-local-variables)
1558 (view-file (expand-file-name "MORE.STUFF"
1560 (goto-address-mode 1)))
1561 (define-key menu-bar-help-menu [sep2]
1563 (define-key menu-bar-help-menu [external-packages]
1564 `(menu-item ,(purecopy "External Packages") menu-bar-help-extra-packages
1565 :help ,(purecopy "Lisp packages distributed separately for use in Emacs")))
1566 (define-key menu-bar-help-menu [find-emacs-packages]
1567 `(menu-item ,(purecopy "Find Emacs Packages") finder-by-keyword
1568 :help ,(purecopy "Find packages and features by keyword")))
1569 (define-key menu-bar-help-menu [more-manuals]
1570 `(menu-item ,(purecopy "More Manuals") ,menu-bar-manuals-menu))
1571 (define-key menu-bar-help-menu [emacs-manual]
1572 `(menu-item ,(purecopy "Read the Emacs Manual") info-emacs-manual
1573 :help ,(purecopy "Full documentation of Emacs features")))
1574 (define-key menu-bar-help-menu [describe]
1575 `(menu-item ,(purecopy "Describe") ,menu-bar-describe-menu))
1576 (define-key menu-bar-help-menu [search-documentation]
1577 `(menu-item ,(purecopy "Search Documentation") ,menu-bar-search-documentation-menu))
1578 (define-key menu-bar-help-menu [sep1]
1580 (define-key menu-bar-help-menu [emacs-psychotherapist]
1581 `(menu-item ,(purecopy "Emacs Psychotherapist") doctor
1582 :help ,(purecopy "Our doctor will help you feel better")))
1583 (define-key menu-bar-help-menu [send-emacs-bug-report]
1584 `(menu-item ,(purecopy "Send Bug Report...") report-emacs-bug
1585 :help ,(purecopy "Send e-mail to Emacs maintainers")))
1586 (define-key menu-bar-help-menu [emacs-known-problems]
1587 `(menu-item ,(purecopy "Emacs Known Problems") view-emacs-problems
1588 :help ,(purecopy "Read about known problems with Emacs")))
1589 (define-key menu-bar-help-menu [emacs-news]
1590 `(menu-item ,(purecopy "Emacs News") view-emacs-news
1591 :help ,(purecopy "New features of this version")))
1592 (define-key menu-bar-help-menu [emacs-faq]
1593 `(menu-item ,(purecopy "Emacs FAQ") view-emacs-FAQ
1594 :help ,(purecopy "Frequently asked (and answered) questions about Emacs")))
1596 (defun help-with-tutorial-spec-language ()
1597 "Use the Emacs tutorial, specifying which language you want."
1599 (help-with-tutorial t))
1601 (define-key menu-bar-help-menu [emacs-tutorial-language-specific]
1602 `(menu-item ,(purecopy "Emacs Tutorial (choose language)...")
1603 help-with-tutorial-spec-language
1604 :help ,(purecopy "Learn how to use Emacs (choose a language)")))
1605 (define-key menu-bar-help-menu [emacs-tutorial]
1606 `(menu-item ,(purecopy "Emacs Tutorial") help-with-tutorial
1607 :help ,(purecopy "Learn how to use Emacs")))
1609 (defun menu-bar-menu-frame-live-and-visible-p ()
1610 "Return non-nil if the menu frame is alive and visible.
1611 The menu frame is the frame for which we are updating the menu."
1612 (let ((menu-frame (or menu-updating-frame (selected-frame))))
1613 (and (frame-live-p menu-frame)
1614 (frame-visible-p menu-frame))))
1616 (defun menu-bar-non-minibuffer-window-p ()
1617 "Return non-nil if selected window of the menu frame is not a minibuf window.
1619 See the documentation of `menu-bar-menu-frame-live-and-visible-p'
1620 for the definition of the menu frame."
1621 (let ((menu-frame (or menu-updating-frame (selected-frame))))
1622 (not (window-minibuffer-p (frame-selected-window menu-frame)))))
1624 (defun kill-this-buffer () ; for the menu bar
1625 "Kill the current buffer.
1626 When called in the minibuffer, get out of the minibuffer
1627 using `abort-recursive-edit'."
1629 (if (menu-bar-non-minibuffer-window-p)
1630 (kill-buffer (current-buffer))
1631 (abort-recursive-edit)))
1633 (defun kill-this-buffer-enabled-p ()
1635 (buffers (buffer-list)))
1637 (or (string-match "^ " (buffer-name (car buffers)))
1638 (setq count (1+ count)))
1639 (setq buffers (cdr buffers)))
1640 (or (not (menu-bar-non-minibuffer-window-p))
1643 (put 'dired 'menu-enable '(menu-bar-non-minibuffer-window-p))
1645 ;; Permit deleting frame if it would leave a visible or iconified frame.
1646 (defun delete-frame-enabled-p ()
1647 "Return non-nil if `delete-frame' should be enabled in the menu bar."
1648 (let ((frames (frame-list))
1651 (if (frame-visible-p (car frames))
1652 (setq count (1+ count)))
1653 (setq frames (cdr frames)))
1656 (defcustom yank-menu-length 20
1657 "Maximum length to display in the yank-menu."
1661 (defun menu-bar-update-yank-menu (string old)
1662 (let ((front (car (cdr yank-menu)))
1663 (menu-string (if (<= (length string) yank-menu-length)
1666 (substring string 0 (/ yank-menu-length 2))
1668 (substring string (- (/ yank-menu-length 2)))))))
1669 ;; Don't let the menu string be all dashes
1670 ;; because that has a special meaning in a menu.
1671 (if (string-match "\\`-+\\'" menu-string)
1672 (setq menu-string (concat menu-string " ")))
1673 ;; If we're supposed to be extending an existing string, and that
1674 ;; string really is at the front of the menu, then update it in place.
1675 (if (and old (or (eq old (car front))
1676 (string= old (car front))))
1678 (setcar front string)
1679 (setcar (cdr front) menu-string))
1682 (cons string (cons menu-string 'menu-bar-select-yank))
1684 (if (> (length (cdr yank-menu)) kill-ring-max)
1685 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
1687 (put 'menu-bar-select-yank 'apropos-inhibit t)
1688 (defun menu-bar-select-yank ()
1689 "Insert the stretch of previously-killed text selected from menu.
1690 The menu shows all the killed text sequences stored in `kill-ring'."
1693 (insert last-command-event))
1698 (defcustom buffers-menu-max-size 10
1699 "Maximum number of entries which may appear on the Buffers menu.
1700 If this is 10, then only the ten most-recently-selected buffers are shown.
1701 If this is nil, then all buffers are shown.
1702 A large number or nil slows down menu responsiveness."
1703 :type '(choice integer
1704 (const :tag "All" nil))
1707 (defcustom buffers-menu-buffer-name-length 30
1708 "Maximum length of the buffer name on the Buffers menu.
1709 If this is a number, then buffer names are truncated to this length.
1710 If this is nil, then buffer names are shown in full.
1711 A large number or nil makes the menu too wide."
1712 :type '(choice integer
1713 (const :tag "Full length" nil))
1716 (defcustom buffers-menu-show-directories 'unless-uniquify
1717 "If non-nil, show directories in the Buffers menu for buffers that have them.
1718 The special value `unless-uniquify' means that directories will be shown
1719 unless `uniquify-buffer-name-style' is non-nil (in which case, buffer
1720 names should include enough of a buffer's directory to distinguish it
1721 from other buffers).
1723 Setting this variable directly does not take effect until next time the
1724 Buffers menu is regenerated."
1725 :set (lambda (symbol value)
1727 (menu-bar-update-buffers t))
1728 :initialize 'custom-initialize-default
1729 :type '(choice (const :tag "Never" nil)
1730 (const :tag "Unless uniquify is enabled" unless-uniquify)
1731 (const :tag "Always" t))
1734 (defcustom buffers-menu-show-status t
1735 "If non-nil, show modified/read-only status of buffers in the Buffers menu.
1736 Setting this variable directly does not take effect until next time the
1737 Buffers menu is regenerated."
1738 :set (lambda (symbol value)
1740 (menu-bar-update-buffers t))
1741 :initialize 'custom-initialize-default
1745 (defvar list-buffers-directory nil
1746 "String to display in buffer listings for buffers not visiting a file.")
1747 (make-variable-buffer-local 'list-buffers-directory)
1749 (defun menu-bar-select-buffer ()
1751 (switch-to-buffer last-command-event))
1753 (defun menu-bar-select-frame (frame)
1754 (make-frame-visible frame)
1756 (select-frame frame))
1758 (defun menu-bar-update-buffers-1 (elt)
1759 (let* ((buf (car elt))
1761 (and (if (eq buffers-menu-show-directories 'unless-uniquify)
1762 (or (not (boundp 'uniquify-buffer-name-style))
1763 (null uniquify-buffer-name-style))
1764 buffers-menu-show-directories)
1765 (or (buffer-file-name buf)
1766 (buffer-local-value 'list-buffers-directory buf)))))
1768 (setq file (file-name-directory file)))
1769 (when (and file (> (length file) 20))
1770 (setq file (concat "..." (substring file -17))))
1771 (cons (if buffers-menu-show-status
1772 (let ((mod (if (buffer-modified-p buf) "*" ""))
1773 (ro (if (buffer-local-value 'buffer-read-only buf) "%" "")))
1775 (format "%s %s%s -- %s" (cdr elt) mod ro file)
1776 (format "%s %s%s" (cdr elt) mod ro)))
1778 (format "%s -- %s" (cdr elt) file)
1782 ;; Used to cache the menu entries for commands in the Buffers menu
1783 (defvar menu-bar-buffers-menu-command-entries nil)
1785 (defun menu-bar-update-buffers (&optional force)
1786 ;; If user discards the Buffers item, play along.
1787 (and (lookup-key (current-global-map) [menu-bar buffer])
1788 (or force (frame-or-buffer-changed-p))
1789 (let ((buffers (buffer-list))
1790 (frames (frame-list))
1792 ;; If requested, list only the N most recently selected buffers.
1793 (if (and (integerp buffers-menu-max-size)
1794 (> buffers-menu-max-size 1))
1795 (if (> (length buffers) buffers-menu-max-size)
1796 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
1798 ;; Make the menu of buffers proper.
1801 ;; Put into each element of buffer-list
1802 ;; the name for actual display,
1803 ;; perhaps truncated in the middle.
1804 (dolist (buf buffers)
1805 (let ((name (buffer-name buf)))
1806 (unless (eq ?\s (aref name 0))
1807 (push (menu-bar-update-buffers-1
1809 (if (and (integerp buffers-menu-buffer-name-length)
1810 (> (length name) buffers-menu-buffer-name-length))
1813 name 0 (/ buffers-menu-buffer-name-length 2))
1816 name (- (/ buffers-menu-buffer-name-length 2))))
1820 ;; Now make the actual list of items.
1821 (let ((buffers-vec (make-vector (length alist) nil))
1823 (dolist (pair alist)
1826 (nconc (list (car pair)
1830 (switch-to-buffer ,(cdr pair))))))
1831 (list buffers-vec))))
1833 ;; Make a Frames menu if we have more than one frame.
1835 (let* ((frames-vec (make-vector (length frames) nil))
1838 (list "Select Frame" frames-vec)))
1840 (dolist (frame frames)
1844 (frame-parameter frame 'name)
1847 (interactive) (menu-bar-select-frame ,frame))))
1849 ;; Put it after the normal buffers
1852 `((frames-separator "--")
1853 (frames menu-item "Frames" ,frames-menu))))))
1855 ;; Add in some normal commands at the end of the menu. We use
1856 ;; the copy cached in `menu-bar-buffers-menu-command-entries'
1857 ;; if it's been set already. Note that we can't use constant
1858 ;; lists for the menu-entries, because the low-level menu-code
1860 (unless menu-bar-buffers-menu-command-entries
1861 (setq menu-bar-buffers-menu-command-entries
1862 (list '(command-separator "--")
1867 :help "Switch to the \"next\" buffer in a cyclic order")
1868 (list 'previous-buffer
1872 :help "Switch to the \"previous\" buffer in a cyclic order")
1873 (list 'select-named-buffer
1875 "Select Named Buffer..."
1877 :help "Prompt for a buffer name, and select that buffer in the current window")
1878 (list 'list-all-buffers
1882 :help "Pop up a window listing all Emacs buffers"
1885 (nconc buffers-menu menu-bar-buffers-menu-command-entries))
1887 ;; We used to "(define-key (current-global-map) [menu-bar buffer]"
1888 ;; but that did not do the right thing when the [menu-bar buffer]
1889 ;; entry above had been moved (e.g. to a parent keymap).
1890 (setcdr global-buffers-menu-map (cons "Select Buffer" buffers-menu)))))
1892 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
1894 (menu-bar-update-buffers)
1896 ;; this version is too slow
1897 ;;(defun format-buffers-menu-line (buffer)
1898 ;; "Returns a string to represent the given buffer in the Buffer menu.
1899 ;;nil means the buffer shouldn't be listed. You can redefine this."
1900 ;; (if (string-match "\\` " (buffer-name buffer))
1902 ;; (with-current-buffer buffer
1903 ;; (let ((size (buffer-size)))
1904 ;; (format "%s%s %-19s %6s %-15s %s"
1905 ;; (if (buffer-modified-p) "*" " ")
1906 ;; (if buffer-read-only "%" " ")
1910 ;; (or (buffer-file-name) ""))))))
1912 ;;; Set up a menu bar menu for the minibuffer.
1914 (dolist (map (list minibuffer-local-map
1915 ;; This shouldn't be necessary, but there's a funny
1916 ;; bug in keymap.c that I don't understand yet. -stef
1917 minibuffer-local-completion-map))
1918 (define-key map [menu-bar minibuf]
1919 (cons (purecopy "Minibuf") (make-sparse-keymap "Minibuf"))))
1921 (let ((map minibuffer-local-completion-map))
1922 (define-key map [menu-bar minibuf ?\?]
1923 `(menu-item ,(purecopy "List Completions") minibuffer-completion-help
1924 :help ,(purecopy "Display all possible completions")))
1925 (define-key map [menu-bar minibuf space]
1926 `(menu-item ,(purecopy "Complete Word") minibuffer-complete-word
1927 :help ,(purecopy "Complete at most one word")))
1928 (define-key map [menu-bar minibuf tab]
1929 `(menu-item ,(purecopy "Complete") minibuffer-complete
1930 :help ,(purecopy "Complete as far as possible"))))
1932 (let ((map minibuffer-local-map))
1933 (define-key map [menu-bar minibuf quit]
1934 `(menu-item ,(purecopy "Quit") abort-recursive-edit
1935 :help ,(purecopy "Abort input and exit minibuffer")))
1936 (define-key map [menu-bar minibuf return]
1937 `(menu-item ,(purecopy "Enter") exit-minibuffer
1938 :key-sequence ,(purecopy "\r")
1939 :help ,(purecopy "Terminate input and exit minibuffer")))
1940 (define-key map [menu-bar minibuf isearch-forward]
1941 `(menu-item ,(purecopy "Isearch History Forward") isearch-forward
1942 :help ,(purecopy "Incrementally search minibuffer history forward")))
1943 (define-key map [menu-bar minibuf isearch-backward]
1944 `(menu-item ,(purecopy "Isearch History Backward") isearch-backward
1945 :help ,(purecopy "Incrementally search minibuffer history backward")))
1946 (define-key map [menu-bar minibuf next]
1947 `(menu-item ,(purecopy "Next History Item") next-history-element
1948 :help ,(purecopy "Put next minibuffer history element in the minibuffer")))
1949 (define-key map [menu-bar minibuf previous]
1950 `(menu-item ,(purecopy "Previous History Item") previous-history-element
1951 :help ,(purecopy "Put previous minibuffer history element in the minibuffer"))))
1953 (define-minor-mode menu-bar-mode
1954 "Toggle display of a menu bar on each frame.
1955 This command applies to all frames that exist and frames to be
1956 created in the future.
1957 With a numeric argument, if the argument is positive,
1958 turn on menu bars; otherwise, turn off menu bars."
1963 ;; Make menu-bar-mode and default-frame-alist consistent.
1964 (modify-all-frames-parameters (list (cons 'menu-bar-lines
1965 (if menu-bar-mode 1 0))))
1967 ;; Make the message appear when Emacs is idle. We can not call message
1968 ;; directly. The minor-mode message "Menu-bar mode disabled" comes
1969 ;; after this function returns, overwriting any message we do here.
1970 (when (and (called-interactively-p 'interactive) (not menu-bar-mode))
1971 (run-with-idle-timer 0 nil 'message
1972 "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear."))
1976 ;; (This does not work right unless it comes after the above definition.)
1977 ;; This comment is taken from tool-bar.el near
1978 ;; (put 'tool-bar-mode ...)
1979 ;; We want to pretend the menu bar by standard is on, as this will make
1980 ;; customize consider disabling the menu bar a customization, and save
1981 ;; that. We could do this for real by setting :init-value above, but
1982 ;; that would overwrite disabling the menu bar from X resources.
1983 (put 'menu-bar-mode 'standard-value '(t))
1985 (defun toggle-menu-bar-mode-from-frame (&optional arg)
1986 "Toggle menu bar on or off, based on the status of the current frame.
1987 See `menu-bar-mode' for more information."
1988 (interactive (list (or current-prefix-arg 'toggle)))
1989 (if (eq arg 'toggle)
1990 (menu-bar-mode (if (> (frame-parameter nil 'menu-bar-lines) 0) 0 1))
1991 (menu-bar-mode arg)))
1993 (declare-function x-menu-bar-open "term/x-win" (&optional frame))
1994 (declare-function w32-menu-bar-open "term/w32-win" (&optional frame))
1996 (defun menu-bar-open (&optional frame)
1997 "Start key navigation of the menu bar in FRAME.
1999 This function decides which method to use to access the menu
2000 depending on FRAME's terminal device. On X displays, it calls
2001 `x-menu-bar-open'; on Windows, `w32-menu-bar-open' otherwise it
2002 calls `tmm-menubar'.
2004 If FRAME is nil or not given, use the selected frame."
2006 (let ((type (framep (or frame (selected-frame)))))
2008 ((eq type 'x) (x-menu-bar-open frame))
2009 ((eq type 'w32) (w32-menu-bar-open frame))
2010 (t (with-selected-frame (or frame (selected-frame))
2013 (global-set-key [f10] 'menu-bar-open)
2017 ;;; menu-bar.el ends here