1 ;;; menu-bar.el --- define a default menu bar
3 ;; Copyright (C) 1993-1995, 2000-2011 Free Software Foundation, Inc.
7 ;; Keywords: internal, mouse
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; Avishai Yacobi suggested some menu rearrangements.
31 ;; 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 (if (not (featurep 'ns
))
38 ;; Force Help item to come last, after the major mode's own items.
39 ;; The symbol used to be called `help', but that gets confused with the
41 (setq menu-bar-final-items
'(help-menu))
42 (if (eq system-type
'darwin
)
43 (setq menu-bar-final-items
'(buffer services help-menu
))
44 (setq menu-bar-final-items
'(buffer services hide-app quit
))
45 ;; Add standard top-level items to GNUstep menu.
46 (define-key global-map
[menu-bar quit
]
47 `(menu-item ,(purecopy "Quit") save-buffers-kill-emacs
48 :help
,(purecopy "Save unsaved buffers, then exit")))
49 (define-key global-map
[menu-bar hide-app
]
50 `(menu-item ,(purecopy "Hide") ns-do-hide-emacs
51 :help
,(purecopy "Hide Emacs"))))
52 (define-key global-map
[menu-bar services
] ; set-up in ns-win
53 (cons (purecopy "Services") (make-sparse-keymap "Services"))))
55 ;; If running under GNUstep, "Help" is moved and renamed "Info" (see below).
56 (or (and (featurep 'ns
)
57 (not (eq system-type
'darwin
)))
58 (define-key global-map
[menu-bar help-menu
]
59 (cons (purecopy "Help") menu-bar-help-menu
)))
61 (defvar menu-bar-tools-menu
(make-sparse-keymap "Tools"))
62 (define-key global-map
[menu-bar tools
]
63 (cons (purecopy "Tools") menu-bar-tools-menu
))
64 ;; This definition is just to show what this looks like.
65 ;; It gets modified in place when menu-bar-update-buffers is called.
66 (defvar global-buffers-menu-map
(make-sparse-keymap "Buffers"))
67 (define-key global-map
[menu-bar buffer
]
68 (cons (purecopy "Buffers") global-buffers-menu-map
))
69 (defvar menu-bar-options-menu
(make-sparse-keymap "Options"))
70 (define-key global-map
[menu-bar options
]
71 (cons (purecopy "Options") menu-bar-options-menu
))
72 (defvar menu-bar-edit-menu
(make-sparse-keymap "Edit"))
73 (define-key global-map
[menu-bar edit
]
74 (cons (purecopy "Edit") menu-bar-edit-menu
))
75 (defvar menu-bar-file-menu
(make-sparse-keymap "File"))
76 (define-key global-map
[menu-bar file
]
77 (cons (purecopy "File") menu-bar-file-menu
))
79 ;; Put "Help" menu at the front, called "Info".
81 (not (eq system-type
'darwin
))
82 (define-key global-map
[menu-bar help-menu
]
83 (cons (purecopy "Info") menu-bar-help-menu
)))
85 ;; Only declared obsolete (and only made a proper alias) in 23.3.
86 (define-obsolete-variable-alias 'menu-bar-files-menu
'menu-bar-file-menu
"22.1")
88 ;; This is referenced by some code below; it is defined in uniquify.el
89 (defvar uniquify-buffer-name-style
)
91 ;; From emulation/cua-base.el; used below
92 (defvar cua-enable-cua-keys
)
95 ;; The "File" menu items
96 (define-key menu-bar-file-menu
[exit-emacs
]
97 `(menu-item ,(purecopy "Quit") save-buffers-kill-terminal
98 :help
,(purecopy "Save unsaved buffers, then exit")))
100 (define-key menu-bar-file-menu
[separator-exit
]
103 ;; Don't use delete-frame as event name because that is a special
105 (define-key menu-bar-file-menu
[delete-this-frame
]
106 `(menu-item ,(purecopy "Delete Frame") delete-frame
107 :visible
(fboundp 'delete-frame
)
108 :enable
(delete-frame-enabled-p)
109 :help
,(purecopy "Delete currently selected frame")))
110 (define-key menu-bar-file-menu
[make-frame-on-display
]
111 `(menu-item ,(purecopy "New Frame on Display...") make-frame-on-display
112 :visible
(fboundp 'make-frame-on-display
)
113 :help
,(purecopy "Open a new frame on another display")))
114 (define-key menu-bar-file-menu
[make-frame
]
115 `(menu-item ,(purecopy "New Frame") make-frame-command
116 :visible
(fboundp 'make-frame-command
)
117 :help
,(purecopy "Open a new frame")))
119 (define-key menu-bar-file-menu
[one-window
]
120 `(menu-item ,(purecopy "Remove Splits") delete-other-windows
121 :enable
(not (one-window-p t nil
))
122 :help
,(purecopy "Selected window grows to fill the whole frame")))
124 (define-key menu-bar-file-menu
[split-window
]
125 `(menu-item ,(purecopy "Split Window") split-window-vertically
126 :enable
(and (menu-bar-menu-frame-live-and-visible-p)
127 (menu-bar-non-minibuffer-window-p))
128 :help
,(purecopy "Split selected window in two windows")))
130 (define-key menu-bar-file-menu
[separator-window
]
133 (define-key menu-bar-file-menu
[ps-print-region
]
134 `(menu-item ,(purecopy "Postscript Print Region (B+W)") ps-print-region
136 :help
,(purecopy "Pretty-print marked region in black and white to PostScript printer")))
137 (define-key menu-bar-file-menu
[ps-print-buffer
]
138 `(menu-item ,(purecopy "Postscript Print Buffer (B+W)") ps-print-buffer
139 :enable
(menu-bar-menu-frame-live-and-visible-p)
140 :help
,(purecopy "Pretty-print current buffer in black and white to PostScript printer")))
141 (define-key menu-bar-file-menu
[ps-print-region-faces
]
142 `(menu-item ,(purecopy "Postscript Print Region") ps-print-region-with-faces
144 :help
,(purecopy "Pretty-print marked region to PostScript printer")))
145 (define-key menu-bar-file-menu
[ps-print-buffer-faces
]
146 `(menu-item ,(purecopy "Postscript Print Buffer") ps-print-buffer-with-faces
147 :enable
(menu-bar-menu-frame-live-and-visible-p)
148 :help
,(purecopy "Pretty-print current buffer to PostScript printer")))
149 (define-key menu-bar-file-menu
[print-region
]
150 `(menu-item ,(purecopy "Print Region") print-region
152 :help
,(purecopy "Print region between mark and current position")))
153 (define-key menu-bar-file-menu
[print-buffer
]
154 `(menu-item ,(purecopy "Print Buffer") print-buffer
155 :enable
(menu-bar-menu-frame-live-and-visible-p)
156 :help
,(purecopy "Print current buffer with page headings")))
158 (define-key menu-bar-file-menu
[separator-print
]
161 (define-key menu-bar-file-menu
[recover-session
]
162 `(menu-item ,(purecopy "Recover Crashed Session") recover-session
163 :enable
(and auto-save-list-file-prefix
165 (file-name-directory auto-save-list-file-prefix
))
167 (file-name-directory auto-save-list-file-prefix
)
171 (file-name-nondirectory
172 auto-save-list-file-prefix
)))
174 :help
,(purecopy "Recover edits from a crashed session")))
175 (define-key menu-bar-file-menu
[revert-buffer
]
176 `(menu-item ,(purecopy "Revert Buffer") revert-buffer
177 :enable
(or revert-buffer-function
178 revert-buffer-insert-file-contents-function
179 (and buffer-file-number
180 (or (buffer-modified-p)
181 (not (verify-visited-file-modtime
182 (current-buffer))))))
183 :help
,(purecopy "Re-read current buffer from its file")))
184 (define-key menu-bar-file-menu
[write-file
]
185 `(menu-item ,(purecopy "Save As...") write-file
186 :enable
(and (menu-bar-menu-frame-live-and-visible-p)
187 (menu-bar-non-minibuffer-window-p))
188 :help
,(purecopy "Write current buffer to another file")))
189 (define-key menu-bar-file-menu
[save-buffer
]
190 `(menu-item ,(purecopy "Save") save-buffer
191 :enable
(and (buffer-modified-p)
193 (menu-bar-non-minibuffer-window-p))
194 :help
,(purecopy "Save current buffer to its file")))
196 (define-key menu-bar-file-menu
[separator-save
]
199 (defun menu-find-file-existing ()
200 "Edit the existing file FILENAME."
202 (let* ((mustmatch (not (and (fboundp 'x-uses-old-gtk-dialog
)
203 (x-uses-old-gtk-dialog))))
204 (filename (car (find-file-read-args "Find file: " mustmatch
))))
206 (find-file-existing filename
)
207 (find-file filename
))))
210 (define-key menu-bar-file-menu
[kill-buffer
]
211 `(menu-item ,(purecopy "Close") kill-this-buffer
212 :enable
(kill-this-buffer-enabled-p)
213 :help
,(purecopy "Discard (kill) current buffer")))
214 (define-key menu-bar-file-menu
[insert-file
]
215 `(menu-item ,(purecopy "Insert File...") insert-file
216 :enable
(menu-bar-non-minibuffer-window-p)
217 :help
,(purecopy "Insert another file into current buffer")))
218 (define-key menu-bar-file-menu
[dired]
219 `(menu-item ,(purecopy "Open Directory...") dired
220 :enable (menu-bar-non-minibuffer-window-p)
221 :help ,(purecopy "Read a directory, to operate on its files")))
222 (define-key menu-bar-file-menu [open-file]
223 `(menu-item ,(purecopy "Open File...") menu-find-file-existing
224 :enable (menu-bar-non-minibuffer-window-p)
225 :help ,(purecopy "Read an existing file into an Emacs buffer")))
226 (define-key menu-bar-file-menu [new-file]
227 `(menu-item ,(purecopy "Visit New File...") find-file
228 :enable (menu-bar-non-minibuffer-window-p)
229 :help ,(purecopy "Specify a new file's name, to edit the file")))
232 ;; The "Edit" menu items
234 ;; The "Edit->Search" submenu
235 (defvar menu-bar-last-search-type nil
236 "Type of last non-incremental search command called from the menu.")
238 (defun nonincremental-repeat-search-forward ()
239 "Search forward for the previous search string or regexp."
242 ((and (eq menu-bar-last-search-type 'string)
244 (search-forward (car search-ring)))
245 ((and (eq menu-bar-last-search-type 'regexp)
247 (re-search-forward (car regexp-search-ring)))
249 (error "No previous search"))))
251 (defun nonincremental-repeat-search-backward ()
252 "Search backward for the previous search string or regexp."
255 ((and (eq menu-bar-last-search-type 'string)
257 (search-backward (car search-ring)))
258 ((and (eq menu-bar-last-search-type 'regexp)
260 (re-search-backward (car regexp-search-ring)))
262 (error "No previous search"))))
264 (defun nonincremental-search-forward (string)
265 "Read a string and search for it nonincrementally."
266 (interactive "sSearch for string: ")
267 (setq menu-bar-last-search-type 'string)
268 (if (equal string "")
269 (search-forward (car search-ring))
270 (isearch-update-ring string nil)
271 (search-forward string)))
273 (defun nonincremental-search-backward (string)
274 "Read a string and search backward for it nonincrementally."
275 (interactive "sSearch for string: ")
276 (setq menu-bar-last-search-type 'string)
277 (if (equal string "")
278 (search-backward (car search-ring))
279 (isearch-update-ring string nil)
280 (search-backward string)))
282 (defun nonincremental-re-search-forward (string)
283 "Read a regular expression and search for it nonincrementally."
284 (interactive "sSearch for regexp: ")
285 (setq menu-bar-last-search-type 'regexp)
286 (if (equal string "")
287 (re-search-forward (car regexp-search-ring))
288 (isearch-update-ring string t)
289 (re-search-forward string)))
291 (defun nonincremental-re-search-backward (string)
292 "Read a regular expression and search backward for it nonincrementally."
293 (interactive "sSearch for regexp: ")
294 (setq menu-bar-last-search-type 'regexp)
295 (if (equal string "")
296 (re-search-backward (car regexp-search-ring))
297 (isearch-update-ring string t)
298 (re-search-backward string)))
300 (defvar menu-bar-search-menu (make-sparse-keymap "Search"))
302 ;; The Edit->Search->Incremental Search menu
303 (defvar menu-bar-i-search-menu
304 (make-sparse-keymap "Incremental Search"))
306 (define-key menu-bar-i-search-menu [isearch-backward-regexp]
307 `(menu-item ,(purecopy "Backward Regexp...") isearch-backward-regexp
308 :help ,(purecopy "Search backwards for a regular expression as you type it")))
309 (define-key menu-bar-i-search-menu [isearch-forward-regexp]
310 `(menu-item ,(purecopy "Forward Regexp...") isearch-forward-regexp
311 :help ,(purecopy "Search forward for a regular expression as you type it")))
312 (define-key menu-bar-i-search-menu [isearch-backward]
313 `(menu-item ,(purecopy "Backward String...") isearch-backward
314 :help ,(purecopy "Search backwards for a string as you type it")))
315 (define-key menu-bar-i-search-menu [isearch-forward]
316 `(menu-item ,(purecopy "Forward String...") isearch-forward
317 :help ,(purecopy "Search forward for a string as you type it")))
319 (define-key menu-bar-search-menu [i-search]
320 `(menu-item ,(purecopy "Incremental Search") ,menu-bar-i-search-menu))
321 (define-key menu-bar-search-menu [separator-tag-isearch]
324 (define-key menu-bar-search-menu [tags-continue]
325 `(menu-item ,(purecopy "Continue Tags Search") tags-loop-continue
326 :help ,(purecopy "Continue last tags search operation")))
327 (define-key menu-bar-search-menu [tags-srch]
328 `(menu-item ,(purecopy "Search Tagged Files...") tags-search
329 :help ,(purecopy "Search for a regexp in all tagged files")))
330 (define-key menu-bar-search-menu [separator-tag-search]
333 (define-key menu-bar-search-menu [repeat-search-back]
334 `(menu-item ,(purecopy "Repeat Backwards") nonincremental-repeat-search-backward
335 :enable (or (and (eq menu-bar-last-search-type 'string)
337 (and (eq menu-bar-last-search-type 'regexp)
339 :help ,(purecopy "Repeat last search backwards")))
340 (define-key menu-bar-search-menu [repeat-search-fwd]
341 `(menu-item ,(purecopy "Repeat Forward") nonincremental-repeat-search-forward
342 :enable (or (and (eq menu-bar-last-search-type 'string)
344 (and (eq menu-bar-last-search-type 'regexp)
346 :help ,(purecopy "Repeat last search forward")))
347 (define-key menu-bar-search-menu [separator-repeat-search]
350 (define-key menu-bar-search-menu [re-search-backward]
351 `(menu-item ,(purecopy "Regexp Backwards...") nonincremental-re-search-backward
352 :help ,(purecopy "Search backwards for a regular expression")))
353 (define-key menu-bar-search-menu [re-search-forward]
354 `(menu-item ,(purecopy "Regexp Forward...") nonincremental-re-search-forward
355 :help ,(purecopy "Search forward for a regular expression")))
357 (define-key menu-bar-search-menu [search-backward]
358 `(menu-item ,(purecopy "String Backwards...") nonincremental-search-backward
359 :help ,(purecopy "Search backwards for a string")))
360 (define-key menu-bar-search-menu [search-forward]
361 `(menu-item ,(purecopy "String Forward...") nonincremental-search-forward
362 :help ,(purecopy "Search forward for a string")))
364 ;; The Edit->Replace submenu
366 (defvar menu-bar-replace-menu (make-sparse-keymap "Replace"))
368 (define-key menu-bar-replace-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-bar-replace-menu [tags-repl]
372 `(menu-item ,(purecopy "Replace in Tagged Files...") tags-query-replace
373 :help ,(purecopy "Interactively replace a regexp in all tagged files")))
374 (define-key menu-bar-replace-menu [separator-replace-tags]
377 (define-key menu-bar-replace-menu [query-replace-regexp]
378 `(menu-item ,(purecopy "Replace Regexp...") query-replace-regexp
379 :enable (not buffer-read-only)
380 :help ,(purecopy "Replace regular expression interactively, ask about each occurrence")))
381 (define-key menu-bar-replace-menu [query-replace]
382 `(menu-item ,(purecopy "Replace String...") query-replace
383 :enable (not buffer-read-only)
384 :help ,(purecopy "Replace string interactively, ask about each occurrence")))
386 ;;; Assemble the top-level Edit menu items.
387 (define-key menu-bar-edit-menu [props]
388 `(menu-item ,(purecopy "Text Properties") facemenu-menu))
390 ;; ns-win.el said: Add spell for platorm consistency.
392 (define-key menu-bar-edit-menu [spell]
393 `(menu-item ,(purecopy "Spell") ispell-menu-map)))
395 (define-key menu-bar-edit-menu [fill]
396 `(menu-item ,(purecopy "Fill") fill-region
397 :enable (and mark-active (not buffer-read-only))
399 ,(purecopy "Fill text in region to fit between left and right margin")))
401 (define-key menu-bar-edit-menu [separator-bookmark]
404 (define-key menu-bar-edit-menu [bookmark]
405 `(menu-item ,(purecopy "Bookmarks") menu-bar-bookmark-map))
407 (defvar menu-bar-goto-menu (make-sparse-keymap "Go To"))
409 (define-key menu-bar-goto-menu [set-tags-name]
410 `(menu-item ,(purecopy "Set Tags File Name...") visit-tags-table
411 :help ,(purecopy "Tell Tags commands which tag table file to use")))
413 (define-key menu-bar-goto-menu [separator-tag-file]
416 (define-key menu-bar-goto-menu [apropos-tags]
417 `(menu-item ,(purecopy "Tags Apropos...") tags-apropos
418 :help ,(purecopy "Find function/variables whose names match regexp")))
419 (define-key menu-bar-goto-menu [next-tag-otherw]
420 `(menu-item ,(purecopy "Next Tag in Other Window")
421 menu-bar-next-tag-other-window
422 :enable (and (boundp 'tags-location-ring)
423 (not (ring-empty-p tags-location-ring)))
424 :help ,(purecopy "Find next function/variable matching last tag name in another window")))
426 (defun menu-bar-next-tag-other-window ()
427 "Find the next definition of the tag already specified."
429 (find-tag-other-window nil t))
431 (defun menu-bar-next-tag ()
432 "Find the next definition of the tag already specified."
436 (define-key menu-bar-goto-menu [next-tag]
437 `(menu-item ,(purecopy "Find Next Tag")
439 :enable (and (boundp 'tags-location-ring)
440 (not (ring-empty-p tags-location-ring)))
441 :help ,(purecopy "Find next function/variable matching last tag name")))
442 (define-key menu-bar-goto-menu [find-tag-otherw]
443 `(menu-item ,(purecopy "Find Tag in Other Window...") find-tag-other-window
444 :help ,(purecopy "Find function/variable definition in another window")))
445 (define-key menu-bar-goto-menu [find-tag]
446 `(menu-item ,(purecopy "Find Tag...") find-tag
447 :help ,(purecopy "Find definition of function or variable")))
449 (define-key menu-bar-goto-menu [separator-tags]
452 (define-key menu-bar-goto-menu [end-of-buf]
453 `(menu-item ,(purecopy "Goto End of Buffer") end-of-buffer))
454 (define-key menu-bar-goto-menu [beg-of-buf]
455 `(menu-item ,(purecopy "Goto Beginning of Buffer") beginning-of-buffer))
456 (define-key menu-bar-goto-menu [go-to-pos]
457 `(menu-item ,(purecopy "Goto Buffer Position...") goto-char
458 :help ,(purecopy "Read a number N and go to buffer position N")))
459 (define-key menu-bar-goto-menu [go-to-line]
460 `(menu-item ,(purecopy "Goto Line...") goto-line
461 :help ,(purecopy "Read a line number and go to that line")))
463 (define-key menu-bar-edit-menu [goto]
464 `(menu-item ,(purecopy "Go To") ,menu-bar-goto-menu))
466 (define-key menu-bar-edit-menu [replace]
467 `(menu-item ,(purecopy "Replace") ,menu-bar-replace-menu))
469 (define-key menu-bar-edit-menu [search]
470 `(menu-item ,(purecopy "Search") ,menu-bar-search-menu))
472 (define-key menu-bar-edit-menu [separator-search]
475 (define-key menu-bar-edit-menu [mark-whole-buffer]
476 `(menu-item ,(purecopy "Select All") mark-whole-buffer
477 :help ,(purecopy "Mark the whole buffer for a subsequent cut/copy")))
478 (define-key menu-bar-edit-menu [clear]
479 `(menu-item ,(purecopy "Clear") delete-region
480 :enable (and mark-active
481 (not buffer-read-only))
483 ,(purecopy "Delete the text in region between mark and current position")))
484 (defvar yank-menu (cons (purecopy "Select Yank") nil))
485 (fset 'yank-menu (cons 'keymap yank-menu))
486 (define-key menu-bar-edit-menu (if (featurep 'ns) [select-paste]
488 ;; ns-win.el said: Change text to be more consistent with
489 ;; surrounding menu items `paste', etc."
490 `(menu-item ,(purecopy (if (featurep 'ns) "Select and Paste"
491 "Paste from Kill Menu")) yank-menu
492 :enable (and (cdr yank-menu) (not buffer-read-only))
493 :help ,(purecopy "Choose a string from the kill ring and paste it")))
494 (define-key menu-bar-edit-menu [paste]
495 `(menu-item ,(purecopy "Paste") yank
497 ;; Emacs compiled --without-x (or --with-ns)
498 ;; doesn't have x-selection-exists-p.
499 (and (fboundp 'x-selection-exists-p)
500 (x-selection-exists-p 'CLIPBOARD))
501 (if (featurep 'ns) ; like paste-from-menu
504 (not buffer-read-only))
505 :help ,(purecopy "Paste (yank) text most recently cut/copied")))
506 (define-key menu-bar-edit-menu [copy]
507 ;; ns-win.el said: Substitute a Copy function that works better
508 ;; under X (for GNUstep).
509 `(menu-item ,(purecopy "Copy") ,(if (featurep 'ns)
510 'ns-copy-including-secondary
513 :help ,(purecopy "Copy text in region between mark and current position")
514 :keys ,(purecopy (if (featurep 'ns)
515 "\\[ns-copy-including-secondary]"
516 "\\[kill-ring-save]"))))
517 (define-key menu-bar-edit-menu [cut]
518 `(menu-item ,(purecopy "Cut") kill-region
519 :enable (and mark-active (not buffer-read-only))
521 ,(purecopy "Cut (kill) text in region between mark and current position")))
522 ;; ns-win.el said: Separate undo from cut/paste section.
524 (define-key menu-bar-edit-menu [separator-undo] menu-bar-separator))
526 (define-key menu-bar-edit-menu [undo]
527 `(menu-item ,(purecopy "Undo") undo
528 :enable (and (not buffer-read-only)
529 (not (eq t buffer-undo-list))
530 (if (eq last-command 'undo)
531 (listp pending-undo-list)
532 (consp buffer-undo-list)))
533 :help ,(purecopy "Undo last operation")))
535 (define-obsolete-function-alias
536 'menu-bar-kill-ring-save 'kill-ring-save "24.1")
538 ;; These are alternative definitions for the cut, paste and copy
539 ;; menu items. Use them if your system expects these to use the clipboard.
541 (put 'clipboard-kill-region 'menu-enable
542 '(and mark-active (not buffer-read-only)))
543 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
544 (put 'clipboard-yank 'menu-enable
545 '(and (or (not (fboundp 'x-selection-exists-p))
546 (x-selection-exists-p)
547 (x-selection-exists-p 'CLIPBOARD))
548 (not buffer-read-only)))
550 (defun clipboard-yank ()
551 "Insert the clipboard contents, or the last stretch of killed text."
553 (let ((x-select-enable-clipboard t))
556 (defun clipboard-kill-ring-save (beg end)
557 "Copy region to kill ring, and save in the X clipboard."
559 (let ((x-select-enable-clipboard t))
560 (kill-ring-save beg end)))
562 (defun clipboard-kill-region (beg end)
563 "Kill the region, and save it in the X clipboard."
565 (let ((x-select-enable-clipboard t))
566 (kill-region beg end)))
568 (defun menu-bar-enable-clipboard ()
569 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
570 Do the same for the keys of the same name."
572 ;; These are Sun server keysyms for the Cut, Copy and Paste keys
573 ;; (also for XFree86 on Sun keyboard):
574 (define-key global-map [f20] 'clipboard-kill-region)
575 (define-key global-map [f16] 'clipboard-kill-ring-save)
576 (define-key global-map [f18] 'clipboard-yank)
578 (define-key global-map [cut] 'clipboard-kill-region)
579 (define-key global-map [copy] 'clipboard-kill-ring-save)
580 (define-key global-map [paste] 'clipboard-yank))
582 ;; The "Options" menu items
584 (defvar menu-bar-custom-menu (make-sparse-keymap "Customize"))
586 (define-key menu-bar-custom-menu [customize-apropos-faces]
587 `(menu-item ,(purecopy "Faces Matching...") customize-apropos-faces
588 :help ,(purecopy "Browse faces matching a regexp or word list")))
589 (define-key menu-bar-custom-menu [customize-apropos-options]
590 `(menu-item ,(purecopy "Options Matching...") customize-apropos-options
591 :help ,(purecopy "Browse options matching a regexp or word list")))
592 (define-key menu-bar-custom-menu [customize-apropos]
593 `(menu-item ,(purecopy "All Settings Matching...") customize-apropos
594 :help ,(purecopy "Browse customizable settings matching a regexp or word list")))
595 (define-key menu-bar-custom-menu [separator-1]
597 (define-key menu-bar-custom-menu [customize-group]
598 `(menu-item ,(purecopy "Specific Group...") customize-group
599 :help ,(purecopy "Customize settings of specific group")))
600 (define-key menu-bar-custom-menu [customize-face]
601 `(menu-item ,(purecopy "Specific Face...") customize-face
602 :help ,(purecopy "Customize attributes of specific face")))
603 (define-key menu-bar-custom-menu [customize-option]
604 `(menu-item ,(purecopy "Specific Option...") customize-option
605 :help ,(purecopy "Customize value of specific option")))
606 (define-key menu-bar-custom-menu [separator-2]
608 (define-key menu-bar-custom-menu [customize-changed-options]
609 `(menu-item ,(purecopy "New Options...") customize-changed-options
610 :help ,(purecopy "Options added or changed in recent Emacs versions")))
611 (define-key menu-bar-custom-menu [customize-saved]
612 `(menu-item ,(purecopy "Saved Options") customize-saved
613 :help ,(purecopy "Customize previously saved options")))
614 (define-key menu-bar-custom-menu [separator-3]
616 (define-key menu-bar-custom-menu [customize-browse]
617 `(menu-item ,(purecopy "Browse Customization Groups") customize-browse
618 :help ,(purecopy "Browse all customization groups")))
619 (define-key menu-bar-custom-menu [customize]
620 `(menu-item ,(purecopy "Top-level Customization Group") customize
621 :help ,(purecopy "The master group called `Emacs'")))
622 (define-key menu-bar-custom-menu [customize-themes]
623 `(menu-item ,(purecopy "Custom Themes") customize-themes
624 :help ,(purecopy "Choose a pre-defined customization theme")))
626 ;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
628 (defmacro menu-bar-make-mm-toggle (fname doc help &optional props)
629 "Make a menu-item for a global minor mode toggle.
630 FNAME is the minor mode's name (variable and function).
631 DOC is the text to use for the menu entry.
632 HELP is the text to use for the tooltip.
633 PROPS are additional properties."
634 `(list 'menu-item (purecopy ,doc) ',fname
635 ,@(mapcar (lambda (p) (list 'quote p)) props)
636 :help (purecopy ,help)
637 :button '(:toggle . (and (default-boundp ',fname)
638 (default-value ',fname)))))
640 (defmacro menu-bar-make-toggle (name variable doc message help &rest body)
642 (defun ,name (&optional interactively)
643 ,(concat "Toggle whether to " (downcase (substring help 0 1))
644 (substring help 1) ".
645 In an interactive call, record this option as a candidate for saving
646 by \"Save Options\" in Custom buffers.")
648 (if ,(if body `(progn . ,body)
650 (custom-load-symbol ',variable)
651 (let ((set (or (get ',variable 'custom-set) 'set-default))
652 (get (or (get ',variable 'custom-get) 'default-value)))
653 (funcall set ',variable (not (funcall get ',variable))))))
654 (message ,message "enabled globally")
655 (message ,message "disabled globally"))
656 ;; The function `customize-mark-as-set' must only be called when
657 ;; a variable is set interactively, as the purpose is to mark it as
658 ;; a candidate for "Save Options", and we do not want to save options
659 ;; the user have already set explicitly in his init file.
660 (if interactively (customize-mark-as-set ',variable)))
661 (list 'menu-item (purecopy ,doc) ',name
662 :help (purecopy ,help)
663 :button '(:toggle . (and (default-boundp ',variable)
664 (default-value ',variable))))))
666 ;; Function for setting/saving default font.
668 (defun menu-set-font ()
669 "Interactively select a font and make it the default."
671 (let ((font (if (fboundp 'x-select-font)
673 (mouse-select-font)))
676 ;; Be careful here: when set-face-attribute is called for the
677 ;; :font attribute, Emacs tries to guess the best matching font
678 ;; by examining the other face attributes (Bug#2476).
679 (set-face-attribute 'default (selected-frame)
684 (let ((font-object (face-attribute 'default :font)))
685 (dolist (f (frame-list))
686 (and (not (eq f (selected-frame)))
687 (display-graphic-p f)
688 (set-face-attribute 'default f :font font-object)))
689 (set-face-attribute 'default t :font font-object))
690 (setq spec (list (list t (face-attr-construct 'default))))
691 (put 'default 'customized-face spec)
692 (custom-push-theme 'theme-face 'default 'user 'set spec)
693 (put 'default 'face-modified nil))))
697 ;;; Assemble all the top-level items of the "Options" menu
698 (define-key menu-bar-options-menu [customize]
699 `(menu-item ,(purecopy "Customize Emacs") ,menu-bar-custom-menu))
701 (defun menu-bar-options-save ()
702 "Save current values of Options menu items using Custom."
704 (let ((need-save nil))
705 ;; These are set with menu-bar-make-mm-toggle, which does not
706 ;; put on a customized-value property.
707 (dolist (elt '(line-number-mode column-number-mode size-indication-mode
708 cua-mode show-paren-mode transient-mark-mode
709 blink-cursor-mode display-time-mode display-battery-mode
710 ;; These are set by other functions that don't set
711 ;; the customized state. Having them here has the
712 ;; side-effect that turning them off via X
713 ;; resources acts like having customized them, but
714 ;; that seems harmless.
715 menu-bar-mode tool-bar-mode))
716 ;; FIXME ? It's a little annoying that running this command
717 ;; always loads cua-base, paren, time, and battery, even if they
718 ;; have not been customized in any way. (Due to custom-load-symbol.)
719 (and (customize-mark-to-save elt)
721 ;; These are set with `customize-set-variable'.
722 (dolist (elt '(scroll-bar-mode
723 debug-on-quit debug-on-error
724 ;; Somehow this works, when tool-bar and menu-bar don't.
726 save-place uniquify-buffer-name-style fringe-mode
727 indicate-empty-lines indicate-buffer-boundaries
728 case-fold-search font-use-system-font
729 current-language-environment default-input-method
730 ;; Saving `text-mode-hook' is somewhat questionable,
731 ;; as we might get more than we bargain for, if
732 ;; other code may has added hooks as well.
733 ;; Nonetheless, not saving it would like be confuse
735 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
736 text-mode-hook tool-bar-position))
737 (and (get elt 'customized-value)
738 (customize-mark-to-save elt)
740 (when (get 'default 'customized-face)
741 (put 'default 'saved-face (get 'default 'customized-face))
742 (put 'default 'customized-face nil)
744 ;; Save if we changed anything.
748 (define-key menu-bar-options-menu [package]
749 '(menu-item "Manage Emacs Packages" package-list-packages
750 :help "Install or uninstall additional Emacs packages"))
752 (define-key menu-bar-options-menu [save]
753 `(menu-item ,(purecopy "Save Options") menu-bar-options-save
754 :help ,(purecopy "Save options set from the menu above")))
756 (define-key menu-bar-options-menu [custom-separator]
759 (define-key menu-bar-options-menu [menu-set-font]
760 `(menu-item ,(purecopy "Set Default Font...") menu-set-font
761 :visible (display-multi-font-p)
762 :help ,(purecopy "Select a default font")))
764 (if (featurep 'system-font-setting)
765 (define-key menu-bar-options-menu [menu-system-font]
766 (menu-bar-make-toggle toggle-use-system-font font-use-system-font
768 "Use system font: %s"
769 "Use the monospaced font defined by the system")))
772 ;; The "Show/Hide" submenu of menu "Options"
774 (defvar menu-bar-showhide-menu (make-sparse-keymap "Show/Hide"))
776 (define-key menu-bar-showhide-menu [column-number-mode]
777 (menu-bar-make-mm-toggle column-number-mode
779 "Show the current column number in the mode line"))
781 (define-key menu-bar-showhide-menu [line-number-mode]
782 (menu-bar-make-mm-toggle line-number-mode
784 "Show the current line number in the mode line"))
786 (define-key menu-bar-showhide-menu [size-indication-mode]
787 (menu-bar-make-mm-toggle size-indication-mode
789 "Show the size of the buffer in the mode line"))
791 (define-key menu-bar-showhide-menu [linecolumn-separator]
794 (define-key menu-bar-showhide-menu [showhide-battery]
795 (menu-bar-make-mm-toggle display-battery-mode
797 "Display battery status information in mode line"))
799 (define-key menu-bar-showhide-menu [showhide-date-time]
800 (menu-bar-make-mm-toggle display-time-mode
801 "Time, Load and Mail"
802 "Display time, system load averages and \
803 mail status in mode line"))
805 (define-key menu-bar-showhide-menu [datetime-separator]
808 (define-key menu-bar-showhide-menu [showhide-speedbar]
809 `(menu-item ,(purecopy "Speedbar") speedbar-frame-mode
810 :help ,(purecopy "Display a Speedbar quick-navigation frame")
812 . (and (boundp 'speedbar-frame)
813 (frame-live-p (symbol-value 'speedbar-frame))
815 (symbol-value 'speedbar-frame))))))
817 (defvar menu-bar-showhide-fringe-menu (make-sparse-keymap "Fringe"))
819 (defvar menu-bar-showhide-fringe-ind-menu
820 (make-sparse-keymap "Buffer boundaries"))
822 (defun menu-bar-showhide-fringe-ind-customize ()
823 "Show customization buffer for `indicate-buffer-boundaries'."
825 (customize-variable 'indicate-buffer-boundaries))
827 (define-key menu-bar-showhide-fringe-ind-menu [customize]
828 `(menu-item ,(purecopy "Other (Customize)")
829 menu-bar-showhide-fringe-ind-customize
830 :help ,(purecopy "Additional choices available through Custom buffer")
831 :visible (display-graphic-p)
832 :button (:radio . (not (member indicate-buffer-boundaries
834 ((top . left) (bottom . right))
835 ((t . right) (top . left))))))))
837 (defun menu-bar-showhide-fringe-ind-mixed ()
838 "Display top and bottom indicators in opposite fringes, arrows in right."
840 (customize-set-variable 'indicate-buffer-boundaries
841 '((t . right) (top . left))))
843 (define-key menu-bar-showhide-fringe-ind-menu [mixed]
844 `(menu-item ,(purecopy "Opposite, Arrows Right") menu-bar-showhide-fringe-ind-mixed
846 ,(purecopy "Show top/bottom indicators in opposite fringes, arrows in right")
847 :visible (display-graphic-p)
848 :button (:radio . (equal indicate-buffer-boundaries
849 '((t . right) (top . left))))))
851 (defun menu-bar-showhide-fringe-ind-box ()
852 "Display top and bottom indicators in opposite fringes."
854 (customize-set-variable 'indicate-buffer-boundaries
855 '((top . left) (bottom . right))))
857 (define-key menu-bar-showhide-fringe-ind-menu [box]
858 `(menu-item ,(purecopy "Opposite, No Arrows") menu-bar-showhide-fringe-ind-box
859 :help ,(purecopy "Show top/bottom indicators in opposite fringes, no arrows")
860 :visible (display-graphic-p)
861 :button (:radio . (equal indicate-buffer-boundaries
862 '((top . left) (bottom . right))))))
864 (defun menu-bar-showhide-fringe-ind-right ()
865 "Display buffer boundaries and arrows in the right fringe."
867 (customize-set-variable 'indicate-buffer-boundaries 'right))
869 (define-key menu-bar-showhide-fringe-ind-menu [right]
870 `(menu-item ,(purecopy "In Right Fringe") menu-bar-showhide-fringe-ind-right
871 :help ,(purecopy "Show buffer boundaries and arrows in right fringe")
872 :visible (display-graphic-p)
873 :button (:radio . (eq indicate-buffer-boundaries 'right))))
875 (defun menu-bar-showhide-fringe-ind-left ()
876 "Display buffer boundaries and arrows in the left fringe."
878 (customize-set-variable 'indicate-buffer-boundaries 'left))
880 (define-key menu-bar-showhide-fringe-ind-menu [left]
881 `(menu-item ,(purecopy "In Left Fringe") menu-bar-showhide-fringe-ind-left
882 :help ,(purecopy "Show buffer boundaries and arrows in left fringe")
883 :visible (display-graphic-p)
884 :button (:radio . (eq indicate-buffer-boundaries 'left))))
886 (defun menu-bar-showhide-fringe-ind-none ()
887 "Do not display any buffer boundary indicators."
889 (customize-set-variable 'indicate-buffer-boundaries nil))
891 (define-key menu-bar-showhide-fringe-ind-menu [none]
892 `(menu-item ,(purecopy "No Indicators") menu-bar-showhide-fringe-ind-none
893 :help ,(purecopy "Hide all buffer boundary indicators and arrows")
894 :visible (display-graphic-p)
895 :button (:radio . (eq indicate-buffer-boundaries nil))))
897 (define-key menu-bar-showhide-fringe-menu [showhide-fringe-ind]
898 `(menu-item ,(purecopy "Buffer Boundaries") ,menu-bar-showhide-fringe-ind-menu
899 :visible (display-graphic-p)
900 :help ,(purecopy "Indicate buffer boundaries in fringe")))
902 (define-key menu-bar-showhide-fringe-menu [indicate-empty-lines]
903 (menu-bar-make-toggle toggle-indicate-empty-lines indicate-empty-lines
904 "Empty Line Indicators"
905 "Indicating of empty lines %s"
906 "Indicate trailing empty lines in fringe, globally"))
908 (defun menu-bar-showhide-fringe-menu-customize ()
909 "Show customization buffer for `fringe-mode'."
911 (customize-variable 'fringe-mode))
913 (define-key menu-bar-showhide-fringe-menu [customize]
914 `(menu-item ,(purecopy "Customize Fringe") menu-bar-showhide-fringe-menu-customize
915 :help ,(purecopy "Detailed customization of fringe")
916 :visible (display-graphic-p)))
918 (defun menu-bar-showhide-fringe-menu-customize-reset ()
919 "Reset the fringe mode: display fringes on both sides of a window."
921 (customize-set-variable 'fringe-mode nil))
923 (define-key menu-bar-showhide-fringe-menu [default]
924 `(menu-item ,(purecopy "Default") menu-bar-showhide-fringe-menu-customize-reset
925 :help ,(purecopy "Default width fringe on both left and right side")
926 :visible (display-graphic-p)
927 :button (:radio . (eq fringe-mode nil))))
929 (defun menu-bar-showhide-fringe-menu-customize-right ()
930 "Display fringes only on the right of each window."
933 (customize-set-variable 'fringe-mode '(0 . nil)))
935 (define-key menu-bar-showhide-fringe-menu [right]
936 `(menu-item ,(purecopy "On the Right") menu-bar-showhide-fringe-menu-customize-right
937 :help ,(purecopy "Fringe only on the right side")
938 :visible (display-graphic-p)
939 :button (:radio . (equal fringe-mode '(0 . nil)))))
941 (defun menu-bar-showhide-fringe-menu-customize-left ()
942 "Display fringes only on the left of each window."
945 (customize-set-variable 'fringe-mode '(nil . 0)))
947 (define-key menu-bar-showhide-fringe-menu [left]
948 `(menu-item ,(purecopy "On the Left") menu-bar-showhide-fringe-menu-customize-left
949 :help ,(purecopy "Fringe only on the left side")
950 :visible (display-graphic-p)
951 :button (:radio . (equal fringe-mode '(nil . 0)))))
953 (defun menu-bar-showhide-fringe-menu-customize-disable ()
954 "Do not display window fringes."
957 (customize-set-variable 'fringe-mode 0))
959 (define-key menu-bar-showhide-fringe-menu [none]
960 `(menu-item ,(purecopy "None") menu-bar-showhide-fringe-menu-customize-disable
961 :help ,(purecopy "Turn off fringe")
962 :visible (display-graphic-p)
963 :button (:radio . (eq fringe-mode 0))))
965 (define-key menu-bar-showhide-menu [showhide-fringe]
966 `(menu-item ,(purecopy "Fringe") ,menu-bar-showhide-fringe-menu
967 :visible (display-graphic-p)))
969 (defvar menu-bar-showhide-scroll-bar-menu (make-sparse-keymap "Scroll-bar"))
971 (define-key menu-bar-showhide-scroll-bar-menu [right]
972 `(menu-item ,(purecopy "On the Right")
973 menu-bar-right-scroll-bar
974 :help ,(purecopy "Scroll-bar on the right side")
975 :visible (display-graphic-p)
976 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
977 (frame-parameters))) 'right))))
978 (defun menu-bar-right-scroll-bar ()
979 "Display scroll bars on the right of each window."
981 (customize-set-variable 'scroll-bar-mode 'right))
983 (define-key menu-bar-showhide-scroll-bar-menu [left]
984 `(menu-item ,(purecopy "On the Left")
985 menu-bar-left-scroll-bar
986 :help ,(purecopy "Scroll-bar on the left side")
987 :visible (display-graphic-p)
988 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
989 (frame-parameters))) 'left))))
991 (defun menu-bar-left-scroll-bar ()
992 "Display scroll bars on the left of each window."
994 (customize-set-variable 'scroll-bar-mode 'left))
996 (define-key menu-bar-showhide-scroll-bar-menu [none]
997 `(menu-item ,(purecopy "None")
998 menu-bar-no-scroll-bar
999 :help ,(purecopy "Turn off scroll-bar")
1000 :visible (display-graphic-p)
1001 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
1002 (frame-parameters))) nil))))
1004 (defun menu-bar-no-scroll-bar ()
1005 "Turn off scroll bars."
1007 (customize-set-variable 'scroll-bar-mode nil))
1009 (define-key menu-bar-showhide-menu [showhide-scroll-bar]
1010 `(menu-item ,(purecopy "Scroll-bar") ,menu-bar-showhide-scroll-bar-menu
1011 :visible (display-graphic-p)))
1013 (define-key menu-bar-showhide-menu [showhide-tooltip-mode]
1014 `(menu-item ,(purecopy "Tooltips") tooltip-mode
1015 :help ,(purecopy "Turn tooltips on/off")
1016 :visible (and (display-graphic-p) (fboundp 'x-show-tip))
1017 :button (:toggle . tooltip-mode)))
1019 (defun menu-bar-frame-for-menubar ()
1020 "Return the frame suitable for updating the menu bar."
1021 (or (and (framep menu-updating-frame)
1022 menu-updating-frame)
1025 (defun menu-bar-positive-p (val)
1026 "Return non-nil iff VAL is a positive number."
1030 (define-key menu-bar-showhide-menu [menu-bar-mode]
1031 `(menu-item ,(purecopy "Menu-bar") toggle-menu-bar-mode-from-frame
1032 :help ,(purecopy "Turn menu-bar on/off")
1034 (:toggle . (menu-bar-positive-p
1035 (frame-parameter (menu-bar-frame-for-menubar)
1036 'menu-bar-lines)))))
1038 (defun menu-bar-set-tool-bar-position (position)
1039 (customize-set-variable 'tool-bar-mode t)
1040 (customize-set-variable 'tool-bar-position position))
1041 (defun menu-bar-showhide-tool-bar-menu-customize-disable ()
1042 "Do not display tool bars."
1044 (customize-set-variable 'tool-bar-mode nil))
1045 (defun menu-bar-showhide-tool-bar-menu-customize-enable-left ()
1046 "Display tool bars on the left side."
1048 (menu-bar-set-tool-bar-position 'left))
1049 (defun menu-bar-showhide-tool-bar-menu-customize-enable-right ()
1050 "Display tool bars on the right side."
1052 (menu-bar-set-tool-bar-position 'right))
1053 (defun menu-bar-showhide-tool-bar-menu-customize-enable-top ()
1054 "Display tool bars on the top side."
1056 (menu-bar-set-tool-bar-position 'top))
1057 (defun menu-bar-showhide-tool-bar-menu-customize-enable-bottom ()
1058 "Display tool bars on the bottom side."
1060 (menu-bar-set-tool-bar-position 'bottom))
1062 (if (featurep 'move-toolbar)
1064 (defvar menu-bar-showhide-tool-bar-menu (make-sparse-keymap "Tool-bar"))
1066 (define-key menu-bar-showhide-tool-bar-menu [showhide-tool-bar-left]
1067 `(menu-item ,(purecopy "On the left")
1068 menu-bar-showhide-tool-bar-menu-customize-enable-left
1069 :help ,(purecopy "Tool-bar at the left side")
1070 :visible (display-graphic-p)
1072 (:radio . (and tool-bar-mode
1073 (eq (frame-parameter
1074 (menu-bar-frame-for-menubar)
1078 (define-key menu-bar-showhide-tool-bar-menu [showhide-tool-bar-right]
1079 `(menu-item ,(purecopy "On the right")
1080 menu-bar-showhide-tool-bar-menu-customize-enable-right
1081 :help ,(purecopy "Tool-bar at the right side")
1082 :visible (display-graphic-p)
1084 (:radio . (and tool-bar-mode
1085 (eq (frame-parameter
1086 (menu-bar-frame-for-menubar)
1090 (define-key menu-bar-showhide-tool-bar-menu [showhide-tool-bar-bottom]
1091 `(menu-item ,(purecopy "On the bottom")
1092 menu-bar-showhide-tool-bar-menu-customize-enable-bottom
1093 :help ,(purecopy "Tool-bar at the bottom")
1094 :visible (display-graphic-p)
1096 (:radio . (and tool-bar-mode
1097 (eq (frame-parameter
1098 (menu-bar-frame-for-menubar)
1102 (define-key menu-bar-showhide-tool-bar-menu [showhide-tool-bar-top]
1103 `(menu-item ,(purecopy "On the top")
1104 menu-bar-showhide-tool-bar-menu-customize-enable-top
1105 :help ,(purecopy "Tool-bar at the top")
1106 :visible (display-graphic-p)
1108 (:radio . (and tool-bar-mode
1109 (eq (frame-parameter
1110 (menu-bar-frame-for-menubar)
1114 (define-key menu-bar-showhide-tool-bar-menu [showhide-tool-bar-none]
1115 `(menu-item ,(purecopy "None")
1116 menu-bar-showhide-tool-bar-menu-customize-disable
1117 :help ,(purecopy "Turn tool-bar off")
1118 :visible (display-graphic-p)
1119 :button (:radio . (eq tool-bar-mode nil))))
1121 (define-key menu-bar-showhide-menu [showhide-tool-bar]
1122 `(menu-item ,(purecopy "Tool-bar") ,menu-bar-showhide-tool-bar-menu
1123 :visible (display-graphic-p)))
1126 ;; else not tool bar that can move.
1127 (define-key menu-bar-showhide-menu [showhide-tool-bar]
1128 `(menu-item ,(purecopy "Tool-bar") toggle-tool-bar-mode-from-frame
1129 :help ,(purecopy "Turn tool-bar on/off")
1130 :visible (display-graphic-p)
1132 (:toggle . (menu-bar-positive-p
1133 (frame-parameter (menu-bar-frame-for-menubar)
1134 'tool-bar-lines))))))
1136 (define-key menu-bar-options-menu [showhide]
1137 `(menu-item ,(purecopy "Show/Hide") ,menu-bar-showhide-menu))
1139 (define-key menu-bar-options-menu [showhide-separator]
1142 (define-key menu-bar-options-menu [mule]
1143 ;; It is better not to use backquote here,
1144 ;; because that makes a bootstrapping problem
1145 ;; if you need to recompile all the Lisp files using interpreted code.
1146 `(menu-item ,(purecopy "Multilingual Environment") ,mule-menu-keymap
1147 ;; Most of the MULE menu actually does make sense in unibyte mode,
1148 ;; e.g. language selection.
1149 ;;; :visible '(default-value 'enable-multibyte-characters)
1151 ;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
1152 ;(define-key menu-bar-options-menu [preferences]
1153 ; `(menu-item ,(purecopy "Preferences") ,menu-bar-preferences-menu
1154 ; :help ,(purecopy "Toggle important global options")))
1156 (define-key menu-bar-options-menu [mule-separator]
1159 (define-key menu-bar-options-menu [debug-on-quit]
1160 (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
1161 "Enter Debugger on Quit/C-g" "Debug on Quit %s"
1162 "Enter Lisp debugger when C-g is pressed"))
1163 (define-key menu-bar-options-menu [debug-on-error]
1164 (menu-bar-make-toggle toggle-debug-on-error debug-on-error
1165 "Enter Debugger on Error" "Debug on Error %s"
1166 "Enter Lisp debugger when an error is signaled"))
1167 (define-key menu-bar-options-menu [debugger-separator]
1170 (define-key menu-bar-options-menu [blink-cursor-mode]
1171 (menu-bar-make-mm-toggle blink-cursor-mode
1173 "Whether the cursor blinks (Blink Cursor mode)"))
1174 (define-key menu-bar-options-menu [cursor-separator]
1177 (define-key menu-bar-options-menu [save-place]
1178 (menu-bar-make-toggle toggle-save-place-globally save-place
1179 "Save Place in Files between Sessions"
1180 "Saving place in files %s"
1181 "Visit files of previous session when restarting Emacs"
1182 (require 'saveplace)
1183 ;; Do it by name, to avoid a free-variable
1184 ;; warning during byte compilation.
1186 'save-place (not (symbol-value 'save-place)))))
1188 (define-key menu-bar-options-menu [uniquify]
1189 (menu-bar-make-toggle toggle-uniquify-buffer-names uniquify-buffer-name-style
1190 "Use Directory Names in Buffer Names"
1191 "Directory name in buffer names (uniquify) %s"
1192 "Uniquify buffer names by adding parent directory names"
1194 (setq uniquify-buffer-name-style
1195 (if (not uniquify-buffer-name-style)
1198 (define-key menu-bar-options-menu [edit-options-separator]
1200 (define-key menu-bar-options-menu [cua-mode]
1201 (menu-bar-make-mm-toggle cua-mode
1202 "C-x/C-c/C-v Cut and Paste (CUA)"
1203 "Use C-z/C-x/C-c/C-v keys for undo/cut/copy/paste"
1204 (:visible (or (not (boundp 'cua-enable-cua-keys))
1205 cua-enable-cua-keys))))
1207 (define-key menu-bar-options-menu [cua-emulation-mode]
1208 (menu-bar-make-mm-toggle cua-mode
1209 "Shift movement mark region (CUA)"
1210 "Use shifted movement keys to set and extend the region"
1211 (:visible (and (boundp 'cua-enable-cua-keys)
1212 (not cua-enable-cua-keys)))))
1214 (define-key menu-bar-options-menu [case-fold-search]
1215 (menu-bar-make-toggle toggle-case-fold-search case-fold-search
1216 "Case-Insensitive Search"
1217 "Case-Insensitive Search %s"
1218 "Ignore letter-case in search commands"))
1220 (defun menu-bar-text-mode-auto-fill ()
1222 (toggle-text-mode-auto-fill)
1223 ;; This is somewhat questionable, as `text-mode-hook'
1224 ;; might have changed outside customize.
1225 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
1226 (customize-mark-as-set 'text-mode-hook))
1228 (define-key menu-bar-options-menu [auto-fill-mode]
1229 `(menu-item ,(purecopy "Auto Fill in Text Modes")
1230 menu-bar-text-mode-auto-fill
1231 :help ,(purecopy "Automatically fill text while typing (Auto Fill mode)")
1232 :button (:toggle . (if (listp text-mode-hook)
1233 (member 'turn-on-auto-fill text-mode-hook)
1234 (eq 'turn-on-auto-fill text-mode-hook)))))
1237 (defvar menu-bar-line-wrapping-menu (make-sparse-keymap "Line Wrapping"))
1239 (define-key menu-bar-line-wrapping-menu [word-wrap]
1240 `(menu-item ,(purecopy "Word Wrap (Visual Line mode)")
1243 (unless visual-line-mode
1244 (visual-line-mode 1))
1245 (message ,(purecopy "Visual-Line mode enabled")))
1246 :help ,(purecopy "Wrap long lines at word boundaries")
1247 :button (:radio . (and (null truncate-lines)
1248 (not (truncated-partial-width-window-p))
1250 :visible (menu-bar-menu-frame-live-and-visible-p)))
1252 (define-key menu-bar-line-wrapping-menu [truncate]
1253 `(menu-item ,(purecopy "Truncate Long Lines")
1256 (if visual-line-mode (visual-line-mode 0))
1257 (setq word-wrap nil)
1258 (toggle-truncate-lines 1))
1259 :help ,(purecopy "Truncate long lines at window edge")
1260 :button (:radio . (or truncate-lines
1261 (truncated-partial-width-window-p)))
1262 :visible (menu-bar-menu-frame-live-and-visible-p)
1263 :enable (not (truncated-partial-width-window-p))))
1265 (define-key menu-bar-line-wrapping-menu [window-wrap]
1266 `(menu-item ,(purecopy "Wrap at Window Edge")
1267 (lambda () (interactive)
1268 (if visual-line-mode (visual-line-mode 0))
1269 (setq word-wrap nil)
1270 (if truncate-lines (toggle-truncate-lines -1)))
1271 :help ,(purecopy "Wrap long lines at window edge")
1272 :button (:radio . (and (null truncate-lines)
1273 (not (truncated-partial-width-window-p))
1275 :visible (menu-bar-menu-frame-live-and-visible-p)
1276 :enable (not (truncated-partial-width-window-p))))
1278 (define-key menu-bar-options-menu [line-wrapping]
1279 `(menu-item ,(purecopy "Line Wrapping in this Buffer") ,menu-bar-line-wrapping-menu))
1282 (define-key menu-bar-options-menu [highlight-separator]
1284 (define-key menu-bar-options-menu [highlight-paren-mode]
1285 (menu-bar-make-mm-toggle show-paren-mode
1286 "Paren Match Highlighting"
1287 "Highlight matching/mismatched parentheses at cursor (Show Paren mode)"))
1288 (define-key menu-bar-options-menu [transient-mark-mode]
1289 (menu-bar-make-mm-toggle transient-mark-mode
1290 "Active Region Highlighting"
1291 "Make text in active region stand out in color (Transient Mark mode)"
1292 (:enable (not cua-mode))))
1295 ;; The "Tools" menu items
1297 (defun send-mail-item-name ()
1298 (let* ((known-send-mail-commands '((sendmail-user-agent . "sendmail")
1299 (mh-e-user-agent . "MH")
1300 (message-user-agent . "Gnus Message")
1301 (gnus-user-agent . "Gnus")))
1302 (name (assq mail-user-agent known-send-mail-commands)))
1304 (setq name (cdr name))
1305 (setq name (symbol-name mail-user-agent))
1306 (if (string-match "\\(.+\\)-user-agent" name)
1307 (setq name (match-string 1 name))))
1310 (defun read-mail-item-name ()
1311 (let* ((known-rmail-commands '((rmail . "RMAIL")
1314 (known (assq read-mail-command known-rmail-commands)))
1315 (if known (cdr known) (symbol-name read-mail-command))))
1317 (defvar menu-bar-games-menu (make-sparse-keymap "Games"))
1319 (define-key menu-bar-tools-menu [games]
1320 `(menu-item ,(purecopy "Games") ,menu-bar-games-menu))
1322 (define-key menu-bar-tools-menu [separator-games]
1325 (define-key menu-bar-games-menu [zone]
1326 `(menu-item ,(purecopy "Zone Out") zone
1327 :help ,(purecopy "Play tricks with Emacs display when Emacs is idle")))
1328 (define-key menu-bar-games-menu [tetris]
1329 `(menu-item ,(purecopy "Tetris") tetris
1330 :help ,(purecopy "Falling blocks game")))
1331 (define-key menu-bar-games-menu [solitaire]
1332 `(menu-item ,(purecopy "Solitaire") solitaire
1333 :help ,(purecopy "Get rid of all the stones")))
1334 (define-key menu-bar-games-menu [snake]
1335 `(menu-item ,(purecopy "Snake") snake
1336 :help ,(purecopy "Move snake around avoiding collisions")))
1337 (define-key menu-bar-games-menu [pong]
1338 `(menu-item ,(purecopy "Pong") pong
1339 :help ,(purecopy "Bounce the ball to your opponent")))
1340 (define-key menu-bar-games-menu [mult]
1341 `(menu-item ,(purecopy "Multiplication Puzzle") mpuz
1342 :help ,(purecopy "Exercise brain with multiplication")))
1343 (define-key menu-bar-games-menu [life]
1344 `(menu-item ,(purecopy "Life") life
1345 :help ,(purecopy "Watch how John Conway's cellular automaton evolves")))
1346 (define-key menu-bar-games-menu [land]
1347 `(menu-item ,(purecopy "Landmark") landmark
1348 :help ,(purecopy "Watch a neural-network robot learn landmarks")))
1349 (define-key menu-bar-games-menu [hanoi]
1350 `(menu-item ,(purecopy "Towers of Hanoi") hanoi
1351 :help ,(purecopy "Watch Towers-of-Hanoi puzzle solved by Emacs")))
1352 (define-key menu-bar-games-menu [gomoku]
1353 `(menu-item ,(purecopy "Gomoku") gomoku
1354 :help ,(purecopy "Mark 5 contiguous squares (like tic-tac-toe)")))
1355 (define-key menu-bar-games-menu [bubbles]
1356 `(menu-item ,(purecopy "Bubbles") bubbles
1357 :help ,(purecopy "Remove all bubbles using the fewest moves")))
1358 (define-key menu-bar-games-menu [black-box]
1359 `(menu-item ,(purecopy "Blackbox") blackbox
1360 :help ,(purecopy "Find balls in a black box by shooting rays")))
1361 (define-key menu-bar-games-menu [adventure]
1362 `(menu-item ,(purecopy "Adventure") dunnet
1363 :help ,(purecopy "Dunnet, a text Adventure game for Emacs")))
1364 (define-key menu-bar-games-menu [5x5]
1365 `(menu-item ,(purecopy "5x5") 5x5
1366 :help ,(purecopy "Fill in all the squares on a 5x5 board")))
1368 (defvar menu-bar-encryption-decryption-menu
1369 (make-sparse-keymap "Encryption/Decryption"))
1371 (define-key menu-bar-tools-menu [encryption-decryption]
1372 `(menu-item ,(purecopy "Encryption/Decryption") ,menu-bar-encryption-decryption-menu))
1374 (define-key menu-bar-tools-menu [separator-encryption-decryption]
1377 (define-key menu-bar-encryption-decryption-menu [insert-keys]
1378 `(menu-item ,(purecopy "Insert Keys") epa-insert-keys
1379 :help ,(purecopy "Insert public keys after the current point")))
1381 (define-key menu-bar-encryption-decryption-menu [export-keys]
1382 `(menu-item ,(purecopy "Export Keys") epa-export-keys
1383 :help ,(purecopy "Export public keys to a file")))
1385 (define-key menu-bar-encryption-decryption-menu [import-keys-region]
1386 `(menu-item ,(purecopy "Import Keys from Region") epa-import-keys-region
1387 :help ,(purecopy "Import public keys from the current region")))
1389 (define-key menu-bar-encryption-decryption-menu [import-keys]
1390 `(menu-item ,(purecopy "Import Keys from File...") epa-import-keys
1391 :help ,(purecopy "Import public keys from a file")))
1393 (define-key menu-bar-encryption-decryption-menu [list-keys]
1394 `(menu-item ,(purecopy "List Keys") epa-list-keys
1395 :help ,(purecopy "Browse your public keyring")))
1397 (define-key menu-bar-encryption-decryption-menu [separator-keys]
1400 (define-key menu-bar-encryption-decryption-menu [sign-region]
1401 `(menu-item ,(purecopy "Sign Region") epa-sign-region
1402 :help ,(purecopy "Create digital signature of the current region")))
1404 (define-key menu-bar-encryption-decryption-menu [verify-region]
1405 `(menu-item ,(purecopy "Verify Region") epa-verify-region
1406 :help ,(purecopy "Verify digital signature of the current region")))
1408 (define-key menu-bar-encryption-decryption-menu [encrypt-region]
1409 `(menu-item ,(purecopy "Encrypt Region") epa-encrypt-region
1410 :help ,(purecopy "Encrypt the current region")))
1412 (define-key menu-bar-encryption-decryption-menu [decrypt-region]
1413 `(menu-item ,(purecopy "Decrypt Region") epa-decrypt-region
1414 :help ,(purecopy "Decrypt the current region")))
1416 (define-key menu-bar-encryption-decryption-menu [separator-file]
1419 (define-key menu-bar-encryption-decryption-menu [sign-file]
1420 `(menu-item ,(purecopy "Sign File...") epa-sign-file
1421 :help ,(purecopy "Create digital signature of a file")))
1423 (define-key menu-bar-encryption-decryption-menu [verify-file]
1424 `(menu-item ,(purecopy "Verify File...") epa-verify-file
1425 :help ,(purecopy "Verify digital signature of a file")))
1427 (define-key menu-bar-encryption-decryption-menu [encrypt-file]
1428 `(menu-item ,(purecopy "Encrypt File...") epa-encrypt-file
1429 :help ,(purecopy "Encrypt a file")))
1431 (define-key menu-bar-encryption-decryption-menu [decrypt-file]
1432 `(menu-item ,(purecopy "Decrypt File...") epa-decrypt-file
1433 :help ,(purecopy "Decrypt a file")))
1435 (define-key menu-bar-tools-menu [simple-calculator]
1436 `(menu-item ,(purecopy "Simple Calculator") calculator
1437 :help ,(purecopy "Invoke the Emacs built-in quick calculator")))
1438 (define-key menu-bar-tools-menu [calc]
1439 `(menu-item ,(purecopy "Programmable Calculator") calc
1440 :help ,(purecopy "Invoke the Emacs built-in full scientific calculator")))
1441 (define-key menu-bar-tools-menu [calendar]
1442 `(menu-item ,(purecopy "Calendar") calendar
1443 :help ,(purecopy "Invoke the Emacs built-in calendar")))
1445 (define-key menu-bar-tools-menu [separator-net]
1448 (define-key menu-bar-tools-menu [directory-search]
1449 `(menu-item ,(purecopy "Directory Search") eudc-tools-menu))
1450 (define-key menu-bar-tools-menu [compose-mail]
1451 `(menu-item (format "Send Mail (with %s)" (send-mail-item-name)) compose-mail
1452 :visible (and mail-user-agent (not (eq mail-user-agent 'ignore)))
1453 :help ,(purecopy "Send a mail message")))
1454 (define-key menu-bar-tools-menu [rmail]
1455 `(menu-item (format "Read Mail (with %s)" (read-mail-item-name))
1457 :visible (and read-mail-command
1458 (not (eq read-mail-command 'ignore)))
1459 :help ,(purecopy "Read your mail and reply to it")))
1461 (defun menu-bar-read-mail ()
1462 "Read mail using `read-mail-command'."
1464 (call-interactively read-mail-command))
1466 (define-key menu-bar-tools-menu [gnus]
1467 `(menu-item ,(purecopy "Read Net News (Gnus)") gnus
1468 :help ,(purecopy "Read network news groups")))
1470 (define-key menu-bar-tools-menu [separator-vc]
1473 (define-key menu-bar-tools-menu [pcl-cvs]
1474 `(menu-item ,(purecopy "PCL-CVS") cvs-global-menu))
1475 (define-key menu-bar-tools-menu [vc] nil) ;Create the place for the VC menu.
1477 (define-key menu-bar-tools-menu [separator-compare]
1480 (define-key menu-bar-tools-menu [epatch]
1481 `(menu-item ,(purecopy "Apply Patch") menu-bar-epatch-menu))
1482 (define-key menu-bar-tools-menu [ediff-merge]
1483 `(menu-item ,(purecopy "Merge") menu-bar-ediff-merge-menu))
1484 (define-key menu-bar-tools-menu [compare]
1485 `(menu-item ,(purecopy "Compare (Ediff)") menu-bar-ediff-menu))
1487 (define-key menu-bar-tools-menu [separator-spell]
1490 (define-key menu-bar-tools-menu [spell]
1491 `(menu-item ,(purecopy "Spell Checking") ispell-menu-map))
1493 (define-key menu-bar-tools-menu [separator-prog]
1496 (define-key menu-bar-tools-menu [semantic]
1497 `(menu-item ,(purecopy "Source Code Parsers (Semantic)")
1499 :help ,(purecopy "Toggle automatic parsing in source code buffers (Semantic mode)")
1500 :button (:toggle . (bound-and-true-p semantic-mode))))
1502 (define-key menu-bar-tools-menu [ede]
1503 `(menu-item ,(purecopy "Project support (EDE)")
1505 :help ,(purecopy "Toggle the Emacs Development Environment (Global EDE mode)")
1506 :button (:toggle . (bound-and-true-p global-ede-mode))))
1508 (define-key menu-bar-tools-menu [gdb]
1509 `(menu-item ,(purecopy "Debugger (GDB)...") gdb
1510 :help ,(purecopy "Debug a program from within Emacs with GDB")))
1511 (define-key menu-bar-tools-menu [shell-on-region]
1512 `(menu-item ,(purecopy "Shell Command on Region...") shell-command-on-region
1514 :help ,(purecopy "Pass marked region to a shell command")))
1515 (define-key menu-bar-tools-menu [shell]
1516 `(menu-item ,(purecopy "Shell Command...") shell-command
1517 :help ,(purecopy "Invoke a shell command and catch its output")))
1518 (define-key menu-bar-tools-menu [compile]
1519 `(menu-item ,(purecopy "Compile...") compile
1520 :help ,(purecopy "Invoke compiler or Make, view compilation errors")))
1521 (define-key menu-bar-tools-menu [grep]
1522 `(menu-item ,(purecopy "Search Files (Grep)...") grep
1523 :help ,(purecopy "Search files for strings or regexps (with Grep)")))
1526 ;; The "Help" menu items
1528 (defvar menu-bar-describe-menu (make-sparse-keymap "Describe"))
1530 (define-key menu-bar-describe-menu [mule-diag]
1531 `(menu-item ,(purecopy "Show All of Mule Status") mule-diag
1532 :visible (default-value 'enable-multibyte-characters)
1533 :help ,(purecopy "Display multilingual environment settings")))
1534 (define-key menu-bar-describe-menu [describe-coding-system-briefly]
1535 `(menu-item ,(purecopy "Describe Coding System (Briefly)")
1536 describe-current-coding-system-briefly
1537 :visible (default-value 'enable-multibyte-characters)))
1538 (define-key menu-bar-describe-menu [describe-coding-system]
1539 `(menu-item ,(purecopy "Describe Coding System...") describe-coding-system
1540 :visible (default-value 'enable-multibyte-characters)))
1541 (define-key menu-bar-describe-menu [describe-input-method]
1542 `(menu-item ,(purecopy "Describe Input Method...") describe-input-method
1543 :visible (default-value 'enable-multibyte-characters)
1544 :help ,(purecopy "Keyboard layout for specific input method")))
1545 (define-key menu-bar-describe-menu [describe-language-environment]
1546 `(menu-item ,(purecopy "Describe Language Environment")
1547 ,describe-language-environment-map))
1549 (define-key menu-bar-describe-menu [separator-desc-mule]
1552 (define-key menu-bar-describe-menu [list-keybindings]
1553 `(menu-item ,(purecopy "List Key Bindings") describe-bindings
1554 :help ,(purecopy "Display all current key bindings (keyboard shortcuts)")))
1555 (define-key menu-bar-describe-menu [describe-current-display-table]
1556 `(menu-item ,(purecopy "Describe Display Table") describe-current-display-table
1557 :help ,(purecopy "Describe the current display table")))
1558 (define-key menu-bar-describe-menu [describe-package]
1559 `(menu-item ,(purecopy "Describe Package...") describe-package
1560 :help ,(purecopy "Display documentation of a Lisp package")))
1561 (define-key menu-bar-describe-menu [describe-face]
1562 `(menu-item ,(purecopy "Describe Face...") describe-face
1563 :help ,(purecopy "Display the properties of a face")))
1564 (define-key menu-bar-describe-menu [describe-variable]
1565 `(menu-item ,(purecopy "Describe Variable...") describe-variable
1566 :help ,(purecopy "Display documentation of variable/option")))
1567 (define-key menu-bar-describe-menu [describe-function]
1568 `(menu-item ,(purecopy "Describe Function...") describe-function
1569 :help ,(purecopy "Display documentation of function/command")))
1570 (define-key menu-bar-describe-menu [describe-key-1]
1571 `(menu-item ,(purecopy "Describe Key or Mouse Operation...") describe-key
1572 ;; Users typically don't identify keys and menu items...
1573 :help ,(purecopy "Display documentation of command bound to a \
1574 key, a click, or a menu-item")))
1575 (define-key menu-bar-describe-menu [describe-mode]
1576 `(menu-item ,(purecopy "Describe Buffer Modes") describe-mode
1577 :help ,(purecopy "Describe this buffer's major and minor mode")))
1579 (defvar menu-bar-search-documentation-menu
1580 (make-sparse-keymap "Search Documentation"))
1581 (defun menu-bar-read-lispref ()
1582 "Display the Emacs Lisp Reference manual in Info mode."
1586 (defun menu-bar-read-lispintro ()
1587 "Display the Introduction to Emacs Lisp Programming in Info mode."
1591 (defun search-emacs-glossary ()
1592 "Display the Glossary node of the Emacs manual in Info mode."
1594 (info "(emacs)Glossary"))
1596 (defun emacs-index-search (topic)
1597 "Look up TOPIC in the indices of the Emacs User Manual."
1598 (interactive "sSubject to look up: ")
1602 (defun elisp-index-search (topic)
1603 "Look up TOPIC in the indices of the Emacs Lisp Reference Manual."
1604 (interactive "sSubject to look up: ")
1608 (define-key menu-bar-search-documentation-menu [search-documentation-strings]
1609 `(menu-item ,(purecopy "Search Documentation Strings...") apropos-documentation
1611 ,(purecopy "Find functions and variables whose doc strings match a regexp")))
1612 (define-key menu-bar-search-documentation-menu [find-any-object-by-name]
1613 `(menu-item ,(purecopy "Find Any Object by Name...") apropos
1614 :help ,(purecopy "Find symbols of any kind whose names match a regexp")))
1615 (define-key menu-bar-search-documentation-menu [find-option-by-value]
1616 `(menu-item ,(purecopy "Find Options by Value...") apropos-value
1617 :help ,(purecopy "Find variables whose values match a regexp")))
1618 (define-key menu-bar-search-documentation-menu [find-options-by-name]
1619 `(menu-item ,(purecopy "Find Options by Name...") apropos-variable
1620 :help ,(purecopy "Find variables whose names match a regexp")))
1621 (define-key menu-bar-search-documentation-menu [find-commands-by-name]
1622 `(menu-item ,(purecopy "Find Commands by Name...") apropos-command
1623 :help ,(purecopy "Find commands whose names match a regexp")))
1624 (define-key menu-bar-search-documentation-menu [sep1]
1626 (define-key menu-bar-search-documentation-menu [lookup-command-in-manual]
1627 `(menu-item ,(purecopy "Look Up Command in User Manual...") Info-goto-emacs-command-node
1628 :help ,(purecopy "Display manual section that describes a command")))
1629 (define-key menu-bar-search-documentation-menu [lookup-key-in-manual]
1630 `(menu-item ,(purecopy "Look Up Key in User Manual...") Info-goto-emacs-key-command-node
1631 :help ,(purecopy "Display manual section that describes a key")))
1632 (define-key menu-bar-search-documentation-menu [lookup-subject-in-elisp-manual]
1633 `(menu-item ,(purecopy "Look Up Subject in ELisp Manual...") elisp-index-search
1634 :help ,(purecopy "Find description of a subject in Emacs Lisp manual")))
1635 (define-key menu-bar-search-documentation-menu [lookup-subject-in-emacs-manual]
1636 `(menu-item ,(purecopy "Look Up Subject in User Manual...") emacs-index-search
1637 :help ,(purecopy "Find description of a subject in Emacs User manual")))
1638 (define-key menu-bar-search-documentation-menu [emacs-terminology]
1639 `(menu-item ,(purecopy "Emacs Terminology") search-emacs-glossary
1640 :help ,(purecopy "Display the Glossary section of the Emacs manual")))
1642 (defvar menu-bar-manuals-menu (make-sparse-keymap "More Manuals"))
1644 (define-key menu-bar-manuals-menu [man]
1645 `(menu-item ,(purecopy "Read Man Page...") manual-entry
1646 :help ,(purecopy "Man-page docs for external commands and libraries")))
1647 (define-key menu-bar-manuals-menu [sep2]
1649 (define-key menu-bar-manuals-menu [order-emacs-manuals]
1650 `(menu-item ,(purecopy "Ordering Manuals") view-order-manuals
1651 :help ,(purecopy "How to order manuals from the Free Software Foundation")))
1652 (define-key menu-bar-manuals-menu [lookup-subject-in-all-manuals]
1653 `(menu-item ,(purecopy "Lookup Subject in all Manuals...") info-apropos
1654 :help ,(purecopy "Find description of a subject in all installed manuals")))
1655 (define-key menu-bar-manuals-menu [other-manuals]
1656 `(menu-item ,(purecopy "All Other Manuals (Info)") Info-directory
1657 :help ,(purecopy "Read any of the installed manuals")))
1658 (define-key menu-bar-manuals-menu [emacs-lisp-reference]
1659 `(menu-item ,(purecopy "Emacs Lisp Reference") menu-bar-read-lispref
1660 :help ,(purecopy "Read the Emacs Lisp Reference manual")))
1661 (define-key menu-bar-manuals-menu [emacs-lisp-intro]
1662 `(menu-item ,(purecopy "Introduction to Emacs Lisp") menu-bar-read-lispintro
1663 :help ,(purecopy "Read the Introduction to Emacs Lisp Programming")))
1665 (define-key menu-bar-help-menu [about-gnu-project]
1666 `(menu-item ,(purecopy "About GNU") describe-gnu-project
1667 :help ,(purecopy "About the GNU System, GNU Project, and GNU/Linux")))
1668 (define-key menu-bar-help-menu [about-emacs]
1669 `(menu-item ,(purecopy "About Emacs") about-emacs
1670 :help ,(purecopy "Display version number, copyright info, and basic help")))
1671 (define-key menu-bar-help-menu [sep4]
1673 (define-key menu-bar-help-menu [describe-no-warranty]
1674 `(menu-item ,(purecopy "(Non)Warranty") describe-no-warranty
1675 :help ,(purecopy "Explain that Emacs has NO WARRANTY")))
1676 (define-key menu-bar-help-menu [describe-copying]
1677 `(menu-item ,(purecopy "Copying Conditions") describe-copying
1678 :help ,(purecopy "Show the Emacs license (GPL)")))
1679 (define-key menu-bar-help-menu [getting-new-versions]
1680 `(menu-item ,(purecopy "Getting New Versions") describe-distribution
1681 :help ,(purecopy "How to get the latest version of Emacs")))
1682 (defun menu-bar-help-extra-packages ()
1683 "Display help about some additional packages available for Emacs."
1685 (let (enable-local-variables)
1686 (view-file (expand-file-name "MORE.STUFF"
1688 (goto-address-mode 1)))
1689 (define-key menu-bar-help-menu [sep2]
1691 (define-key menu-bar-help-menu [external-packages]
1692 `(menu-item ,(purecopy "Finding Extra Packages") menu-bar-help-extra-packages
1693 :help ,(purecopy "Lisp packages distributed separately for use in Emacs")))
1694 (define-key menu-bar-help-menu [find-emacs-packages]
1695 `(menu-item ,(purecopy "Search Built-in Packages") finder-by-keyword
1696 :help ,(purecopy "Find built-in packages and features by keyword")))
1697 (define-key menu-bar-help-menu [more-manuals]
1698 `(menu-item ,(purecopy "More Manuals") ,menu-bar-manuals-menu))
1699 (define-key menu-bar-help-menu [emacs-manual]
1700 `(menu-item ,(purecopy "Read the Emacs Manual") info-emacs-manual
1701 :help ,(purecopy "Full documentation of Emacs features")))
1702 (define-key menu-bar-help-menu [describe]
1703 `(menu-item ,(purecopy "Describe") ,menu-bar-describe-menu))
1704 (define-key menu-bar-help-menu [search-documentation]
1705 `(menu-item ,(purecopy "Search Documentation") ,menu-bar-search-documentation-menu))
1706 (define-key menu-bar-help-menu [sep1]
1708 (define-key menu-bar-help-menu [emacs-psychotherapist]
1709 `(menu-item ,(purecopy "Emacs Psychotherapist") doctor
1710 :help ,(purecopy "Our doctor will help you feel better")))
1711 (define-key menu-bar-help-menu [send-emacs-bug-report]
1712 `(menu-item ,(purecopy "Send Bug Report...") report-emacs-bug
1713 :help ,(purecopy "Send e-mail to Emacs maintainers")))
1714 (define-key menu-bar-help-menu [emacs-known-problems]
1715 `(menu-item ,(purecopy "Emacs Known Problems") view-emacs-problems
1716 :help ,(purecopy "Read about known problems with Emacs")))
1717 (define-key menu-bar-help-menu [emacs-news]
1718 `(menu-item ,(purecopy "Emacs News") view-emacs-news
1719 :help ,(purecopy "New features of this version")))
1720 (define-key menu-bar-help-menu [emacs-faq]
1721 `(menu-item ,(purecopy "Emacs FAQ") view-emacs-FAQ
1722 :help ,(purecopy "Frequently asked (and answered) questions about Emacs")))
1724 (defun help-with-tutorial-spec-language ()
1725 "Use the Emacs tutorial, specifying which language you want."
1727 (help-with-tutorial t))
1729 (define-key menu-bar-help-menu [emacs-tutorial-language-specific]
1730 `(menu-item ,(purecopy "Emacs Tutorial (choose language)...")
1731 help-with-tutorial-spec-language
1732 :help ,(purecopy "Learn how to use Emacs (choose a language)")))
1733 (define-key menu-bar-help-menu [emacs-tutorial]
1734 `(menu-item ,(purecopy "Emacs Tutorial") help-with-tutorial
1735 :help ,(purecopy "Learn how to use Emacs")))
1737 ;; In OS X it's in the app menu already.
1738 ;; FIXME? There already is an "About Emacs" (sans ...) entry in the Help menu.
1740 (not (eq system-type 'darwin))
1741 (define-key menu-bar-help-menu [info-panel]
1742 `(menu-item ,(purecopy "About Emacs...") ns-do-emacs-info-panel)))
1744 (defun menu-bar-menu-frame-live-and-visible-p ()
1745 "Return non-nil if the menu frame is alive and visible.
1746 The menu frame is the frame for which we are updating the menu."
1747 (let ((menu-frame (or menu-updating-frame (selected-frame))))
1748 (and (frame-live-p menu-frame)
1749 (frame-visible-p menu-frame))))
1751 (defun menu-bar-non-minibuffer-window-p ()
1752 "Return non-nil if selected window of the menu frame is not a minibuf window.
1754 See the documentation of `menu-bar-menu-frame-live-and-visible-p'
1755 for the definition of the menu frame."
1756 (let ((menu-frame (or menu-updating-frame (selected-frame))))
1757 (not (window-minibuffer-p (frame-selected-window menu-frame)))))
1759 (defun kill-this-buffer () ; for the menu bar
1760 "Kill the current buffer.
1761 When called in the minibuffer, get out of the minibuffer
1762 using `abort-recursive-edit'."
1764 (if (menu-bar-non-minibuffer-window-p)
1765 (kill-buffer (current-buffer))
1766 (abort-recursive-edit)))
1768 (defun kill-this-buffer-enabled-p ()
1770 (buffers (buffer-list)))
1772 (or (string-match "^ " (buffer-name (car buffers)))
1773 (setq count (1+ count)))
1774 (setq buffers (cdr buffers)))
1775 (or (not (menu-bar-non-minibuffer-window-p))
1778 (put 'dired 'menu-enable '(menu-bar-non-minibuffer-window-p))
1780 ;; Permit deleting frame if it would leave a visible or iconified frame.
1781 (defun delete-frame-enabled-p ()
1782 "Return non-nil if `delete-frame' should be enabled in the menu bar."
1783 (let ((frames (frame-list))
1786 (if (frame-visible-p (car frames))
1787 (setq count (1+ count)))
1788 (setq frames (cdr frames)))
1791 (defcustom yank-menu-length 20
1792 "Maximum length to display in the yank-menu."
1796 (defun menu-bar-update-yank-menu (string old)
1797 (let ((front (car (cdr yank-menu)))
1798 (menu-string (if (<= (length string) yank-menu-length)
1801 (substring string 0 (/ yank-menu-length 2))
1803 (substring string (- (/ yank-menu-length 2)))))))
1804 ;; Don't let the menu string be all dashes
1805 ;; because that has a special meaning in a menu.
1806 (if (string-match "\\`-+\\'" menu-string)
1807 (setq menu-string (concat menu-string " ")))
1808 ;; If we're supposed to be extending an existing string, and that
1809 ;; string really is at the front of the menu, then update it in place.
1810 (if (and old (or (eq old (car front))
1811 (string= old (car front))))
1813 (setcar front string)
1814 (setcar (cdr front) menu-string))
1817 (cons string (cons menu-string 'menu-bar-select-yank))
1819 (if (> (length (cdr yank-menu)) kill-ring-max)
1820 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
1822 (put 'menu-bar-select-yank 'apropos-inhibit t)
1823 (defun menu-bar-select-yank ()
1824 "Insert the stretch of previously-killed text selected from menu.
1825 The menu shows all the killed text sequences stored in `kill-ring'."
1828 (insert last-command-event))
1833 (defcustom buffers-menu-max-size 10
1834 "Maximum number of entries which may appear on the Buffers menu.
1835 If this is 10, then only the ten most-recently-selected buffers are shown.
1836 If this is nil, then all buffers are shown.
1837 A large number or nil slows down menu responsiveness."
1838 :type '(choice integer
1839 (const :tag "All" nil))
1842 (defcustom buffers-menu-buffer-name-length 30
1843 "Maximum length of the buffer name on the Buffers menu.
1844 If this is a number, then buffer names are truncated to this length.
1845 If this is nil, then buffer names are shown in full.
1846 A large number or nil makes the menu too wide."
1847 :type '(choice integer
1848 (const :tag "Full length" nil))
1851 (defcustom buffers-menu-show-directories 'unless-uniquify
1852 "If non-nil, show directories in the Buffers menu for buffers that have them.
1853 The special value `unless-uniquify' means that directories will be shown
1854 unless `uniquify-buffer-name-style' is non-nil (in which case, buffer
1855 names should include enough of a buffer's directory to distinguish it
1856 from other buffers).
1858 Setting this variable directly does not take effect until next time the
1859 Buffers menu is regenerated."
1860 :set (lambda (symbol value)
1862 (menu-bar-update-buffers t))
1863 :initialize 'custom-initialize-default
1864 :type '(choice (const :tag "Never" nil)
1865 (const :tag "Unless uniquify is enabled" unless-uniquify)
1866 (const :tag "Always" t))
1869 (defcustom buffers-menu-show-status t
1870 "If non-nil, show modified/read-only status of buffers in the Buffers menu.
1871 Setting this variable directly does not take effect until next time the
1872 Buffers menu is regenerated."
1873 :set (lambda (symbol value)
1875 (menu-bar-update-buffers t))
1876 :initialize 'custom-initialize-default
1880 (defvar list-buffers-directory nil
1881 "String to display in buffer listings for buffers not visiting a file.")
1882 (make-variable-buffer-local 'list-buffers-directory)
1884 (defun menu-bar-select-buffer ()
1886 (switch-to-buffer last-command-event))
1888 (defun menu-bar-select-frame (frame)
1889 (make-frame-visible frame)
1891 (select-frame frame))
1893 (defun menu-bar-update-buffers-1 (elt)
1894 (let* ((buf (car elt))
1896 (and (if (eq buffers-menu-show-directories 'unless-uniquify)
1897 (or (not (boundp 'uniquify-buffer-name-style))
1898 (null uniquify-buffer-name-style))
1899 buffers-menu-show-directories)
1900 (or (buffer-file-name buf)
1901 (buffer-local-value 'list-buffers-directory buf)))))
1903 (setq file (file-name-directory file)))
1904 (when (and file (> (length file) 20))
1905 (setq file (concat "..." (substring file -17))))
1906 (cons (if buffers-menu-show-status
1907 (let ((mod (if (buffer-modified-p buf) "*" ""))
1908 (ro (if (buffer-local-value 'buffer-read-only buf) "%" "")))
1910 (format "%s %s%s -- %s" (cdr elt) mod ro file)
1911 (format "%s %s%s" (cdr elt) mod ro)))
1913 (format "%s -- %s" (cdr elt) file)
1917 ;; Used to cache the menu entries for commands in the Buffers menu
1918 (defvar menu-bar-buffers-menu-command-entries nil)
1920 (defun menu-bar-update-buffers (&optional force)
1921 ;; If user discards the Buffers item, play along.
1922 (and (lookup-key (current-global-map) [menu-bar buffer])
1923 (or force (frame-or-buffer-changed-p))
1924 (let ((buffers (buffer-list))
1925 (frames (frame-list))
1927 ;; If requested, list only the N most recently selected buffers.
1928 (if (and (integerp buffers-menu-max-size)
1929 (> buffers-menu-max-size 1))
1930 (if (> (length buffers) buffers-menu-max-size)
1931 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
1933 ;; Make the menu of buffers proper.
1936 ;; Put into each element of buffer-list
1937 ;; the name for actual display,
1938 ;; perhaps truncated in the middle.
1939 (dolist (buf buffers)
1940 (let ((name (buffer-name buf)))
1941 (unless (eq ?\s (aref name 0))
1942 (push (menu-bar-update-buffers-1
1944 (if (and (integerp buffers-menu-buffer-name-length)
1945 (> (length name) buffers-menu-buffer-name-length))
1948 name 0 (/ buffers-menu-buffer-name-length 2))
1951 name (- (/ buffers-menu-buffer-name-length 2))))
1955 ;; Now make the actual list of items.
1956 (let ((buffers-vec (make-vector (length alist) nil))
1958 (dolist (pair alist)
1961 (nconc (list (car pair)
1965 (switch-to-buffer ,(cdr pair))))))
1966 (list buffers-vec))))
1968 ;; Make a Frames menu if we have more than one frame.
1970 (let* ((frames-vec (make-vector (length frames) nil))
1973 (list "Select Frame" frames-vec)))
1975 (dolist (frame frames)
1979 (frame-parameter frame 'name)
1982 (interactive) (menu-bar-select-frame ,frame))))
1984 ;; Put it after the normal buffers
1987 `((frames-separator "--")
1988 (frames menu-item "Frames" ,frames-menu))))))
1990 ;; Add in some normal commands at the end of the menu. We use
1991 ;; the copy cached in `menu-bar-buffers-menu-command-entries'
1992 ;; if it's been set already. Note that we can't use constant
1993 ;; lists for the menu-entries, because the low-level menu-code
1995 (unless menu-bar-buffers-menu-command-entries
1996 (setq menu-bar-buffers-menu-command-entries
1997 (list '(command-separator "--")
2002 :help "Switch to the \"next\" buffer in a cyclic order")
2003 (list 'previous-buffer
2007 :help "Switch to the \"previous\" buffer in a cyclic order")
2008 (list 'select-named-buffer
2010 "Select Named Buffer..."
2012 :help "Prompt for a buffer name, and select that buffer in the current window")
2013 (list 'list-all-buffers
2017 :help "Pop up a window listing all Emacs buffers"
2020 (nconc buffers-menu menu-bar-buffers-menu-command-entries))
2022 ;; We used to "(define-key (current-global-map) [menu-bar buffer]"
2023 ;; but that did not do the right thing when the [menu-bar buffer]
2024 ;; entry above had been moved (e.g. to a parent keymap).
2025 (setcdr global-buffers-menu-map (cons "Select Buffer" buffers-menu)))))
2027 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
2029 (menu-bar-update-buffers)
2031 ;; this version is too slow
2032 ;;(defun format-buffers-menu-line (buffer)
2033 ;; "Returns a string to represent the given buffer in the Buffer menu.
2034 ;;nil means the buffer shouldn't be listed. You can redefine this."
2035 ;; (if (string-match "\\` " (buffer-name buffer))
2037 ;; (with-current-buffer buffer
2038 ;; (let ((size (buffer-size)))
2039 ;; (format "%s%s %-19s %6s %-15s %s"
2040 ;; (if (buffer-modified-p) "*" " ")
2041 ;; (if buffer-read-only "%" " ")
2045 ;; (or (buffer-file-name) ""))))))
2047 ;;; Set up a menu bar menu for the minibuffer.
2049 (dolist (map (list minibuffer-local-map
2050 ;; This shouldn't be necessary, but there's a funny
2051 ;; bug in keymap.c that I don't understand yet. -stef
2052 minibuffer-local-completion-map))
2053 (define-key map [menu-bar minibuf]
2054 (cons (purecopy "Minibuf") (make-sparse-keymap "Minibuf"))))
2056 (let ((map minibuffer-local-completion-map))
2057 (define-key map [menu-bar minibuf ?\?]
2058 `(menu-item ,(purecopy "List Completions") minibuffer-completion-help
2059 :help ,(purecopy "Display all possible completions")))
2060 (define-key map [menu-bar minibuf space]
2061 `(menu-item ,(purecopy "Complete Word") minibuffer-complete-word
2062 :help ,(purecopy "Complete at most one word")))
2063 (define-key map [menu-bar minibuf tab]
2064 `(menu-item ,(purecopy "Complete") minibuffer-complete
2065 :help ,(purecopy "Complete as far as possible"))))
2067 (let ((map minibuffer-local-map))
2068 (define-key map [menu-bar minibuf quit]
2069 `(menu-item ,(purecopy "Quit") abort-recursive-edit
2070 :help ,(purecopy "Abort input and exit minibuffer")))
2071 (define-key map [menu-bar minibuf return]
2072 `(menu-item ,(purecopy "Enter") exit-minibuffer
2073 :key-sequence ,(purecopy "\r")
2074 :help ,(purecopy "Terminate input and exit minibuffer")))
2075 (define-key map [menu-bar minibuf isearch-forward]
2076 `(menu-item ,(purecopy "Isearch History Forward") isearch-forward
2077 :help ,(purecopy "Incrementally search minibuffer history forward")))
2078 (define-key map [menu-bar minibuf isearch-backward]
2079 `(menu-item ,(purecopy "Isearch History Backward") isearch-backward
2080 :help ,(purecopy "Incrementally search minibuffer history backward")))
2081 (define-key map [menu-bar minibuf next]
2082 `(menu-item ,(purecopy "Next History Item") next-history-element
2083 :help ,(purecopy "Put next minibuffer history element in the minibuffer")))
2084 (define-key map [menu-bar minibuf previous]
2085 `(menu-item ,(purecopy "Previous History Item") previous-history-element
2086 :help ,(purecopy "Put previous minibuffer history element in the minibuffer"))))
2088 (define-minor-mode menu-bar-mode
2089 "Toggle display of a menu bar on each frame.
2090 This command applies to all frames that exist and frames to be
2091 created in the future.
2092 With a numeric argument, if the argument is positive,
2093 turn on menu bars; otherwise, turn off menu bars."
2096 ;; It's defined in C/cus-start, this stops the d-m-m macro defining it again.
2097 :variable menu-bar-mode
2099 ;; Turn the menu-bars on all frames on or off.
2100 (let ((val (if menu-bar-mode 1 0)))
2101 (dolist (frame (frame-list))
2102 (set-frame-parameter frame 'menu-bar-lines val))
2103 ;; If the user has given `default-frame-alist' a `menu-bar-lines'
2104 ;; parameter, replace it.
2105 (if (assq 'menu-bar-lines default-frame-alist)
2106 (setq default-frame-alist
2107 (cons (cons 'menu-bar-lines val)
2108 (assq-delete-all 'menu-bar-lines
2109 default-frame-alist)))))
2110 ;; Make the message appear when Emacs is idle. We can not call message
2111 ;; directly. The minor-mode message "Menu-bar mode disabled" comes
2112 ;; after this function returns, overwriting any message we do here.
2113 (when (and (called-interactively-p 'interactive) (not menu-bar-mode))
2114 (run-with-idle-timer 0 nil 'message
2115 "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear.")))
2118 ;; (This does not work right unless it comes after the above definition.)
2119 ;; This comment is taken from tool-bar.el near
2120 ;; (put 'tool-bar-mode ...)
2121 ;; We want to pretend the menu bar by standard is on, as this will make
2122 ;; customize consider disabling the menu bar a customization, and save
2123 ;; that. We could do this for real by setting :init-value above, but
2124 ;; that would overwrite disabling the menu bar from X resources.
2125 (put 'menu-bar-mode 'standard-value '(t))
2127 (defun toggle-menu-bar-mode-from-frame (&optional arg)
2128 "Toggle menu bar on or off, based on the status of the current frame.
2129 See `menu-bar-mode' for more information."
2130 (interactive (list (or current-prefix-arg 'toggle)))
2131 (if (eq arg 'toggle)
2133 (if (menu-bar-positive-p
2134 (frame-parameter (menu-bar-frame-for-menubar) 'menu-bar-lines))
2136 (menu-bar-mode arg)))
2138 (declare-function x-menu-bar-open "term/x-win" (&optional frame))
2139 (declare-function w32-menu-bar-open "term/w32-win" (&optional frame))
2141 (defun menu-bar-open (&optional frame)
2142 "Start key navigation of the menu bar in FRAME.
2144 This function decides which method to use to access the menu
2145 depending on FRAME's terminal device. On X displays, it calls
2146 `x-menu-bar-open'; on Windows, `w32-menu-bar-open' otherwise it
2147 calls `tmm-menubar'.
2149 If FRAME is nil or not given, use the selected frame."
2151 (let ((type (framep (or frame (selected-frame)))))
2153 ((eq type 'x) (x-menu-bar-open frame))
2154 ((eq type 'w32) (w32-menu-bar-open frame))
2155 (t (with-selected-frame (or frame (selected-frame))
2158 (global-set-key [f10] 'menu-bar-open)
2162 ;;; menu-bar.el ends here