2007-08-19 Michael Kifer <kifer@cs.stonybrook.edu>
[emacs.git] / lisp / menu-bar.el
blobfcf11f05314f00af23962c4f8dce52c2f9350d7b
1 ;;; menu-bar.el --- define a default menu bar
3 ;; Copyright (C) 1993, 1994, 1995, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: RMS
7 ;; Maintainer: FSF
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, or (at your option)
15 ;; 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; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
27 ;; Avishai Yacobi suggested some menu rearrangements.
29 ;;; Commentary:
31 ;;; Code:
33 ;;; User options:
35 (defcustom buffers-menu-max-size 10
36 "*Maximum number of entries which may appear on the Buffers menu.
37 If this is 10, then only the ten most-recently-selected buffers are shown.
38 If this is nil, then all buffers are shown.
39 A large number or nil slows down menu responsiveness."
40 :type '(choice integer
41 (const :tag "All" nil))
42 :group 'mouse)
44 ;; Don't clobber an existing menu-bar keymap, to preserve any menu-bar key
45 ;; definitions made in loaddefs.el.
46 (or (lookup-key global-map [menu-bar])
47 (define-key global-map [menu-bar] (make-sparse-keymap "menu-bar")))
48 (defvar menu-bar-help-menu (make-sparse-keymap "Help"))
50 ;; Force Help item to come last, after the major mode's own items.
51 ;; The symbol used to be called `help', but that gets confused with the
52 ;; help key.
53 (setq menu-bar-final-items '(help-menu))
55 (define-key global-map [menu-bar help-menu] (cons "Help" menu-bar-help-menu))
56 (defvar menu-bar-tools-menu (make-sparse-keymap "Tools"))
57 (define-key global-map [menu-bar tools] (cons "Tools" menu-bar-tools-menu))
58 ;; This definition is just to show what this looks like.
59 ;; It gets overridden below when menu-bar-update-buffers is called.
60 (define-key global-map [menu-bar buffer]
61 (cons "Buffers" (make-sparse-keymap "Buffers")))
62 (defvar menu-bar-options-menu (make-sparse-keymap "Options"))
63 (define-key global-map [menu-bar options]
64 (cons "Options" menu-bar-options-menu))
65 (defvar menu-bar-edit-menu (make-sparse-keymap "Edit"))
66 (define-key global-map [menu-bar edit] (cons "Edit" menu-bar-edit-menu))
67 (defvar menu-bar-file-menu (make-sparse-keymap "File"))
68 (define-key global-map [menu-bar file] (cons "File" menu-bar-file-menu))
70 ;; This alias is for compatibility with 19.28 and before.
71 (defvar menu-bar-files-menu menu-bar-file-menu)
73 ;; This is referenced by some code below; it is defined in uniquify.el
74 (defvar uniquify-buffer-name-style)
77 ;; The "File" menu items
78 (define-key menu-bar-file-menu [exit-emacs]
79 '(menu-item "Exit Emacs" save-buffers-kill-emacs
80 :help "Save unsaved buffers, then exit"))
82 (define-key menu-bar-file-menu [separator-exit]
83 '("--"))
85 ;; Don't use delete-frame as event name because that is a special
86 ;; event.
87 (define-key menu-bar-file-menu [delete-this-frame]
88 '(menu-item "Delete Frame" delete-frame
89 :visible (fboundp 'delete-frame)
90 :enable (delete-frame-enabled-p)
91 :help "Delete currently selected frame"))
92 (define-key menu-bar-file-menu [make-frame-on-display]
93 '(menu-item "New Frame on Display..." make-frame-on-display
94 :visible (fboundp 'make-frame-on-display)
95 :help "Open a new frame on another display"))
96 (define-key menu-bar-file-menu [make-frame]
97 '(menu-item "New Frame" make-frame-command
98 :visible (fboundp 'make-frame-command)
99 :help "Open a new frame"))
101 (define-key menu-bar-file-menu [one-window]
102 '(menu-item "Remove Splits" delete-other-windows
103 :enable (not (one-window-p t nil))
104 :help "Selected window grows to fill the whole frame"))
106 (define-key menu-bar-file-menu [split-window]
107 '(menu-item "Split Window" split-window-vertically
108 :enable (and (menu-bar-menu-frame-live-and-visible-p)
109 (menu-bar-non-minibuffer-window-p))
110 :help "Split selected window in two windows"))
112 (define-key menu-bar-file-menu [separator-window]
113 '(menu-item "--"))
115 (define-key menu-bar-file-menu [ps-print-region]
116 '(menu-item "Postscript Print Region (B+W)" ps-print-region
117 :enable mark-active
118 :help "Pretty-print marked region in black and white to PostScript printer"))
119 (define-key menu-bar-file-menu [ps-print-buffer]
120 '(menu-item "Postscript Print Buffer (B+W)" ps-print-buffer
121 :enable (menu-bar-menu-frame-live-and-visible-p)
122 :help "Pretty-print current buffer in black and white to PostScript printer"))
123 (define-key menu-bar-file-menu [ps-print-region-faces]
124 '(menu-item "Postscript Print Region" ps-print-region-with-faces
125 :enable mark-active
126 :help "Pretty-print marked region to PostScript printer"))
127 (define-key menu-bar-file-menu [ps-print-buffer-faces]
128 '(menu-item "Postscript Print Buffer" ps-print-buffer-with-faces
129 :enable (menu-bar-menu-frame-live-and-visible-p)
130 :help "Pretty-print current buffer to PostScript printer"))
131 (define-key menu-bar-file-menu [print-region]
132 '(menu-item "Print Region" print-region
133 :enable mark-active
134 :help "Print region between mark and current position"))
135 (define-key menu-bar-file-menu [print-buffer]
136 '(menu-item "Print Buffer" print-buffer
137 :enable (menu-bar-menu-frame-live-and-visible-p)
138 :help "Print current buffer with page headings"))
140 (define-key menu-bar-file-menu [separator-print]
141 '(menu-item "--"))
143 (define-key menu-bar-file-menu [recover-session]
144 '(menu-item "Recover Crashed Session" recover-session
145 :enable (and auto-save-list-file-prefix
146 (file-directory-p
147 (file-name-directory auto-save-list-file-prefix))
148 (directory-files
149 (file-name-directory auto-save-list-file-prefix)
151 (concat "\\`"
152 (regexp-quote
153 (file-name-nondirectory
154 auto-save-list-file-prefix)))
156 :help "Recover edits from a crashed session"))
157 (define-key menu-bar-file-menu [revert-buffer]
158 '(menu-item "Revert Buffer" revert-buffer
159 :enable (or revert-buffer-function
160 revert-buffer-insert-file-contents-function
161 (and buffer-file-number
162 (or (buffer-modified-p)
163 (not (verify-visited-file-modtime
164 (current-buffer))))))
165 :help "Re-read current buffer from its file"))
166 (define-key menu-bar-file-menu [write-file]
167 '(menu-item "Save As..." write-file
168 :enable (and (menu-bar-menu-frame-live-and-visible-p)
169 (menu-bar-non-minibuffer-window-p))
170 :help "Write current buffer to another file"))
171 (define-key menu-bar-file-menu [save-buffer]
172 '(menu-item "Save" save-buffer
173 :enable (and (buffer-modified-p)
174 (buffer-file-name)
175 (menu-bar-non-minibuffer-window-p))
176 :help "Save current buffer to its file"))
178 (define-key menu-bar-file-menu [separator-save]
179 '(menu-item "--"))
181 (defun menu-find-file-existing ()
182 "Edit the existing file FILENAME."
183 (interactive)
184 (let* ((mustmatch (not (and (fboundp 'x-uses-old-gtk-dialog)
185 (x-uses-old-gtk-dialog))))
186 (filename (car (find-file-read-args "Find file: " mustmatch))))
187 (if mustmatch
188 (find-file-existing filename)
189 (find-file filename))))
192 (define-key menu-bar-file-menu [kill-buffer]
193 '(menu-item "Close" kill-this-buffer
194 :enable (kill-this-buffer-enabled-p)
195 :help "Discard (kill) current buffer"))
196 (define-key menu-bar-file-menu [insert-file]
197 '(menu-item "Insert File..." insert-file
198 :enable (menu-bar-non-minibuffer-window-p)
199 :help "Insert another file into current buffer"))
200 (define-key menu-bar-file-menu [dired]
201 '(menu-item "Open Directory..." dired
202 :enable (menu-bar-non-minibuffer-window-p)
203 :help "Read a directory, to operate on its files"))
204 (define-key menu-bar-file-menu [open-file]
205 '(menu-item "Open File..." menu-find-file-existing
206 :enable (menu-bar-non-minibuffer-window-p)
207 :help "Read an existing file into an Emacs buffer"))
208 (define-key menu-bar-file-menu [new-file]
209 '(menu-item "Visit New File..." find-file
210 :enable (menu-bar-non-minibuffer-window-p)
211 :help "Specify a new file's name, to edit the file"))
214 ;; The "Edit" menu items
216 ;; The "Edit->Search" submenu
217 (defvar menu-bar-last-search-type nil
218 "Type of last non-incremental search command called from the menu.")
220 (defun nonincremental-repeat-search-forward ()
221 "Search forward for the previous search string or regexp."
222 (interactive)
223 (cond
224 ((and (eq menu-bar-last-search-type 'string)
225 search-ring)
226 (search-forward (car search-ring)))
227 ((and (eq menu-bar-last-search-type 'regexp)
228 regexp-search-ring)
229 (re-search-forward (car regexp-search-ring)))
231 (error "No previous search"))))
233 (defun nonincremental-repeat-search-backward ()
234 "Search backward for the previous search string or regexp."
235 (interactive)
236 (cond
237 ((and (eq menu-bar-last-search-type 'string)
238 search-ring)
239 (search-backward (car search-ring)))
240 ((and (eq menu-bar-last-search-type 'regexp)
241 regexp-search-ring)
242 (re-search-backward (car regexp-search-ring)))
244 (error "No previous search"))))
246 (defun nonincremental-search-forward (string)
247 "Read a string and search for it nonincrementally."
248 (interactive "sSearch for string: ")
249 (setq menu-bar-last-search-type 'string)
250 (if (equal string "")
251 (search-forward (car search-ring))
252 (isearch-update-ring string nil)
253 (search-forward string)))
255 (defun nonincremental-search-backward (string)
256 "Read a string and search backward for it nonincrementally."
257 (interactive "sSearch for string: ")
258 (setq menu-bar-last-search-type 'string)
259 (if (equal string "")
260 (search-backward (car search-ring))
261 (isearch-update-ring string nil)
262 (search-backward string)))
264 (defun nonincremental-re-search-forward (string)
265 "Read a regular expression and search for it nonincrementally."
266 (interactive "sSearch for regexp: ")
267 (setq menu-bar-last-search-type 'regexp)
268 (if (equal string "")
269 (re-search-forward (car regexp-search-ring))
270 (isearch-update-ring string t)
271 (re-search-forward string)))
273 (defun nonincremental-re-search-backward (string)
274 "Read a regular expression and search backward for it nonincrementally."
275 (interactive "sSearch for regexp: ")
276 (setq menu-bar-last-search-type 'regexp)
277 (if (equal string "")
278 (re-search-backward (car regexp-search-ring))
279 (isearch-update-ring string t)
280 (re-search-backward string)))
282 (defvar menu-bar-search-menu (make-sparse-keymap "Search"))
284 ;; The Edit->Search->Incremental Search menu
285 (defvar menu-bar-i-search-menu
286 (make-sparse-keymap "Incremental Search"))
288 (define-key menu-bar-i-search-menu [isearch-backward-regexp]
289 '(menu-item "Backward Regexp..." isearch-backward-regexp
290 :help "Search backwards for a regular expression as you type it"))
291 (define-key menu-bar-i-search-menu [isearch-forward-regexp]
292 '(menu-item "Forward Regexp..." isearch-forward-regexp
293 :help "Search forward for a regular expression as you type it"))
294 (define-key menu-bar-i-search-menu [isearch-backward]
295 '(menu-item "Backward String..." isearch-backward
296 :help "Search backwards for a string as you type it"))
297 (define-key menu-bar-i-search-menu [isearch-forward]
298 '(menu-item "Forward String..." isearch-forward
299 :help "Search forward for a string as you type it"))
302 (define-key menu-bar-search-menu [i-search]
303 (list 'menu-item "Incremental Search" menu-bar-i-search-menu))
304 (define-key menu-bar-search-menu [separator-tag-isearch]
305 '(menu-item "--"))
307 (define-key menu-bar-search-menu [tags-continue]
308 '(menu-item "Continue Tags Search" tags-loop-continue
309 :help "Continue last tags search operation"))
310 (define-key menu-bar-search-menu [tags-srch]
311 '(menu-item "Search tagged files..." tags-search
312 :help "Search for a regexp in all tagged files"))
313 (define-key menu-bar-search-menu [separator-tag-search]
314 '(menu-item "--"))
316 (define-key menu-bar-search-menu [repeat-search-back]
317 '(menu-item "Repeat Backwards" nonincremental-repeat-search-backward
318 :enable (or (and (eq menu-bar-last-search-type 'string)
319 search-ring)
320 (and (eq menu-bar-last-search-type 'regexp)
321 regexp-search-ring))
322 :help "Repeat last search backwards"))
323 (define-key menu-bar-search-menu [repeat-search-fwd]
324 '(menu-item "Repeat Forward" nonincremental-repeat-search-forward
325 :enable (or (and (eq menu-bar-last-search-type 'string)
326 search-ring)
327 (and (eq menu-bar-last-search-type 'regexp)
328 regexp-search-ring))
329 :help "Repeat last search forward"))
330 (define-key menu-bar-search-menu [separator-repeat-search]
331 '(menu-item "--"))
333 (define-key menu-bar-search-menu [re-search-backward]
334 '(menu-item "Regexp Backwards..." nonincremental-re-search-backward
335 :help "Search backwards for a regular expression"))
336 (define-key menu-bar-search-menu [re-search-forward]
337 '(menu-item "Regexp Forward..." nonincremental-re-search-forward
338 :help "Search forward for a regular expression"))
340 (define-key menu-bar-search-menu [search-backward]
341 '(menu-item "String Backwards..." nonincremental-search-backward
342 :help "Search backwards for a string"))
343 (define-key menu-bar-search-menu [search-forward]
344 '(menu-item "String Forward..." nonincremental-search-forward
345 :help "Search forward for a string"))
347 ;; The Edit->Replace submenu
349 (defvar menu-bar-replace-menu (make-sparse-keymap "Replace"))
351 (define-key menu-bar-replace-menu [tags-repl-continue]
352 '(menu-item "Continue Replace" tags-loop-continue
353 :help "Continue last tags replace operation"))
354 (define-key menu-bar-replace-menu [tags-repl]
355 '(menu-item "Replace in tagged files..." tags-query-replace
356 :help "Interactively replace a regexp in all tagged files"))
357 (define-key menu-bar-replace-menu [separator-replace-tags]
358 '(menu-item "--"))
360 (define-key menu-bar-replace-menu [query-replace-regexp]
361 '(menu-item "Replace Regexp..." query-replace-regexp
362 :enable (not buffer-read-only)
363 :help "Replace regular expression interactively, ask about each occurrence"))
364 (define-key menu-bar-replace-menu [query-replace]
365 '(menu-item "Replace String..." query-replace
366 :enable (not buffer-read-only)
367 :help "Replace string interactively, ask about each occurrence"))
369 ;;; Assemble the top-level Edit menu items.
370 (define-key menu-bar-edit-menu [props]
371 '(menu-item "Text Properties" facemenu-menu))
373 (define-key menu-bar-edit-menu [fill]
374 '(menu-item "Fill" fill-region
375 :enable (and mark-active (not buffer-read-only))
376 :help
377 "Fill text in region to fit between left and right margin"))
379 (define-key menu-bar-edit-menu [separator-bookmark]
380 '(menu-item "--"))
382 (define-key menu-bar-edit-menu [bookmark]
383 '(menu-item "Bookmarks" menu-bar-bookmark-map))
385 (defvar menu-bar-goto-menu (make-sparse-keymap "Go To"))
387 (define-key menu-bar-goto-menu [set-tags-name]
388 '(menu-item "Set Tags File Name..." visit-tags-table
389 :help "Tell Tags commands which tag table file to use"))
391 (define-key menu-bar-goto-menu [separator-tag-file]
392 '(menu-item "--"))
394 (define-key menu-bar-goto-menu [apropos-tags]
395 '(menu-item "Tags Apropos..." tags-apropos
396 :help "Find function/variables whose names match regexp"))
397 (define-key menu-bar-goto-menu [next-tag-otherw]
398 '(menu-item "Next Tag in Other Window"
399 menu-bar-next-tag-other-window
400 :enable (and (boundp 'tags-location-ring)
401 (not (ring-empty-p tags-location-ring)))
402 :help "Find next function/variable matching last tag name in another window"))
404 (defun menu-bar-next-tag-other-window ()
405 "Find the next definition of the tag already specified."
406 (interactive)
407 (find-tag-other-window nil t))
409 (defun menu-bar-next-tag ()
410 "Find the next definition of the tag already specified."
411 (interactive)
412 (find-tag nil t))
414 (define-key menu-bar-goto-menu [next-tag]
415 '(menu-item "Find Next Tag"
416 menu-bar-next-tag
417 :enable (and (boundp 'tags-location-ring)
418 (not (ring-empty-p tags-location-ring)))
419 :help "Find next function/variable matching last tag name"))
420 (define-key menu-bar-goto-menu [find-tag-otherw]
421 '(menu-item "Find Tag in Other Window..." find-tag-other-window
422 :help "Find function/variable definition in another window"))
423 (define-key menu-bar-goto-menu [find-tag]
424 '(menu-item "Find Tag..." find-tag
425 :help "Find definition of function or variable"))
427 (define-key menu-bar-goto-menu [separator-tags]
428 '(menu-item "--"))
430 (define-key menu-bar-goto-menu [end-of-buf]
431 '(menu-item "Goto End of Buffer" end-of-buffer))
432 (define-key menu-bar-goto-menu [beg-of-buf]
433 '(menu-item "Goto Beginning of Buffer" beginning-of-buffer))
434 (define-key menu-bar-goto-menu [go-to-pos]
435 '(menu-item "Goto Buffer Position..." goto-char
436 :help "Read a number N and go to buffer position N"))
437 (define-key menu-bar-goto-menu [go-to-line]
438 '(menu-item "Goto Line..." goto-line
439 :help "Read a line number and go to that line"))
441 (define-key menu-bar-edit-menu [goto]
442 (list 'menu-item "Go To" menu-bar-goto-menu))
444 (define-key menu-bar-edit-menu [replace]
445 (list 'menu-item "Replace" menu-bar-replace-menu))
447 (define-key menu-bar-edit-menu [search]
448 (list 'menu-item "Search" menu-bar-search-menu))
450 (define-key menu-bar-edit-menu [separator-search]
451 '(menu-item "--"))
453 (define-key menu-bar-edit-menu [mark-whole-buffer]
454 '(menu-item "Select All" mark-whole-buffer
455 :help "Mark the whole buffer for a subsequent cut/copy."))
456 (define-key menu-bar-edit-menu [clear]
457 '(menu-item "Clear" delete-region
458 :enable (and mark-active
459 (not buffer-read-only)
460 (not (mouse-region-match)))
461 :help
462 "Delete the text in region between mark and current position"))
463 (defvar yank-menu (cons "Select Yank" nil))
464 (fset 'yank-menu (cons 'keymap yank-menu))
465 (define-key menu-bar-edit-menu [paste-from-menu]
466 '(menu-item "Paste from kill menu" yank-menu
467 :enable (and (cdr yank-menu) (not buffer-read-only))
468 :help "Choose a string from the kill ring and paste it"))
469 (define-key menu-bar-edit-menu [paste]
470 '(menu-item "Paste" yank
471 :enable (and
472 ;; Emacs compiled --without-x doesn't have
473 ;; x-selection-exists-p.
474 (fboundp 'x-selection-exists-p)
475 (x-selection-exists-p) (not buffer-read-only))
476 :help "Paste (yank) text most recently cut/copied"))
477 (define-key menu-bar-edit-menu [copy]
478 '(menu-item "Copy" menu-bar-kill-ring-save
479 :enable mark-active
480 :help "Copy text in region between mark and current position"
481 :keys "\\[kill-ring-save]"))
482 (define-key menu-bar-edit-menu [cut]
483 '(menu-item "Cut" kill-region
484 :enable (and mark-active (not buffer-read-only))
485 :help
486 "Cut (kill) text in region between mark and current position"))
487 (define-key menu-bar-edit-menu [undo]
488 '(menu-item "Undo" undo
489 :enable (and (not buffer-read-only)
490 (not (eq t buffer-undo-list))
491 (if (eq last-command 'undo)
492 (listp pending-undo-list)
493 (consp buffer-undo-list)))
494 :help "Undo last operation"))
497 (defun menu-bar-kill-ring-save (beg end)
498 (interactive "r")
499 (if (mouse-region-match)
500 (message "Selecting a region with the mouse does `copy' automatically")
501 (kill-ring-save beg end)))
503 ;; These are alternative definitions for the cut, paste and copy
504 ;; menu items. Use them if your system expects these to use the clipboard.
506 (put 'clipboard-kill-region 'menu-enable 'mark-active)
507 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
508 (put 'clipboard-yank 'menu-enable
509 '(or (and (fboundp 'x-selection-exists-p) (x-selection-exists-p))
510 (x-selection-exists-p 'CLIPBOARD)))
512 (defun clipboard-yank ()
513 "Insert the clipboard contents, or the last stretch of killed text."
514 (interactive "*")
515 (let ((x-select-enable-clipboard t))
516 (yank)))
518 (defun clipboard-kill-ring-save (beg end)
519 "Copy region to kill ring, and save in the X clipboard."
520 (interactive "r")
521 (let ((x-select-enable-clipboard t))
522 (kill-ring-save beg end)))
524 (defun clipboard-kill-region (beg end)
525 "Kill the region, and save it in the X clipboard."
526 (interactive "r")
527 (let ((x-select-enable-clipboard t))
528 (kill-region beg end)))
530 (defun menu-bar-enable-clipboard ()
531 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
532 Do the same for the keys of the same name."
533 (interactive)
534 ;; We can't use constant list structure here because it becomes pure,
535 ;; and because it gets modified with cache data.
536 (define-key menu-bar-edit-menu [paste]
537 (cons "Paste" (cons "Paste text from clipboard" 'clipboard-yank)))
538 (define-key menu-bar-edit-menu [copy]
539 (cons "Copy" (cons "Copy text in region to the clipboard"
540 'clipboard-kill-ring-save)))
541 (define-key menu-bar-edit-menu [cut]
542 (cons "Cut" (cons "Delete text in region and copy it to the clipboard"
543 'clipboard-kill-region)))
545 ;; These are Sun server keysyms for the Cut, Copy and Paste keys
546 ;; (also for XFree86 on Sun keyboard):
547 (define-key global-map [f20] 'clipboard-kill-region)
548 (define-key global-map [f16] 'clipboard-kill-ring-save)
549 (define-key global-map [f18] 'clipboard-yank)
550 ;; X11R6 versions:
551 (define-key global-map [cut] 'clipboard-kill-region)
552 (define-key global-map [copy] 'clipboard-kill-ring-save)
553 (define-key global-map [paste] 'clipboard-yank))
555 ;; The "Options" menu items
557 (defvar menu-bar-custom-menu (make-sparse-keymap "Customize"))
559 (define-key menu-bar-custom-menu [customize-apropos-groups]
560 '(menu-item "Groups Matching Regexp..." customize-apropos-groups
561 :help "Browse groups whose names match regexp"))
562 (define-key menu-bar-custom-menu [customize-apropos-faces]
563 '(menu-item "Faces Matching Regexp..." customize-apropos-faces
564 :help "Browse faces whose names match regexp"))
565 (define-key menu-bar-custom-menu [customize-apropos-options]
566 '(menu-item "Options Matching Regexp..." customize-apropos-options
567 :help "Browse options whose names match regexp"))
568 (define-key menu-bar-custom-menu [customize-apropos]
569 '(menu-item "Settings Matching Regexp..." customize-apropos
570 :help "Browse customizable settings whose names match regexp"))
571 (define-key menu-bar-custom-menu [separator-1]
572 '("--"))
573 (define-key menu-bar-custom-menu [customize-group]
574 '(menu-item "Specific Group..." customize-group
575 :help "Customize settings of specific group"))
576 (define-key menu-bar-custom-menu [customize-face]
577 '(menu-item "Specific Face..." customize-face
578 :help "Customize attributes of specific face"))
579 (define-key menu-bar-custom-menu [customize-option]
580 '(menu-item "Specific Option..." customize-option
581 :help "Customize value of specific option"))
582 (define-key menu-bar-custom-menu [separator-2]
583 '("--"))
584 (define-key menu-bar-custom-menu [customize-changed-options]
585 '(menu-item "New Options..." customize-changed-options
586 :help "Options added or changed in recent Emacs versions"))
587 (define-key menu-bar-custom-menu [customize-saved]
588 '(menu-item "Saved Options" customize-saved
589 :help "Customize previously saved options"))
590 (define-key menu-bar-custom-menu [separator-3]
591 '("--"))
592 (define-key menu-bar-custom-menu [customize-browse]
593 '(menu-item "Browse Customization Groups" customize-browse
594 :help "Browse all customization groups"))
595 (define-key menu-bar-custom-menu [customize]
596 '(menu-item "Top-level Customization Group" customize
597 :help "The master group called `Emacs'"))
599 ;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
601 (defmacro menu-bar-make-mm-toggle (fname doc help &optional props)
602 "Make a menu-item for a global minor mode toggle.
603 FNAME is the minor mode's name (variable and function).
604 DOC is the text to use for the menu entry.
605 HELP is the text to use for the tooltip.
606 PROPS are additional properties."
607 `'(menu-item ,doc ,fname
608 ,@props
609 :help ,help
610 :button (:toggle . (and (default-boundp ',fname)
611 (default-value ',fname)))))
613 (defmacro menu-bar-make-toggle (name variable doc message help &rest body)
614 `(progn
615 (defun ,name (&optional interactively)
616 ,(concat "Toggle whether to " (downcase (substring help 0 1))
617 (substring help 1) ".
618 In an interactive call, record this option as a candidate for saving
619 by \"Save Options\" in Custom buffers.")
620 (interactive "p")
621 (if ,(if body `(progn . ,body)
622 `(progn
623 (custom-load-symbol ',variable)
624 (let ((set (or (get ',variable 'custom-set) 'set-default))
625 (get (or (get ',variable 'custom-get) 'default-value)))
626 (funcall set ',variable (not (funcall get ',variable))))))
627 (message ,message "enabled globally")
628 (message ,message "disabled globally"))
629 ;; The function `customize-mark-as-set' must only be called when
630 ;; a variable is set interactively, as the purpose is to mark it as
631 ;; a candidate for "Save Options", and we do not want to save options
632 ;; the user have already set explicitly in his init file.
633 (if interactively (customize-mark-as-set ',variable)))
634 '(menu-item ,doc ,name
635 :help ,help
636 :button (:toggle . (and (default-boundp ',variable)
637 (default-value ',variable))))))
639 ;;; Assemble all the top-level items of the "Options" menu
640 (define-key menu-bar-options-menu [customize]
641 (list 'menu-item "Customize Emacs" menu-bar-custom-menu))
643 (defun menu-bar-options-save ()
644 "Save current values of Options menu items using Custom."
645 (interactive)
646 (let ((need-save nil))
647 ;; These are set with menu-bar-make-mm-toggle, which does not
648 ;; put on a customized-value property.
649 (dolist (elt '(line-number-mode column-number-mode size-indication-mode
650 cua-mode show-paren-mode transient-mark-mode
651 blink-cursor-mode display-time-mode display-battery-mode))
652 (and (customize-mark-to-save elt)
653 (setq need-save t)))
654 ;; These are set with `customize-set-variable'.
655 (dolist (elt '(scroll-bar-mode
656 debug-on-quit debug-on-error
657 tooltip-mode menu-bar-mode tool-bar-mode
658 save-place uniquify-buffer-name-style fringe-mode
659 indicate-empty-lines indicate-buffer-boundaries
660 case-fold-search
661 current-language-environment default-input-method
662 ;; Saving `text-mode-hook' is somewhat questionable,
663 ;; as we might get more than we bargain for, if
664 ;; other code may has added hooks as well.
665 ;; Nonetheless, not saving it would like be confuse
666 ;; more often.
667 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
668 text-mode-hook))
669 (and (get elt 'customized-value)
670 (customize-mark-to-save elt)
671 (setq need-save t)))
672 ;; Save if we changed anything.
673 (when need-save
674 (custom-save-all))))
676 (define-key menu-bar-options-menu [save]
677 '(menu-item "Save Options" menu-bar-options-save
678 :help "Save options set from the menu above"))
680 (define-key menu-bar-options-menu [custom-separator]
681 '("--"))
683 (define-key menu-bar-options-menu [mouse-set-font]
684 '(menu-item "Set Font/Fontset..." mouse-set-font
685 :visible (display-multi-font-p)
686 :help "Select a font from list of known fonts/fontsets"))
688 ;; The "Show/Hide" submenu of menu "Options"
690 (defvar menu-bar-showhide-menu (make-sparse-keymap "Show/Hide"))
692 (define-key menu-bar-showhide-menu [column-number-mode]
693 (menu-bar-make-mm-toggle column-number-mode
694 "Column Numbers"
695 "Show the current column number in the mode line"))
697 (define-key menu-bar-showhide-menu [line-number-mode]
698 (menu-bar-make-mm-toggle line-number-mode
699 "Line Numbers"
700 "Show the current line number in the mode line"))
702 (define-key menu-bar-showhide-menu [size-indication-mode]
703 (menu-bar-make-mm-toggle size-indication-mode
704 "Size Indication"
705 "Show the size of the buffer in the mode line"))
707 (define-key menu-bar-showhide-menu [linecolumn-separator]
708 '("--"))
710 (define-key menu-bar-showhide-menu [showhide-battery]
711 (menu-bar-make-mm-toggle display-battery-mode
712 "Battery Status"
713 "Display battery status information in mode line"))
715 (define-key menu-bar-showhide-menu [showhide-date-time]
716 (menu-bar-make-mm-toggle display-time-mode
717 "Time, Load and Mail"
718 "Display time, system load averages and \
719 mail status in mode line"))
721 (define-key menu-bar-showhide-menu [datetime-separator]
722 '("--"))
724 (define-key menu-bar-showhide-menu [showhide-speedbar]
725 '(menu-item "Speedbar" speedbar-frame-mode
726 :help "Display a Speedbar quick-navigation frame"
727 :button (:toggle
728 . (and (boundp 'speedbar-frame)
729 (frame-live-p (symbol-value 'speedbar-frame))
730 (frame-visible-p
731 (symbol-value 'speedbar-frame))))))
733 (defvar menu-bar-showhide-fringe-menu (make-sparse-keymap "Fringe"))
735 (defvar menu-bar-showhide-fringe-ind-menu
736 (make-sparse-keymap "Buffer boundaries"))
738 (defun menu-bar-showhide-fringe-ind-customize ()
739 "Show customization buffer for `indicate-buffer-boundaries'."
740 (interactive)
741 (customize-variable 'indicate-buffer-boundaries))
743 (define-key menu-bar-showhide-fringe-ind-menu [customize]
744 '(menu-item "Other (Customize)"
745 menu-bar-showhide-fringe-ind-customize
746 :help "Additional choices available through Custom buffer"
747 :visible (display-graphic-p)))
749 (defun menu-bar-showhide-fringe-ind-mixed ()
750 "Display top and bottom indicators in opposite fringes, arrows in right."
751 (interactive)
752 (customize-set-variable 'indicate-buffer-boundaries
753 '((t . right) (top . left))))
755 (define-key menu-bar-showhide-fringe-ind-menu [mixed]
756 '(menu-item "Opposite, Arrows Right" menu-bar-showhide-fringe-ind-mixed
757 :help
758 "Show top/bottom indicators in opposite fringes, arrows in right"
759 :visible (display-graphic-p)
760 :button (:radio . (eq indicate-buffer-boundaries
761 '((t . right) (top . left))))))
763 (defun menu-bar-showhide-fringe-ind-box ()
764 "Display top and bottom indicators in opposite fringes."
765 (interactive)
766 (customize-set-variable 'indicate-buffer-boundaries
767 '((top . left) (bottom . right))))
769 (define-key menu-bar-showhide-fringe-ind-menu [box]
770 '(menu-item "Opposite, No Arrows" menu-bar-showhide-fringe-ind-box
771 :help "Show top/bottom indicators in opposite fringes, no arrows"
772 :visible (display-graphic-p)
773 :button (:radio . (eq indicate-buffer-boundaries
774 '((top . left) (bottom . right))))))
776 (defun menu-bar-showhide-fringe-ind-right ()
777 "Display buffer boundaries and arrows in the right fringe."
778 (interactive)
779 (customize-set-variable 'indicate-buffer-boundaries 'right))
781 (define-key menu-bar-showhide-fringe-ind-menu [right]
782 '(menu-item "In Right Fringe" menu-bar-showhide-fringe-ind-right
783 :help "Show buffer boundaries and arrows in right fringe"
784 :visible (display-graphic-p)
785 :button (:radio . (eq indicate-buffer-boundaries 'right))))
787 (defun menu-bar-showhide-fringe-ind-left ()
788 "Display buffer boundaries and arrows in the left fringe."
789 (interactive)
790 (customize-set-variable 'indicate-buffer-boundaries 'left))
792 (define-key menu-bar-showhide-fringe-ind-menu [left]
793 '(menu-item "In Left Fringe" menu-bar-showhide-fringe-ind-left
794 :help "Show buffer boundaries and arrows in left fringe"
795 :visible (display-graphic-p)
796 :button (:radio . (eq indicate-buffer-boundaries 'left))))
798 (defun menu-bar-showhide-fringe-ind-none ()
799 "Do not display any buffer boundary indicators."
800 (interactive)
801 (customize-set-variable 'indicate-buffer-boundaries nil))
803 (define-key menu-bar-showhide-fringe-ind-menu [none]
804 '(menu-item "No Indicators" menu-bar-showhide-fringe-ind-none
805 :help "Hide all buffer boundary indicators and arrows"
806 :visible (display-graphic-p)
807 :button (:radio . (eq indicate-buffer-boundaries nil))))
809 (define-key menu-bar-showhide-fringe-menu [showhide-fringe-ind]
810 (list 'menu-item "Buffer Boundaries" menu-bar-showhide-fringe-ind-menu
811 :visible `(display-graphic-p)
812 :help "Indicate buffer boundaries in fringe"))
814 (define-key menu-bar-showhide-fringe-menu [indicate-empty-lines]
815 (menu-bar-make-toggle toggle-indicate-empty-lines indicate-empty-lines
816 "Empty Line Indicators"
817 "Indicating of empty lines %s"
818 "Indicate trailing empty lines in fringe, globally"))
820 (defun menu-bar-showhide-fringe-menu-customize ()
821 "Show customization buffer for `fringe-mode'."
822 (interactive)
823 (customize-variable 'fringe-mode))
825 (define-key menu-bar-showhide-fringe-menu [customize]
826 '(menu-item "Customize Fringe" menu-bar-showhide-fringe-menu-customize
827 :help "Detailed customization of fringe"
828 :visible (display-graphic-p)))
830 (defun menu-bar-showhide-fringe-menu-customize-reset ()
831 "Reset the fringe mode: display fringes on both sides of a window."
832 (interactive)
833 (customize-set-variable 'fringe-mode nil))
835 (define-key menu-bar-showhide-fringe-menu [default]
836 '(menu-item "Default" menu-bar-showhide-fringe-menu-customize-reset
837 :help "Default width fringe on both left and right side"
838 :visible (display-graphic-p)
839 :button (:radio . (eq fringe-mode nil))))
841 (defun menu-bar-showhide-fringe-menu-customize-right ()
842 "Display fringes only on the right of each window."
843 (interactive)
844 (require 'fringe)
845 (customize-set-variable 'fringe-mode '(0 . nil)))
847 (define-key menu-bar-showhide-fringe-menu [right]
848 '(menu-item "On the Right" menu-bar-showhide-fringe-menu-customize-right
849 :help "Fringe only on the right side"
850 :visible (display-graphic-p)
851 :button (:radio . (equal fringe-mode '(0 . nil)))))
853 (defun menu-bar-showhide-fringe-menu-customize-left ()
854 "Display fringes only on the left of each window."
855 (interactive)
856 (require 'fringe)
857 (customize-set-variable 'fringe-mode '(nil . 0)))
859 (define-key menu-bar-showhide-fringe-menu [left]
860 '(menu-item "On the Left" menu-bar-showhide-fringe-menu-customize-left
861 :help "Fringe only on the left side"
862 :visible (display-graphic-p)
863 :button (:radio . (equal fringe-mode '(nil . 0)))))
865 (defun menu-bar-showhide-fringe-menu-customize-disable ()
866 "Do not display window fringes."
867 (interactive)
868 (require 'fringe)
869 (customize-set-variable 'fringe-mode 0))
871 (define-key menu-bar-showhide-fringe-menu [none]
872 '(menu-item "None" menu-bar-showhide-fringe-menu-customize-disable
873 :help "Turn off fringe"
874 :visible (display-graphic-p)
875 :button (:radio . (eq fringe-mode 0))))
877 (define-key menu-bar-showhide-menu [showhide-fringe]
878 (list 'menu-item "Fringe" menu-bar-showhide-fringe-menu
879 :visible `(display-graphic-p)))
881 (defvar menu-bar-showhide-scroll-bar-menu (make-sparse-keymap "Scroll-bar"))
883 (define-key menu-bar-showhide-scroll-bar-menu [right]
884 '(menu-item "On the Right"
885 menu-bar-right-scroll-bar
886 :help "Scroll-bar on the right side"
887 :visible (display-graphic-p)
888 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
889 (frame-parameters))) 'right))))
890 (defun menu-bar-right-scroll-bar ()
891 "Display scroll bars on the right of each window."
892 (interactive)
893 (customize-set-variable 'scroll-bar-mode 'right))
895 (define-key menu-bar-showhide-scroll-bar-menu [left]
896 '(menu-item "On the Left"
897 menu-bar-left-scroll-bar
898 :help "Scroll-bar on the left side"
899 :visible (display-graphic-p)
900 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
901 (frame-parameters))) 'left))))
903 (defun menu-bar-left-scroll-bar ()
904 "Display scroll bars on the left of each window."
905 (interactive)
906 (customize-set-variable 'scroll-bar-mode 'left))
908 (define-key menu-bar-showhide-scroll-bar-menu [none]
909 '(menu-item "None"
910 menu-bar-no-scroll-bar
911 :help "Turn off scroll-bar"
912 :visible (display-graphic-p)
913 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
914 (frame-parameters))) nil))))
916 (defun menu-bar-no-scroll-bar ()
917 "Turn off scroll bars."
918 (interactive)
919 (customize-set-variable 'scroll-bar-mode nil))
921 (define-key menu-bar-showhide-menu [showhide-scroll-bar]
922 (list 'menu-item "Scroll-bar" menu-bar-showhide-scroll-bar-menu
923 :visible `(display-graphic-p)))
925 (define-key menu-bar-showhide-menu [showhide-tooltip-mode]
926 (list 'menu-item "Tooltips" 'tooltip-mode
927 :help "Turn tooltips on/off"
928 :visible `(and (display-graphic-p) (fboundp 'x-show-tip))
929 :button `(:toggle . tooltip-mode)))
931 (define-key menu-bar-showhide-menu [menu-bar-mode]
932 '(menu-item "Menu-bar" menu-bar-mode
933 :help "Turn menu-bar on/off"
934 :button (:toggle . menu-bar-mode)))
936 (define-key menu-bar-showhide-menu [showhide-tool-bar]
937 (list 'menu-item "Tool-bar" 'tool-bar-mode
938 :help "Turn tool-bar on/off"
939 :visible `(display-graphic-p)
940 :button `(:toggle . tool-bar-mode)))
942 (define-key menu-bar-options-menu [showhide]
943 (list 'menu-item "Show/Hide" menu-bar-showhide-menu))
945 (define-key menu-bar-options-menu [showhide-separator]
946 '("--"))
948 (define-key menu-bar-options-menu [mule]
949 ;; It is better not to use backquote here,
950 ;; because that makes a bootstrapping problem
951 ;; if you need to recompile all the Lisp files using interpreted code.
952 (list 'menu-item "Mule (Multilingual Environment)" mule-menu-keymap
953 ;; Most of the MULE menu actually does make sense in unibyte mode,
954 ;; e.g. language selection.
955 ;;; ':visible 'default-enable-multibyte-characters
957 ;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
958 ;(define-key menu-bar-options-menu [preferences]
959 ; (list 'menu-item "Preferences" menu-bar-preferences-menu
960 ; :help "Toggle important global options"))
962 (define-key menu-bar-options-menu [mule-separator]
963 '("--"))
965 (define-key menu-bar-options-menu [debug-on-quit]
966 (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
967 "Enter Debugger on Quit/C-g" "Debug on Quit %s"
968 "Enter Lisp debugger when C-g is pressed"))
969 (define-key menu-bar-options-menu [debug-on-error]
970 (menu-bar-make-toggle toggle-debug-on-error debug-on-error
971 "Enter Debugger on Error" "Debug on Error %s"
972 "Enter Lisp debugger when an error is signaled"))
973 (define-key menu-bar-options-menu [debugger-separator]
974 '("--"))
976 (define-key menu-bar-options-menu [blink-cursor-mode]
977 (menu-bar-make-mm-toggle blink-cursor-mode
978 "Blinking Cursor"
979 "Whether the cursor blinks (Blink Cursor mode)"))
980 (define-key menu-bar-options-menu [cursor-separator]
981 '("--"))
983 (define-key menu-bar-options-menu [save-place]
984 (menu-bar-make-toggle toggle-save-place-globally save-place
985 "Save Place in Files between Sessions"
986 "Saving place in files %s"
987 "Visit files of previous session when restarting Emacs"
988 (require 'saveplace)
989 ;; Do it by name, to avoid a free-variable
990 ;; warning during byte compilation.
991 (set-default
992 'save-place (not (symbol-value 'save-place)))))
994 (define-key menu-bar-options-menu [uniquify]
995 (menu-bar-make-toggle toggle-uniquify-buffer-names uniquify-buffer-name-style
996 "Use Directory Names in Buffer Names"
997 "Directory name in buffer names (uniquify) %s"
998 "Uniquify buffer names by adding parent directory names"
999 (require 'uniquify)
1000 (setq uniquify-buffer-name-style
1001 (if (not uniquify-buffer-name-style)
1002 'forward))))
1004 (define-key menu-bar-options-menu [edit-options-separator]
1005 '("--"))
1006 (define-key menu-bar-options-menu [cua-mode]
1007 (menu-bar-make-mm-toggle cua-mode
1008 "C-x/C-c/C-v Cut and Paste (CUA)"
1009 "Use C-z/C-x/C-c/C-v keys for undo/cut/copy/paste"
1010 (:visible (or (not (boundp 'cua-enable-cua-keys))
1011 cua-enable-cua-keys))))
1013 (define-key menu-bar-options-menu [cua-emulation-mode]
1014 (menu-bar-make-mm-toggle cua-mode
1015 "Shift movement mark region (CUA)"
1016 "Use shifted movement keys to set and extend the region."
1017 (:visible (and (boundp 'cua-enable-cua-keys)
1018 (not cua-enable-cua-keys)))))
1020 (define-key menu-bar-options-menu [case-fold-search]
1021 (menu-bar-make-toggle toggle-case-fold-search case-fold-search
1022 "Case-Insensitive Search"
1023 "Case-Insensitive Search %s"
1024 "Globally ignore letter-case in search"))
1026 (defun menu-bar-text-mode-auto-fill ()
1027 (interactive)
1028 (toggle-text-mode-auto-fill)
1029 ;; This is somewhat questionable, as `text-mode-hook'
1030 ;; might have changed outside customize.
1031 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
1032 (customize-mark-as-set 'text-mode-hook))
1034 (define-key menu-bar-options-menu [auto-fill-mode]
1035 '(menu-item "Word Wrap in Text Modes"
1036 menu-bar-text-mode-auto-fill
1037 :help "Automatically fill text between left and right margins (Auto Fill)"
1038 :button (:toggle . (if (listp text-mode-hook)
1039 (member 'turn-on-auto-fill text-mode-hook)
1040 (eq 'turn-on-auto-fill text-mode-hook)))))
1041 (define-key menu-bar-options-menu [truncate-lines]
1042 '(menu-item "Truncate Long Lines in this Buffer"
1043 toggle-truncate-lines
1044 :help "Truncate long lines on the screen"
1045 :button (:toggle . truncate-lines)
1046 :enable (menu-bar-menu-frame-live-and-visible-p)))
1048 (define-key menu-bar-options-menu [highlight-separator]
1049 '("--"))
1050 (define-key menu-bar-options-menu [highlight-paren-mode]
1051 (menu-bar-make-mm-toggle show-paren-mode
1052 "Paren Match Highlighting"
1053 "Highlight matching/mismatched parentheses at cursor (Show Paren mode)"))
1054 (define-key menu-bar-options-menu [transient-mark-mode]
1055 (menu-bar-make-mm-toggle transient-mark-mode
1056 "Active Region Highlighting"
1057 "Make text in active region stand out in color (Transient Mark mode)"
1058 (:enable (not cua-mode))))
1061 ;; The "Tools" menu items
1063 (defun send-mail-item-name ()
1064 (let* ((known-send-mail-commands '((sendmail-user-agent . "sendmail")
1065 (mh-e-user-agent . "MH")
1066 (message-user-agent . "Gnus Message")
1067 (gnus-user-agent . "Gnus")))
1068 (name (assq mail-user-agent known-send-mail-commands)))
1069 (if name
1070 (setq name (cdr name))
1071 (setq name (symbol-name mail-user-agent))
1072 (if (string-match "\\(.+\\)-user-agent" name)
1073 (setq name (match-string 1 name))))
1074 name))
1076 (defun read-mail-item-name ()
1077 (let* ((known-rmail-commands '((rmail . "RMAIL")
1078 (mh-rmail . "MH")
1079 (gnus . "Gnus")))
1080 (known (assq read-mail-command known-rmail-commands)))
1081 (if known (cdr known) (symbol-name read-mail-command))))
1083 (defvar menu-bar-games-menu (make-sparse-keymap "Games"))
1085 (define-key menu-bar-tools-menu [games]
1086 (list 'menu-item "Games" menu-bar-games-menu))
1088 (define-key menu-bar-tools-menu [separator-games]
1089 '("--"))
1091 (define-key menu-bar-games-menu [zone]
1092 '(menu-item "Zone Out" zone
1093 :help "Play tricks with Emacs display when Emacs is idle"))
1094 (define-key menu-bar-games-menu [tetris]
1095 '(menu-item "Tetris" tetris))
1096 (define-key menu-bar-games-menu [solitaire]
1097 '(menu-item "Solitaire" solitaire))
1098 (define-key menu-bar-games-menu [snake]
1099 '(menu-item "Snake" snake
1100 :help "Move snake around avoiding collisions"))
1101 (define-key menu-bar-games-menu [mult]
1102 '(menu-item "Multiplication Puzzle" mpuz
1103 :help "Exercise brain with multiplication"))
1104 (define-key menu-bar-games-menu [life]
1105 '(menu-item "Life" life
1106 :help "Watch how John Conway's cellular automaton evolves"))
1107 (define-key menu-bar-games-menu [hanoi]
1108 '(menu-item "Towers of Hanoi" hanoi
1109 :help "Watch Towers-of-Hanoi puzzle solved by Emacs"))
1110 (define-key menu-bar-games-menu [gomoku]
1111 '(menu-item "Gomoku" gomoku
1112 :help "Mark 5 contiguous squares (like tic-tac-toe)"))
1113 (define-key menu-bar-games-menu [black-box]
1114 '(menu-item "Blackbox" blackbox
1115 :help "Find balls in a black box by shooting rays"))
1116 (define-key menu-bar-games-menu [adventure]
1117 '(menu-item "Adventure" dunnet
1118 :help "Dunnet, a text Adventure game for Emacs"))
1119 (define-key menu-bar-games-menu [5x5]
1120 '(menu-item "5x5" 5x5
1121 :help "Fill in all the squares on a 5x5 board"))
1123 (define-key menu-bar-tools-menu [simple-calculator]
1124 '(menu-item "Simple Calculator" calculator
1125 :help "Invoke the Emacs built-in quick calculator"))
1126 (define-key menu-bar-tools-menu [calc]
1127 '(menu-item "Programmable Calculator" calc
1128 :help "Invoke the Emacs built-in full scientific calculator"))
1129 (define-key menu-bar-tools-menu [calendar]
1130 '(menu-item "Calendar" calendar
1131 :help "Invoke the Emacs built-in calendar"))
1133 (define-key menu-bar-tools-menu [separator-net]
1134 '("--"))
1136 (define-key menu-bar-tools-menu [directory-search]
1137 '(menu-item "Directory Search" eudc-tools-menu))
1138 (define-key menu-bar-tools-menu [compose-mail]
1139 (list
1140 'menu-item `(format "Send Mail (with %s)" (send-mail-item-name))
1141 'compose-mail
1142 :visible `(and mail-user-agent (not (eq mail-user-agent 'ignore)))
1143 :help "Send a mail message"))
1144 (define-key menu-bar-tools-menu [rmail]
1145 (list
1146 'menu-item `(format "Read Mail (with %s)" (read-mail-item-name))
1147 'menu-bar-read-mail
1148 :visible `(and read-mail-command (not (eq read-mail-command 'ignore)))
1149 :help "Read your mail and reply to it"))
1151 (defun menu-bar-read-mail ()
1152 "Read mail using `read-mail-command'."
1153 (interactive)
1154 (call-interactively read-mail-command))
1156 (define-key menu-bar-tools-menu [gnus]
1157 '(menu-item "Read Net News (Gnus)" gnus
1158 :help "Read network news groups"))
1160 (define-key menu-bar-tools-menu [separator-vc]
1161 '("--"))
1163 (defvar vc-menu-map (make-sparse-keymap "Version Control"))
1164 (defalias 'vc-menu-map vc-menu-map)
1165 (define-key menu-bar-tools-menu [pcl-cvs]
1166 '(menu-item "PCL-CVS" cvs-global-menu))
1167 (define-key menu-bar-tools-menu [vc]
1168 (list 'menu-item "Version Control" vc-menu-map
1169 :filter 'menu-bar-vc-filter))
1171 (defun menu-bar-vc-filter (orig-binding)
1172 (let ((ext-binding
1173 (if vc-mode (vc-call-backend (vc-backend buffer-file-name) 'extra-menu))))
1174 ;; Give the VC backend a chance to add menu entries
1175 ;; specific for that backend.
1176 (if (null ext-binding)
1177 orig-binding
1178 (append orig-binding
1179 '((ext-menu-separator "---"))
1180 ext-binding))))
1182 (define-key menu-bar-tools-menu [separator-compare]
1183 '("--"))
1185 (define-key menu-bar-tools-menu [ediff-misc]
1186 '(menu-item "Ediff Miscellanea" menu-bar-ediff-misc-menu))
1187 (define-key menu-bar-tools-menu [epatch]
1188 '(menu-item "Apply Patch" menu-bar-epatch-menu))
1189 (define-key menu-bar-tools-menu [ediff-merge]
1190 '(menu-item "Merge" menu-bar-ediff-merge-menu))
1191 (define-key menu-bar-tools-menu [compare]
1192 '(menu-item "Compare (Ediff)" menu-bar-ediff-menu))
1194 (define-key menu-bar-tools-menu [separator-spell]
1195 '("--"))
1197 (define-key menu-bar-tools-menu [spell]
1198 '(menu-item "Spell Checking" ispell-menu-map))
1200 (define-key menu-bar-tools-menu [separator-prog]
1201 '("--"))
1203 (define-key menu-bar-tools-menu [gdb]
1204 '(menu-item "Debugger (GDB)..." gdb
1205 :help "Debug a program from within Emacs with GDB"))
1206 (define-key menu-bar-tools-menu [shell-on-region]
1207 '(menu-item "Shell Command on Region..." shell-command-on-region
1208 :enable mark-active
1209 :help "Pass marked region to a shell command"))
1210 (define-key menu-bar-tools-menu [shell]
1211 '(menu-item "Shell Command..." shell-command
1212 :help "Invoke a shell command and catch its output"))
1213 (define-key menu-bar-tools-menu [compile]
1214 '(menu-item "Compile..." compile
1215 :help "Invoke compiler or Make, view compilation errors"))
1216 (define-key menu-bar-tools-menu [grep]
1217 '(menu-item "Search Files (Grep)..." grep
1218 :help "Search files for strings or regexps (with Grep)"))
1221 ;; The "Help" menu items
1223 (defvar menu-bar-describe-menu (make-sparse-keymap "Describe"))
1225 (define-key menu-bar-describe-menu [mule-diag]
1226 '(menu-item "Show All of Mule Status" mule-diag
1227 :visible default-enable-multibyte-characters
1228 :help "Display multilingual environment settings"))
1229 (define-key menu-bar-describe-menu [describe-coding-system-briefly]
1230 '(menu-item "Describe Coding System (Briefly)..."
1231 describe-current-coding-system-briefly
1232 :visible default-enable-multibyte-characters))
1233 (define-key menu-bar-describe-menu [describe-coding-system]
1234 '(menu-item "Describe Coding System..." describe-coding-system
1235 :visible default-enable-multibyte-characters))
1236 (define-key menu-bar-describe-menu [describe-input-method]
1237 '(menu-item "Describe Input Method..." describe-input-method
1238 :visible default-enable-multibyte-characters
1239 :help "Keyboard layout for specific input method"))
1240 (define-key menu-bar-describe-menu [describe-language-environment]
1241 (list 'menu-item "Describe Language Environment"
1242 describe-language-environment-map))
1244 (define-key menu-bar-describe-menu [separator-desc-mule]
1245 '("--"))
1247 (define-key menu-bar-describe-menu [list-keybindings]
1248 '(menu-item "List Key Bindings" describe-bindings
1249 :help "Display all current keybindings (keyboard shortcuts)"))
1250 (define-key menu-bar-describe-menu [describe-current-display-table]
1251 '(menu-item "Describe Display Table" describe-current-display-table
1252 :help "Describe the current display table"))
1253 (define-key menu-bar-describe-menu [describe-face]
1254 '(menu-item "Describe Face..." describe-face
1255 :help "Display the properties of a face"))
1256 (define-key menu-bar-describe-menu [describe-variable]
1257 '(menu-item "Describe Variable..." describe-variable
1258 :help "Display documentation of variable/option"))
1259 (define-key menu-bar-describe-menu [describe-function]
1260 '(menu-item "Describe Function..." describe-function
1261 :help "Display documentation of function/command"))
1262 (define-key menu-bar-describe-menu [describe-key-1]
1263 '(menu-item "Describe Key or Mouse Operation..." describe-key
1264 ;; Users typically don't identify keys and menu items...
1265 :help "Display documentation of command bound to a \
1266 key, a click, or a menu-item"))
1267 (define-key menu-bar-describe-menu [describe-mode]
1268 '(menu-item "Describe Buffer Modes" describe-mode
1269 :help "Describe this buffer's major and minor mode"))
1271 (defvar menu-bar-apropos-menu (make-sparse-keymap "Apropos"))
1272 (defun menu-bar-read-lispref ()
1273 "Display the Emacs Lisp Reference manual in Info mode."
1274 (interactive)
1275 (info "elisp"))
1277 (defun menu-bar-read-lispintro ()
1278 "Display the Introduction to Emacs Lisp Programming in Info mode."
1279 (interactive)
1280 (info "eintr"))
1282 (defun search-emacs-glossary ()
1283 "Display the Glossary node of the Emacs manual in Info mode."
1284 (interactive)
1285 (info "(emacs)Glossary"))
1287 (defun emacs-index-search (topic)
1288 "Look up TOPIC in the indices of the Emacs User Manual."
1289 (interactive "sSubject to look up: ")
1290 (info "emacs")
1291 (Info-index topic))
1293 (defun elisp-index-search (topic)
1294 "Look up TOPIC in the indices of the Emacs Lisp Reference Manual."
1295 (interactive "sSubject to look up: ")
1296 (info "elisp")
1297 (Info-index topic))
1299 (define-key menu-bar-apropos-menu [apropos-documentation]
1300 '(menu-item "Search Documentation Strings..." apropos-documentation
1301 :help
1302 "Find functions and variables whose doc strings match a regexp"))
1303 (define-key menu-bar-apropos-menu [apropos]
1304 '(menu-item "Find Any Object by Name..." apropos
1305 :help "Find symbols of any kind whose names match a regexp"))
1306 (define-key menu-bar-apropos-menu [apropos-value]
1307 '(menu-item "Find Options by Value..." apropos-value
1308 :help "Find variables whose values match a regexp"))
1309 (define-key menu-bar-apropos-menu [apropos-variables]
1310 '(menu-item "Find Options by Name..." apropos-variable
1311 :help "Find variables whose names match a regexp"))
1312 (define-key menu-bar-apropos-menu [apropos-commands]
1313 '(menu-item "Find Commands by Name..." apropos-command
1314 :help "Find commands whose names match a regexp"))
1315 (define-key menu-bar-apropos-menu [sep1]
1316 '("--"))
1317 (define-key menu-bar-apropos-menu [emacs-command-node]
1318 '(menu-item "Look Up Command in User Manual..." Info-goto-emacs-command-node
1319 :help "Display manual section that describes a command"))
1320 (define-key menu-bar-apropos-menu [emacs-key-command-node]
1321 '(menu-item "Look Up Key in User Manual..." Info-goto-emacs-key-command-node
1322 :help "Display manual section that describes a key"))
1323 (define-key menu-bar-apropos-menu [elisp-index-search]
1324 '(menu-item "Look Up Subject in ELisp Manual..." elisp-index-search
1325 :help "Find description of a subject in Emacs Lisp manual"))
1326 (define-key menu-bar-apropos-menu [emacs-index-search]
1327 '(menu-item "Look Up Subject in User Manual..." emacs-index-search
1328 :help "Find description of a subject in Emacs User manual"))
1329 (define-key menu-bar-apropos-menu [emacs-glossary]
1330 '(menu-item "Emacs Terminology" search-emacs-glossary
1331 :help "Display the Glossary section of the Emacs manual"))
1333 (defvar menu-bar-manuals-menu (make-sparse-keymap "More Manuals"))
1335 (define-key menu-bar-manuals-menu [man]
1336 '(menu-item "Read Man Page..." manual-entry
1337 :help "Man-page docs for external commands and libraries"))
1338 (define-key menu-bar-manuals-menu [sep2]
1339 '("--"))
1340 (define-key menu-bar-manuals-menu [order-emacs-manuals]
1341 '(menu-item "Ordering Manuals" view-order-manuals
1342 :help "How to order manuals from the Free Software Foundation"))
1343 (define-key menu-bar-manuals-menu [info-apropos]
1344 '(menu-item "Lookup Subject in all manuals..." info-apropos
1345 :help "Find description of a subject in all installed manuals"))
1346 (define-key menu-bar-manuals-menu [info]
1347 '(menu-item "All Other Manuals (Info)" Info-directory
1348 :help "Read any of the installed manuals"))
1349 (define-key menu-bar-manuals-menu [info-elisp]
1350 '(menu-item "Emacs Lisp Reference" menu-bar-read-lispref
1351 :help "Read the Emacs Lisp Reference manual"))
1352 (define-key menu-bar-manuals-menu [info-elintro]
1353 '(menu-item "Introduction to Emacs Lisp" menu-bar-read-lispintro
1354 :help "Read the Introduction to Emacs Lisp Programming"))
1356 (define-key menu-bar-help-menu [eliza]
1357 '(menu-item "Emacs Psychotherapist" doctor
1358 :help "Our doctor will help you feel better"))
1359 (define-key menu-bar-help-menu [sep4]
1360 '("--"))
1361 (define-key menu-bar-help-menu [describe-no-warranty]
1362 '(menu-item "(Non)Warranty" describe-no-warranty
1363 :help "Explain that Emacs has NO WARRANTY"))
1364 (define-key menu-bar-help-menu [describe-copying]
1365 '(menu-item "Copying Conditions" describe-copying
1366 :help "Show the Emacs license (GPL)"))
1367 (define-key menu-bar-help-menu [describe-project]
1368 '(menu-item "About GNU" describe-project
1369 :help "About the GNU System, GNU Project, and GNU/Linux"))
1370 (define-key menu-bar-help-menu [describe-distribution]
1371 '(menu-item "Getting New Versions" describe-distribution
1372 :help "How to get latest versions of Emacs"))
1373 (define-key menu-bar-help-menu [more]
1374 '(menu-item "External Packages" menu-bar-help-extra-packages
1375 :help "Lisp packages distributed separately for use in Emacs"))
1376 (defun menu-bar-help-extra-packages ()
1377 "Display help about some additional packages available for Emacs."
1378 (interactive)
1379 (let (enable-local-variables)
1380 (view-file (expand-file-name "MORE.STUFF"
1381 data-directory))
1382 (goto-address)))
1383 (define-key menu-bar-help-menu [about]
1384 '(menu-item "About Emacs" about-emacs
1385 :help "Display version number, copyright info, and basic help"))
1386 (define-key menu-bar-help-menu [sep2]
1387 '("--"))
1388 (define-key menu-bar-help-menu [finder-by-keyword]
1389 '(menu-item "Find Emacs Packages" finder-by-keyword
1390 :help "Find packages and features by keyword"))
1391 (define-key menu-bar-help-menu [manuals]
1392 (list 'menu-item "More Manuals" menu-bar-manuals-menu))
1393 (define-key menu-bar-help-menu [emacs-manual]
1394 '(menu-item "Read the Emacs Manual" info-emacs-manual
1395 :help "Full documentation of Emacs features"))
1396 (define-key menu-bar-help-menu [describe]
1397 (list 'menu-item "Describe" menu-bar-describe-menu))
1398 (define-key menu-bar-help-menu [apropos]
1399 (list 'menu-item "Search Documentation" menu-bar-apropos-menu))
1400 (define-key menu-bar-help-menu [sep1]
1401 '("--"))
1402 (define-key menu-bar-help-menu [report-emacs-bug]
1403 '(menu-item "Send Bug Report..." report-emacs-bug
1404 :help "Send e-mail to Emacs maintainers"))
1405 (define-key menu-bar-help-menu [emacs-problems]
1406 '(menu-item "Emacs Known Problems" view-emacs-problems
1407 :help "Read about known problems with Emacs"))
1408 (define-key menu-bar-help-menu [emacs-news]
1409 '(menu-item "Emacs News" view-emacs-news
1410 :help "New features of this version"))
1411 (define-key menu-bar-help-menu [emacs-faq]
1412 '(menu-item "Emacs FAQ" view-emacs-FAQ
1413 :help "Frequently asked (and answered) questions about Emacs"))
1415 (defun help-with-tutorial-spec-language ()
1416 "Use the Emacs tutorial, specifying which language you want."
1417 (interactive)
1418 (help-with-tutorial t))
1420 (define-key menu-bar-help-menu [emacs-tutorial-language-specific]
1421 '(menu-item "Emacs Tutorial (choose language)..."
1422 help-with-tutorial-spec-language
1423 :help "Learn how to use Emacs (choose a language)"))
1424 (define-key menu-bar-help-menu [emacs-tutorial]
1425 '(menu-item "Emacs Tutorial" help-with-tutorial
1426 :help "Learn how to use Emacs"))
1428 (defun menu-bar-menu-frame-live-and-visible-p ()
1429 "Return non-nil if the menu frame is alive and visible.
1430 The menu frame is the frame for which we are updating the menu."
1431 (let ((menu-frame (or menu-updating-frame (selected-frame))))
1432 (and (frame-live-p menu-frame)
1433 (frame-visible-p menu-frame))))
1435 (defun menu-bar-non-minibuffer-window-p ()
1436 "Return non-nil if selected window of the menu frame is not a minibuf window.
1438 See the documentation of `menu-bar-menu-frame-live-and-visible-p'
1439 for the definition of the menu frame."
1440 (let ((menu-frame (or menu-updating-frame (selected-frame))))
1441 (not (window-minibuffer-p (frame-selected-window menu-frame)))))
1443 (defun kill-this-buffer () ; for the menu bar
1444 "Kill the current buffer."
1445 (interactive)
1446 (kill-buffer (current-buffer)))
1448 (defun kill-this-buffer-enabled-p ()
1449 (let ((count 0)
1450 (buffers (buffer-list)))
1451 (while buffers
1452 (or (string-match "^ " (buffer-name (car buffers)))
1453 (setq count (1+ count)))
1454 (setq buffers (cdr buffers)))
1455 (and (menu-bar-non-minibuffer-window-p)
1456 (> count 1))))
1458 (put 'dired 'menu-enable '(menu-bar-non-minibuffer-window-p))
1460 ;; Permit deleting frame if it would leave a visible or iconified frame.
1461 (defun delete-frame-enabled-p ()
1462 "Return non-nil if `delete-frame' should be enabled in the menu bar."
1463 (let ((frames (frame-list))
1464 (count 0))
1465 (while frames
1466 (if (frame-visible-p (car frames))
1467 (setq count (1+ count)))
1468 (setq frames (cdr frames)))
1469 (> count 1)))
1471 (defcustom yank-menu-length 20
1472 "*Maximum length to display in the yank-menu."
1473 :type 'integer
1474 :group 'mouse)
1476 (defun menu-bar-update-yank-menu (string old)
1477 (let ((front (car (cdr yank-menu)))
1478 (menu-string (if (<= (length string) yank-menu-length)
1479 string
1480 (concat
1481 (substring string 0 (/ yank-menu-length 2))
1482 "..."
1483 (substring string (- (/ yank-menu-length 2)))))))
1484 ;; Don't let the menu string be all dashes
1485 ;; because that has a special meaning in a menu.
1486 (if (string-match "\\`-+\\'" menu-string)
1487 (setq menu-string (concat menu-string " ")))
1488 ;; If we're supposed to be extending an existing string, and that
1489 ;; string really is at the front of the menu, then update it in place.
1490 (if (and old (or (eq old (car front))
1491 (string= old (car front))))
1492 (progn
1493 (setcar front string)
1494 (setcar (cdr front) menu-string))
1495 (setcdr yank-menu
1496 (cons
1497 (cons string (cons menu-string 'menu-bar-select-yank))
1498 (cdr yank-menu)))))
1499 (if (> (length (cdr yank-menu)) kill-ring-max)
1500 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
1502 (put 'menu-bar-select-yank 'apropos-inhibit t)
1503 (defun menu-bar-select-yank ()
1504 "Insert the stretch of previously-killed text selected from menu.
1505 The menu shows all the killed text sequences stored in `kill-ring'."
1506 (interactive "*")
1507 (push-mark (point))
1508 (insert last-command-event))
1511 (defcustom buffers-menu-show-directories 'unless-uniquify
1512 "If non-nil, show directories in the Buffers menu for buffers that have them.
1513 The special value `unless-uniquify' means that directories will be shown
1514 unless `uniquify-buffer-name-style' is non-nil (in which case, buffer
1515 names should include enough of a buffer's directory to distinguish it
1516 from other buffers).
1518 Setting this variable directly does not take effect until next time the
1519 Buffers menu is regenerated."
1520 :set (lambda (symbol value)
1521 (set symbol value)
1522 (menu-bar-update-buffers t))
1523 :initialize 'custom-initialize-default
1524 :type '(choice (const :tag "Never" nil)
1525 (const :tag "Unless uniquify is enabled" unless-uniquify)
1526 (const :tag "Always" t))
1527 :group 'menu)
1529 (defcustom buffers-menu-show-status t
1530 "If non-nil, show modified/read-only status of buffers in the Buffers menu.
1531 Setting this variable directly does not take effect until next time the
1532 Buffers menu is regenerated."
1533 :set (lambda (symbol value)
1534 (set symbol value)
1535 (menu-bar-update-buffers t))
1536 :initialize 'custom-initialize-default
1537 :type 'boolean
1538 :group 'menu)
1540 (defvar list-buffers-directory nil)
1542 (defvar menu-bar-update-buffers-maxbuf)
1544 (defun menu-bar-select-buffer ()
1545 (interactive)
1546 (switch-to-buffer last-command-event))
1548 (defun menu-bar-select-frame ()
1549 (interactive)
1550 (let (frame)
1551 (dolist (f (frame-list))
1552 (when (equal last-command-event (frame-parameter f 'name))
1553 (setq frame f)))
1554 ;; FRAME can be nil when user specifies the selected frame.
1555 (setq frame (or frame (selected-frame)))
1556 (make-frame-visible frame)
1557 (raise-frame frame)
1558 (select-frame frame)))
1560 (defun menu-bar-update-buffers-1 (elt)
1561 (let* ((buf (car elt))
1562 (file
1563 (and (if (eq buffers-menu-show-directories 'unless-uniquify)
1564 (or (not (boundp 'uniquify-buffer-name-style))
1565 (null uniquify-buffer-name-style))
1566 buffers-menu-show-directories)
1567 (or (buffer-file-name buf)
1568 (buffer-local-value 'list-buffers-directory buf)))))
1569 (when file
1570 (setq file (file-name-directory file)))
1571 (when (and file (> (length file) 20))
1572 (setq file (concat "..." (substring file -17))))
1573 (cons (if buffers-menu-show-status
1574 (let ((mod (if (buffer-modified-p buf) "*" ""))
1575 (ro (if (buffer-local-value 'buffer-read-only buf) "%" "")))
1576 (if file
1577 (format "%s %s%s -- %s" (cdr elt) mod ro file)
1578 (format "%s %s%s" (cdr elt) mod ro)))
1579 (if file
1580 (format "%s -- %s" (cdr elt) file)
1581 (cdr elt)))
1582 buf)))
1584 ;; Used to cache the menu entries for commands in the Buffers menu
1585 (defvar menu-bar-buffers-menu-command-entries nil)
1587 (defun menu-bar-update-buffers (&optional force)
1588 ;; If user discards the Buffers item, play along.
1589 (and (lookup-key (current-global-map) [menu-bar buffer])
1590 (or force (frame-or-buffer-changed-p))
1591 (let ((buffers (buffer-list))
1592 (frames (frame-list))
1593 buffers-menu frames-menu)
1594 ;; If requested, list only the N most recently selected buffers.
1595 (if (and (integerp buffers-menu-max-size)
1596 (> buffers-menu-max-size 1))
1597 (if (> (length buffers) buffers-menu-max-size)
1598 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
1600 ;; Make the menu of buffers proper.
1601 (setq buffers-menu
1602 (let* ((buffer-list
1603 (mapcar 'list buffers))
1604 (menu-bar-update-buffers-maxbuf 0)
1605 alist)
1606 ;; Put into each element of buffer-list
1607 ;; the name for actual display,
1608 ;; perhaps truncated in the middle.
1609 (dolist (buf buffer-list)
1610 (let ((name (buffer-name (car buf))))
1611 (setcdr buf
1612 (if (> (length name) 27)
1613 (concat (substring name 0 12)
1614 "..."
1615 (substring name -12))
1616 name))))
1617 ;; Compute the maximum length of any name.
1618 (dolist (buf buffer-list)
1619 (unless (eq ?\s (aref (cdr buf) 0))
1620 (setq menu-bar-update-buffers-maxbuf
1621 (max menu-bar-update-buffers-maxbuf
1622 (length (cdr buf))))))
1623 ;; Set ALIST to an alist of the form
1624 ;; ITEM-STRING . BUFFER
1625 (dolist (buf buffer-list)
1626 (unless (eq ?\s (aref (cdr buf) 0))
1627 (push (menu-bar-update-buffers-1 buf) alist)))
1628 ;; Now make the actual list of items, and add
1629 ;; some miscellaneous buffer commands to the end.
1630 (mapcar (lambda (pair)
1631 ;; This is somewhat risque, to use
1632 ;; the buffer name itself as the event
1633 ;; type to define, but it works.
1634 ;; It would not work to use the buffer
1635 ;; since a buffer as an event has its
1636 ;; own meaning.
1637 (nconc (list (buffer-name (cdr pair))
1638 (car pair)
1639 (cons nil nil))
1640 'menu-bar-select-buffer))
1641 (nreverse alist))))
1643 ;; Make a Frames menu if we have more than one frame.
1644 (when (cdr frames)
1645 (let ((frames-menu
1646 (cons 'keymap
1647 (cons "Select Frame"
1648 (mapcar
1649 (lambda (frame)
1650 (nconc
1651 (list (frame-parameter frame 'name)
1652 (frame-parameter frame 'name)
1653 (cons nil nil))
1654 'menu-bar-select-frame))
1655 frames)))))
1656 ;; Put it after the normal buffers
1657 (setq buffers-menu
1658 (nconc buffers-menu
1659 `((frames-separator "--")
1660 (frames menu-item "Frames" ,frames-menu))))))
1662 ;; Add in some normal commands at the end of the menu. We use
1663 ;; the copy cached in `menu-bar-buffers-menu-command-entries'
1664 ;; if it's been set already. Note that we can't use constant
1665 ;; lists for the menu-entries, because the low-level menu-code
1666 ;; modifies them.
1667 (unless menu-bar-buffers-menu-command-entries
1668 (setq menu-bar-buffers-menu-command-entries
1669 (list '(command-separator "--")
1670 (list 'next-buffer
1671 'menu-item
1672 "Next Buffer"
1673 'next-buffer
1674 :help "Switch to the \"next\" buffer in a cyclic order")
1675 (list 'previous-buffer
1676 'menu-item
1677 "Previous Buffer"
1678 'previous-buffer
1679 :help "Switch to the \"previous\" buffer in a cyclic order")
1680 (list 'select-named-buffer
1681 'menu-item
1682 "Select Named Buffer..."
1683 'switch-to-buffer
1684 :help "Prompt for a buffer name, and select that buffer in the current window")
1685 (list 'list-all-buffers
1686 'menu-item
1687 "List All Buffers"
1688 'list-buffers
1689 :help "Pop up a window listing all Emacs buffers"
1690 ))))
1691 (setq buffers-menu
1692 (nconc buffers-menu menu-bar-buffers-menu-command-entries))
1694 (setq buffers-menu (cons 'keymap (cons "Select Buffer" buffers-menu)))
1695 (define-key (current-global-map) [menu-bar buffer]
1696 ;; Call copy-sequence so the string is not pure.
1697 (cons (copy-sequence "Buffers") buffers-menu)))))
1699 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
1701 (menu-bar-update-buffers)
1703 ;; this version is too slow
1704 ;;(defun format-buffers-menu-line (buffer)
1705 ;; "Returns a string to represent the given buffer in the Buffer menu.
1706 ;;nil means the buffer shouldn't be listed. You can redefine this."
1707 ;; (if (string-match "\\` " (buffer-name buffer))
1708 ;; nil
1709 ;; (save-excursion
1710 ;; (set-buffer buffer)
1711 ;; (let ((size (buffer-size)))
1712 ;; (format "%s%s %-19s %6s %-15s %s"
1713 ;; (if (buffer-modified-p) "*" " ")
1714 ;; (if buffer-read-only "%" " ")
1715 ;; (buffer-name)
1716 ;; size
1717 ;; mode-name
1718 ;; (or (buffer-file-name) ""))))))
1720 ;;; Set up a menu bar menu for the minibuffer.
1722 (dolist (map (list minibuffer-local-map
1723 ;; This shouldn't be necessary, but there's a funny
1724 ;; bug in keymap.c that I don't understand yet. -stef
1725 minibuffer-local-completion-map))
1726 (define-key map [menu-bar minibuf]
1727 (cons "Minibuf" (make-sparse-keymap "Minibuf"))))
1729 (let ((map minibuffer-local-completion-map))
1730 (define-key map [menu-bar minibuf ?\?]
1731 (list 'menu-item "List Completions" 'minibuffer-completion-help
1732 :help "Display all possible completions"))
1733 (define-key map [menu-bar minibuf space]
1734 (list 'menu-item "Complete Word" 'minibuffer-complete-word
1735 :help "Complete at most one word"))
1736 (define-key map [menu-bar minibuf tab]
1737 (list 'menu-item "Complete" 'minibuffer-complete
1738 :help "Complete as far as possible")))
1740 (let ((map minibuffer-local-map))
1741 (define-key map [menu-bar minibuf quit]
1742 (list 'menu-item "Quit" 'keyboard-escape-quit
1743 :help "Abort input and exit minibuffer"))
1744 (define-key map [menu-bar minibuf return]
1745 (list 'menu-item "Enter" 'exit-minibuffer
1746 :help "Terminate input and exit minibuffer")))
1748 ;;;###autoload
1749 ;; This comment is taken from tool-bar.el near
1750 ;; (put 'tool-bar-mode ...)
1751 ;; We want to pretend the menu bar by standard is on, as this will make
1752 ;; customize consider disabling the menu bar a customization, and save
1753 ;; that. We could do this for real by setting :init-value below, but
1754 ;; that would overwrite disabling the tool bar from X resources.
1755 (put 'menu-bar-mode 'standard-value '(t))
1757 ;;;###autoload
1758 (define-minor-mode menu-bar-mode
1759 "Toggle display of a menu bar on each frame.
1760 This command applies to all frames that exist and frames to be
1761 created in the future.
1762 With a numeric argument, if the argument is positive,
1763 turn on menu bars; otherwise, turn off menu bars."
1764 :init-value nil
1765 :global t
1766 :group 'frames
1767 ;; Make menu-bar-mode and default-frame-alist consistent.
1768 (let ((lines (if menu-bar-mode 1 0)))
1769 ;; Alter existing frames...
1770 (mapc (lambda (frame)
1771 (modify-frame-parameters frame
1772 (list (cons 'menu-bar-lines lines))))
1773 (frame-list))
1774 ;; ...and future ones.
1775 (let ((elt (assq 'menu-bar-lines default-frame-alist)))
1776 (if elt
1777 (setcdr elt lines)
1778 (add-to-list 'default-frame-alist (cons 'menu-bar-lines lines)))))
1780 ;; Make the message appear when Emacs is idle. We can not call message
1781 ;; directly. The minor-mode message "Menu-bar mode disabled" comes
1782 ;; after this function returns, overwriting any message we do here.
1783 (when (and (interactive-p) (not menu-bar-mode))
1784 (run-with-idle-timer 0 nil 'message
1785 "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear."))
1786 menu-bar-mode)
1788 (provide 'menu-bar)
1790 ;;; arch-tag: 6e6a3c22-4ec4-4d3d-8190-583f8ef94ced
1791 ;;; menu-bar.el ends here