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