(Revert Buffer): Condition on buffer-file-number.
[emacs.git] / lisp / menu-bar.el
blob2c0dbd6e2536bfd7d75d1b444e1cdf85d28bb32f
1 ;;; menu-bar.el --- define a default menu bar
3 ;; Copyright (C) 1993, 1994, 1995, 2000, 2001, 2002 Free Software Foundation, Inc.
5 ;; Author: RMS
6 ;; Maintainer: FSF
7 ;; Keywords: internal, mouse
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;; Avishai Yacobi suggested some menu rearrangements.
28 ;;; Commentary:
30 ;;; Code:
32 ;;; User options:
34 (defcustom buffers-menu-max-size 10
35 "*Maximum number of entries which may appear on the Buffers menu.
36 If this is 10, then only the ten most-recently-selected buffers are shown.
37 If this is nil, then all buffers are shown.
38 A large number or nil slows down menu responsiveness."
39 :type '(choice integer
40 (const :tag "All" nil))
41 :group 'mouse)
43 ;; Don't clobber an existing menu-bar keymap, to preserve any menu-bar key
44 ;; definitions made in loaddefs.el.
45 (or (lookup-key global-map [menu-bar])
46 (define-key global-map [menu-bar] (make-sparse-keymap "menu-bar")))
47 (defvar menu-bar-help-menu (make-sparse-keymap "Help"))
49 ;; Force Help item to come last, after the major mode's own items.
50 ;; The symbol used to be called `help', but that gets confused with the
51 ;; help key.
52 (setq menu-bar-final-items '(help-menu))
54 (define-key global-map [menu-bar help-menu] (cons "Help" menu-bar-help-menu))
55 (defvar menu-bar-tools-menu (make-sparse-keymap "Tools"))
56 (define-key global-map [menu-bar tools] (cons "Tools" menu-bar-tools-menu))
57 ;; This definition is just to show what this looks like.
58 ;; It gets overridden below when menu-bar-update-buffers is called.
59 (define-key global-map [menu-bar buffer]
60 (cons "Buffers" (make-sparse-keymap "Buffers")))
61 (defvar menu-bar-options-menu (make-sparse-keymap "Options"))
62 (define-key global-map [menu-bar options]
63 (cons "Options" menu-bar-options-menu))
64 (defvar menu-bar-edit-menu (make-sparse-keymap "Edit"))
65 (define-key global-map [menu-bar edit] (cons "Edit" menu-bar-edit-menu))
66 (defvar menu-bar-files-menu (make-sparse-keymap "File"))
67 (define-key global-map [menu-bar files] (cons "File" menu-bar-files-menu))
69 ;; This alias is for compatibility with 19.28 and before.
70 (defvar menu-bar-file-menu menu-bar-files-menu)
72 ;; This is referenced by some code below; it is defined in uniquify.el
73 (defvar uniquify-buffer-name-style)
76 ;; The "File" menu items
77 (define-key menu-bar-files-menu [exit-emacs]
78 '(menu-item "Exit Emacs" save-buffers-kill-emacs
79 :help "Save unsaved buffers, then exit"))
81 (define-key menu-bar-files-menu [separator-exit]
82 '("--"))
84 ;; Don't use delete-frame as event name because that is a special
85 ;; event.
86 (define-key menu-bar-files-menu [delete-this-frame]
87 '(menu-item "Delete Frame" delete-frame
88 :visible (fboundp 'delete-frame)
89 :enable (delete-frame-enabled-p)
90 :help "Delete currently selected frame"))
91 (define-key menu-bar-files-menu [make-frame-on-display]
92 '(menu-item "New Frame on Display..." make-frame-on-display
93 :visible (fboundp 'make-frame-on-display)
94 :help "Open a new frame on another display"))
95 (define-key menu-bar-files-menu [make-frame]
96 '(menu-item "New Frame" make-frame-command
97 :visible (fboundp 'make-frame-command)
98 :help "Open a new frame"))
100 (define-key menu-bar-files-menu [one-window]
101 '(menu-item "Unsplit Windows" delete-other-windows
102 :enable (not (one-window-p t nil))
103 :help "Make selected window fill its frame"))
105 (define-key menu-bar-files-menu [split-window]
106 '(menu-item "Split Window" split-window-vertically
107 :help "Split selected window in two"))
109 (define-key menu-bar-files-menu [separator-window]
110 '(menu-item "--"))
112 (define-key menu-bar-files-menu [ps-print-region]
113 '(menu-item "Postscript Print Region (B+W)" ps-print-region
114 :enable mark-active
115 :help "Pretty-print marked region in black and white to PostScript printer"))
116 (define-key menu-bar-files-menu [ps-print-buffer]
117 '(menu-item "Postscript Print Buffer (B+W)" ps-print-buffer
118 :help "Pretty-print current buffer in black and white to PostScript printer"))
119 (define-key menu-bar-files-menu [ps-print-region-faces]
120 '(menu-item "Postscript Print Region" ps-print-region-with-faces
121 :enable mark-active
122 :help "Pretty-print marked region to PostScript printer"))
123 (define-key menu-bar-files-menu [ps-print-buffer-faces]
124 '(menu-item "Postscript Print Buffer" ps-print-buffer-with-faces
125 :help "Pretty-print current buffer to PostScript printer"))
126 (define-key menu-bar-files-menu [print-region]
127 '(menu-item "Print Region" print-region
128 :enable mark-active
129 :help "Print region between mark and current position"))
130 (define-key menu-bar-files-menu [print-buffer]
131 '(menu-item "Print Buffer" print-buffer
132 :help "Print current buffer with page headings"))
134 (define-key menu-bar-files-menu [separator-print]
135 '(menu-item "--"))
137 (define-key menu-bar-files-menu [recover-session]
138 '(menu-item "Recover Crashed Session..." recover-session
139 :enable (and auto-save-list-file-prefix
140 (file-directory-p
141 (file-name-directory auto-save-list-file-prefix))
142 (directory-files
143 (file-name-directory auto-save-list-file-prefix)
145 (concat "\\`"
146 (regexp-quote
147 (file-name-nondirectory
148 auto-save-list-file-prefix)))
150 :help "Recover edits from a crashed session"))
151 (define-key menu-bar-files-menu [revert-buffer]
152 '(menu-item "Revert Buffer" revert-buffer
153 :enable (or revert-buffer-function
154 revert-buffer-insert-file-contents-function
155 (and buffer-file-number
156 (or (buffer-modified-p)
157 (not (verify-visited-file-modtime
158 (current-buffer))))))
159 :help "Re-read current buffer from its file"))
160 (define-key menu-bar-files-menu [write-file]
161 '(menu-item "Save Buffer As..." write-file
162 :enable (not (window-minibuffer-p
163 (frame-selected-window menu-updating-frame)))
164 :help "Write current buffer to another file"))
165 (define-key menu-bar-files-menu [save-buffer]
166 '(menu-item "Save (current buffer)" save-buffer
167 :enable (and (buffer-modified-p)
168 (buffer-file-name)
169 (not (window-minibuffer-p
170 (frame-selected-window menu-updating-frame))))
171 :help "Save current buffer to its file"))
173 (define-key menu-bar-files-menu [separator-save]
174 '(menu-item "--"))
176 (define-key menu-bar-files-menu [kill-buffer]
177 '(menu-item "Close (current buffer)" kill-this-buffer
178 :enable (kill-this-buffer-enabled-p)
179 :help "Discard current buffer"))
180 (define-key menu-bar-files-menu [insert-file]
181 '(menu-item "Insert File..." insert-file
182 :enable (not (window-minibuffer-p
183 (frame-selected-window menu-updating-frame)))
184 :help "Insert another file into current buffer"))
185 (define-key menu-bar-files-menu [dired]
186 '(menu-item "Open Directory..." dired
187 :help "Read a directory, operate on its files"))
188 (define-key menu-bar-files-menu [open-file]
189 '(menu-item "Open File..." find-file
190 :enable (not (window-minibuffer-p
191 (frame-selected-window menu-updating-frame)))
192 :help "Read a file into an Emacs buffer"))
195 ;; The "Edit" menu items
197 ;; The "Edit->Search" submenu
198 (defvar menu-bar-last-search-type nil
199 "Type of last non-incremental search command called from the menu.")
201 (defun nonincremental-repeat-search-forward ()
202 "Search forward for the previous search string or regexp."
203 (interactive)
204 (cond
205 ((and (eq menu-bar-last-search-type 'string)
206 search-ring)
207 (search-forward (car search-ring)))
208 ((and (eq menu-bar-last-search-type 'regexp)
209 regexp-search-ring)
210 (re-search-forward (car regexp-search-ring)))
212 (error "No previous search"))))
214 (defun nonincremental-repeat-search-backward ()
215 "Search backward for the previous search string or regexp."
216 (interactive)
217 (cond
218 ((and (eq menu-bar-last-search-type 'string)
219 search-ring)
220 (search-backward (car search-ring)))
221 ((and (eq menu-bar-last-search-type 'regexp)
222 regexp-search-ring)
223 (re-search-backward (car regexp-search-ring)))
225 (error "No previous search"))))
227 (defun nonincremental-search-forward (string)
228 "Read a string and search for it nonincrementally."
229 (interactive "sSearch for string: ")
230 (setq menu-bar-last-search-type 'string)
231 (if (equal string "")
232 (search-forward (car search-ring))
233 (isearch-update-ring string nil)
234 (search-forward string)))
236 (defun nonincremental-search-backward (string)
237 "Read a string and search backward for it nonincrementally."
238 (interactive "sSearch for string: ")
239 (setq menu-bar-last-search-type 'string)
240 (if (equal string "")
241 (search-backward (car search-ring))
242 (isearch-update-ring string nil)
243 (search-backward string)))
245 (defun nonincremental-re-search-forward (string)
246 "Read a regular expression and search for it nonincrementally."
247 (interactive "sSearch for regexp: ")
248 (setq menu-bar-last-search-type 'regexp)
249 (if (equal string "")
250 (re-search-forward (car regexp-search-ring))
251 (isearch-update-ring string t)
252 (re-search-forward string)))
254 (defun nonincremental-re-search-backward (string)
255 "Read a regular expression and search backward for it nonincrementally."
256 (interactive "sSearch for regexp: ")
257 (setq menu-bar-last-search-type 'regexp)
258 (if (equal string "")
259 (re-search-backward (car regexp-search-ring))
260 (isearch-update-ring string t)
261 (re-search-backward string)))
263 (defvar menu-bar-search-menu (make-sparse-keymap "Search"))
265 ;; The Edit->Search->Incremental Search menu
266 (defvar menu-bar-i-search-menu
267 (make-sparse-keymap "Incremental Search"))
269 (define-key menu-bar-i-search-menu [isearch-backward-regexp]
270 '(menu-item "Backward Regexp..." isearch-backward-regexp
271 :help "Search backwards for a regular expression as you type it"))
272 (define-key menu-bar-i-search-menu [isearch-forward-regexp]
273 '(menu-item "Forward Regexp..." isearch-forward-regexp
274 :help "Search forward for a regular expression as you type it"))
275 (define-key menu-bar-i-search-menu [isearch-backward]
276 '(menu-item "Backward String..." isearch-backward
277 :help "Search backwards for a string as you type it"))
278 (define-key menu-bar-i-search-menu [isearch-forward]
279 '(menu-item "Forward String..." isearch-forward
280 :help "Search forward for a string as you type it"))
283 (define-key menu-bar-search-menu [i-search]
284 (list 'menu-item "Incremental Search" menu-bar-i-search-menu
285 :help "Incremental Search finds partial matches while you type the search string.\nIt is most convenient from the keyboard. Try it!"))
286 (define-key menu-bar-search-menu [separator-tag-isearch]
287 '(menu-item "--"))
289 (define-key menu-bar-search-menu [tags-continue]
290 '(menu-item "Continue Tags Search" tags-loop-continue
291 :help "Continue last tags search operation"))
292 (define-key menu-bar-search-menu [tags-srch]
293 '(menu-item "Search tagged files" tags-search
294 :help "Search for a regexp in all tagged files"))
295 (define-key menu-bar-search-menu [separator-tag-search]
296 '(menu-item "--"))
298 (define-key menu-bar-search-menu [repeat-search-back]
299 '(menu-item "Repeat Backwards" nonincremental-repeat-search-backward
300 :enable (or (and (eq menu-bar-last-search-type 'string)
301 search-ring)
302 (and (eq menu-bar-last-search-type 'regexp)
303 regexp-search-ring))
304 :help "Repeat last search backwards"))
305 (define-key menu-bar-search-menu [repeat-search-fwd]
306 '(menu-item "Repeat Forward" nonincremental-repeat-search-forward
307 :enable (or (and (eq menu-bar-last-search-type 'string)
308 search-ring)
309 (and (eq menu-bar-last-search-type 'regexp)
310 regexp-search-ring))
311 :help "Repeat last search forward"))
312 (define-key menu-bar-search-menu [separator-repeat-search]
313 '(menu-item "--"))
315 (define-key menu-bar-search-menu [re-search-backward]
316 '(menu-item "Regexp Backwards..." nonincremental-re-search-backward
317 :help "Search backwards for a regular expression"))
318 (define-key menu-bar-search-menu [re-search-forward]
319 '(menu-item "Regexp Forward..." nonincremental-re-search-forward
320 :help "Search forward for a regular expression"))
322 (define-key menu-bar-search-menu [search-backward]
323 '(menu-item "String Backwards..." nonincremental-search-backward
324 :help "Search backwards for a string"))
325 (define-key menu-bar-search-menu [search-forward]
326 '(menu-item "String Forward..." nonincremental-search-forward
327 :help "Search forward for a string"))
329 ;; The Edit->Replace submenu
331 (defvar menu-bar-replace-menu (make-sparse-keymap "Replace"))
333 (define-key menu-bar-replace-menu [tags-repl-continue]
334 '(menu-item "Continue Replace" tags-loop-continue
335 :help "Continue last tags replace operation"))
336 (define-key menu-bar-replace-menu [tags-repl]
337 '(menu-item "Replace in tagged files" tags-query-replace
338 :help "Interactively replace a regexp in all tagged files"))
339 (define-key menu-bar-replace-menu [separator-replace-tags]
340 '(menu-item "--"))
342 (define-key menu-bar-replace-menu [query-replace-regexp]
343 '(menu-item "Replace Regexp..." query-replace-regexp
344 :enable (not buffer-read-only)
345 :help "Replace regular expression interactively, ask about each occurrence"))
346 (define-key menu-bar-replace-menu [query-replace]
347 '(menu-item "Replace String..." query-replace
348 :enable (not buffer-read-only)
349 :help "Replace string interactively, ask about each occurrence"))
351 ;;; Assemble the top-level Edit menu items.
352 (define-key menu-bar-edit-menu [props]
353 '(menu-item "Text Properties" facemenu-menu
354 :help "Change properties of text in region"))
356 (define-key menu-bar-edit-menu [fill]
357 '(menu-item "Fill" fill-region
358 :enable (and mark-active (not buffer-read-only))
359 :help
360 "Fill text in region to fit between left and right margin"))
362 (define-key menu-bar-edit-menu [separator-bookmark]
363 '(menu-item "--"))
365 (define-key menu-bar-edit-menu [bookmark]
366 '(menu-item "Bookmarks" menu-bar-bookmark-map
367 :help "Record positions and jump between them"))
369 (defvar menu-bar-goto-menu (make-sparse-keymap "Go To"))
371 (define-key menu-bar-goto-menu [set-tags-name]
372 '(menu-item "Set Tags File Name" visit-tags-table
373 :help "Tell Tags commands which tag table file to use"))
375 (define-key menu-bar-goto-menu [separator-tag-file]
376 '(menu-item "--"))
378 (define-key menu-bar-goto-menu [apropos-tags]
379 '(menu-item "Tags Apropos" tags-apropos
380 :help "Find function/variables whose names match regexp"))
381 (define-key menu-bar-goto-menu [next-tag-otherw]
382 '(menu-item "Next Tag in Other Window"
383 menu-bar-next-tag-other-window
384 :enable (and (boundp 'tags-location-ring)
385 (not (ring-empty-p tags-location-ring)))
386 :help "Find next function/variable matching last tag name in another window"))
388 (defun menu-bar-next-tag-other-window ()
389 "Find the next definition of the tag already specified."
390 (interactive)
391 (find-tag-other-window nil t))
393 (defun menu-bar-next-tag ()
394 "Find the next definition of the tag already specified."
395 (interactive)
396 (find-tag nil t))
398 (define-key menu-bar-goto-menu [next-tag]
399 '(menu-item "Find Next Tag"
400 menu-bar-next-tag
401 :enable (and (boundp 'tags-location-ring)
402 (not (ring-empty-p tags-location-ring)))
403 :help "Find next function/variable matching last tag name"))
404 (define-key menu-bar-goto-menu [find-tag-otherw]
405 '(menu-item "Find Tag in Other Window..." find-tag-other-window
406 :help "Find function/variable definition in another window"))
407 (define-key menu-bar-goto-menu [find-tag]
408 '(menu-item "Find Tag..." find-tag
409 :help "Find definition of function or variable"))
411 (define-key menu-bar-goto-menu [separator-tags]
412 '(menu-item "--"))
414 (define-key menu-bar-goto-menu [end-of-buf]
415 '(menu-item "Goto End of Buffer" end-of-buffer))
416 (define-key menu-bar-goto-menu [beg-of-buf]
417 '(menu-item "Goto Beginning of Buffer" beginning-of-buffer))
418 (define-key menu-bar-goto-menu [go-to-pos]
419 '(menu-item "Goto Buffer Position..." goto-char
420 :help "Read a number N and go to buffer position N"))
421 (define-key menu-bar-goto-menu [go-to-line]
422 '(menu-item "Goto Line..." goto-line
423 :help "Read a line number and go to that line"))
425 (define-key menu-bar-edit-menu [goto]
426 (list 'menu-item "Go To" menu-bar-goto-menu))
428 (define-key menu-bar-edit-menu [replace]
429 (list 'menu-item "Replace" menu-bar-replace-menu))
431 (define-key menu-bar-edit-menu [search]
432 (list 'menu-item "Search" menu-bar-search-menu))
434 (define-key menu-bar-edit-menu [separator-search]
435 '(menu-item "--"))
437 (define-key menu-bar-edit-menu [mark-whole-buffer]
438 '(menu-item "Select All" mark-whole-buffer
439 :help "Mark the whole buffer for a subsequent cut/copy."))
440 (define-key menu-bar-edit-menu [clear]
441 '(menu-item "Clear" delete-region
442 :enable (and mark-active
443 (not buffer-read-only)
444 (not (mouse-region-match)))
445 :help
446 "Delete the text in region between mark and current position"))
447 (defvar yank-menu (cons "Select Yank" nil))
448 (fset 'yank-menu (cons 'keymap yank-menu))
449 (define-key menu-bar-edit-menu [select-paste]
450 '(menu-item "Select and Paste" yank-menu
451 :enable (and (cdr yank-menu) (not buffer-read-only))
452 :help "Paste (yank) text cut or copied earlier"))
453 (define-key menu-bar-edit-menu [paste]
454 '(menu-item "Paste" yank
455 :enable (and
456 ;; Emacs compiled --without-x doesn't have
457 ;; x-selection-exists-p.
458 (fboundp 'x-selection-exists-p)
459 (x-selection-exists-p) (not buffer-read-only))
460 :help "Paste (yank) text most recently cut/copied"))
461 (define-key menu-bar-edit-menu [copy]
462 '(menu-item "Copy" menu-bar-kill-ring-save
463 :enable mark-active
464 :help "Copy text in region between mark and current position"
465 :keys "\\[kill-ring-save]"))
466 (define-key menu-bar-edit-menu [cut]
467 '(menu-item "Cut" kill-region
468 :enable (and mark-active (not buffer-read-only))
469 :help
470 "Cut (kill) text in region between mark and current position"))
471 (define-key menu-bar-edit-menu [undo]
472 '(menu-item "Undo" undo
473 :enable (and (not buffer-read-only)
474 (not (eq t buffer-undo-list))
475 (if (eq last-command 'undo)
476 pending-undo-list
477 (consp buffer-undo-list)))
478 :help "Undo last operation"))
481 (defun menu-bar-kill-ring-save (beg end)
482 (interactive "r")
483 (if (mouse-region-match)
484 (message "Selecting a region with the mouse does `copy' automatically")
485 (kill-ring-save beg end)))
487 (autoload 'ispell-menu-map "ispell" nil t 'keymap)
489 ;; These are alternative definitions for the cut, paste and copy
490 ;; menu items. Use them if your system expects these to use the clipboard.
492 (put 'clipboard-kill-region 'menu-enable 'mark-active)
493 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
494 (put 'clipboard-yank 'menu-enable
495 '(or (and (fboundp 'x-selection-exists-p) (x-selection-exists-p))
496 (x-selection-exists-p 'CLIPBOARD)))
498 (defun clipboard-yank ()
499 "Insert the clipboard contents, or the last stretch of killed text."
500 (interactive)
501 (let ((x-select-enable-clipboard t))
502 (yank)))
504 (defun clipboard-kill-ring-save (beg end)
505 "Copy region to kill ring, and save in the X clipboard."
506 (interactive "r")
507 (let ((x-select-enable-clipboard t))
508 (kill-ring-save beg end)))
510 (defun clipboard-kill-region (beg end)
511 "Kill the region, and save it in the X clipboard."
512 (interactive "r")
513 (let ((x-select-enable-clipboard t))
514 (kill-region beg end)))
516 (defun menu-bar-enable-clipboard ()
517 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
518 Do the same for the keys of the same name."
519 (interactive)
520 ;; We can't use constant list structure here because it becomes pure,
521 ;; and because it gets modified with cache data.
522 (define-key menu-bar-edit-menu [paste]
523 (cons "Paste" (cons "Paste text from clipboard" 'clipboard-yank)))
524 (define-key menu-bar-edit-menu [copy]
525 (cons "Copy" (cons "Copy text in region to the clipboard"
526 'clipboard-kill-ring-save)))
527 (define-key menu-bar-edit-menu [cut]
528 (cons "Cut" (cons "Delete text in region and copy it to the clipboard"
529 'clipboard-kill-region)))
531 (define-key global-map [f20] 'clipboard-kill-region)
532 (define-key global-map [f16] 'clipboard-kill-ring-save)
533 (define-key global-map [f18] 'clipboard-yank)
534 ;; X11R6 versions
535 (define-key global-map [cut] 'clipboard-kill-region)
536 (define-key global-map [copy] 'clipboard-kill-ring-save)
537 (define-key global-map [paste] 'clipboard-yank))
539 ;; The "Options" menu items
541 (defvar menu-bar-custom-menu (make-sparse-keymap "Customize"))
543 (define-key menu-bar-custom-menu [customize-apropos-groups]
544 '(menu-item "Groups Matching Regexp..." customize-apropos-groups
545 :help "Browse groups whose names match regexp"))
546 (define-key menu-bar-custom-menu [customize-apropos-faces]
547 '(menu-item "Faces Matching Regexp..." customize-apropos-faces
548 :help "Browse faces whose names match regexp"))
549 (define-key menu-bar-custom-menu [customize-apropos-options]
550 '(menu-item "Options Matching Regexp..." customize-apropos-options
551 :help "Browse options whose names match regexp"))
552 (define-key menu-bar-custom-menu [customize-apropos]
553 '(menu-item "Settings Matching Regexp..." customize-apropos
554 :help "Browse customizable settings whose names match regexp"))
555 (define-key menu-bar-custom-menu [separator-1]
556 '("--"))
557 (define-key menu-bar-custom-menu [customize-group]
558 '(menu-item "Specific Group..." customize-group
559 :help "Customize settings of specific group"))
560 (define-key menu-bar-custom-menu [customize-face]
561 '(menu-item "Specific Face..." customize-face
562 :help "Customize attributes of specific face"))
563 (define-key menu-bar-custom-menu [customize-option]
564 '(menu-item "Specific Option..." customize-option
565 :help "Customize value of specific option"))
566 (define-key menu-bar-custom-menu [separator-2]
567 '("--"))
568 (define-key menu-bar-custom-menu [customize-changed-options]
569 '(menu-item "New Options..." customize-changed-options
570 :help "Options added or changed in recent Emacs versions"))
571 (define-key menu-bar-custom-menu [customize-saved]
572 '(menu-item "Saved Options" customize-saved
573 :help "Customize previously saved options"))
574 (define-key menu-bar-custom-menu [separator-3]
575 '("--"))
576 (define-key menu-bar-custom-menu [customize-browse]
577 '(menu-item "Browse Customization Groups" customize-browse
578 :help "Browse all customization groups"))
579 (define-key menu-bar-custom-menu [customize]
580 '(menu-item "Top-level Customization Group" customize
581 :help "The master group called `Emacs'"))
583 ;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
585 (defmacro menu-bar-make-mm-toggle (fname doc help &optional props)
586 "Make a menu-item for a global minor mode toggle.
587 FNAME is the minor mode's name (variable and function).
588 DOC is the text to use the menu entry.
589 HELP is the text to use for the tooltip.
590 PROPS are additional properties."
591 `'(menu-item ,doc ,fname
592 ,@(if props props)
593 :help ,help
594 :button (:toggle . (and (default-boundp ',fname)
595 (default-value ',fname)))))
597 (defmacro menu-bar-make-toggle (name variable doc message help &rest body)
598 `(progn
599 (defun ,name ()
600 ,(concat "Toggle whether to " (downcase (substring help 0 1))
601 (substring help 1) ".")
602 (interactive)
603 (if ,(if body `(progn . ,body)
604 `(progn
605 (custom-load-symbol ',variable)
606 (let ((set (or (get ',variable 'custom-set) 'set-default))
607 (get (or (get ',variable 'custom-get) 'default-value)))
608 (funcall set ',variable (not (funcall get ',variable))))))
609 (message ,message "enabled")
610 (message ,message "disabled"))
611 ;; The function `customize-mark-as-set' must only be called when
612 ;; a variable is set interactively, as the purpose is to mark it as
613 ;; a candidate for "Save Options", and we do not want to save options
614 ;; the user have already set explicitly in his init file.
615 (if (interactive-p) (customize-mark-as-set ',variable)))
616 '(menu-item ,doc ,name
617 :help ,help
618 :button (:toggle . (and (default-boundp ',variable)
619 (default-value ',variable))))))
621 ;;; Assemble all the top-level items of the "Options" menu
622 (define-key menu-bar-options-menu [customize]
623 (list 'menu-item "Customize Emacs" menu-bar-custom-menu
624 :help "Full customization of every Emacs feature"))
626 (defun menu-bar-options-save ()
627 "Save current values of Options menu items using Custom."
628 (interactive)
629 (let ((need-save nil))
630 ;; These are set with `customize-set-variable'.
631 (dolist (elt '(line-number-mode column-number-mode scroll-bar-mode
632 debug-on-quit debug-on-error menu-bar-mode tool-bar-mode
633 save-place uniquify-buffer-name-style fringe-mode
634 case-fold-search cua-mode show-paren-mode
635 transient-mark-mode global-font-lock-mode
636 display-time-mode auto-compression-mode
637 current-language-environment default-input-method
638 ;; Saving `text-mode-hook' is somewhat questionable,
639 ;; as we might get more than we bargain for, if
640 ;; other code may has added hooks as well.
641 ;; Nonetheless, not saving it would like be confuse
642 ;; more often.
643 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
644 text-mode-hook))
645 (and (get elt 'customized-value)
646 (customize-mark-to-save elt)
647 (setq need-save t)))
648 ;; Save if we changed anything.
649 (when need-save
650 (custom-save-all))))
652 (define-key menu-bar-options-menu [save]
653 '(menu-item "Save Options" menu-bar-options-save
654 :help "Save options set from the menu above"))
656 (define-key menu-bar-options-menu [custom-separator]
657 '("--"))
659 ;; The "Show/Hide" submenu of menu "Options"
661 (defvar menu-bar-showhide-menu (make-sparse-keymap "Show/Hide"))
663 (define-key menu-bar-showhide-menu [column-number-mode]
664 (menu-bar-make-mm-toggle column-number-mode
665 "Show Column Numbers"
666 "Show the current column number in the mode line"))
668 (define-key menu-bar-showhide-menu [line-number-mode]
669 (menu-bar-make-mm-toggle line-number-mode
670 "Show Line Numbers"
671 "Show the current line number in the mode line"))
673 (define-key menu-bar-showhide-menu [linecolumn-separator]
674 '("--"))
676 (defun showhide-date-time ()
677 "Toggle whether to show date and time in the mode-line."
678 (interactive)
679 (if (display-time-mode)
680 (message "Display-time mode enabled.")
681 (message "Display-time mode disabled."))
682 (customize-mark-as-set 'display-time-mode))
684 (define-key menu-bar-showhide-menu [showhide-date-time]
685 '(menu-item "Date and Time" showhide-date-time
686 :help "Display date and time in the mode line"
687 :button (:toggle . display-time-mode)))
689 (define-key menu-bar-showhide-menu [datetime-separator]
690 '("--"))
692 (define-key menu-bar-showhide-menu [showhide-speedbar]
693 '(menu-item "Speedbar" speedbar-frame-mode
694 :help "Display a Speedbar quick-navigation frame"
695 :button (:toggle
696 . (and (boundp 'speedbar-frame)
697 (frame-live-p (symbol-value 'speedbar-frame))
698 (frame-visible-p
699 (symbol-value 'speedbar-frame))))))
701 (defvar menu-bar-showhide-fringe-menu (make-sparse-keymap "Fringe"))
703 (defun menu-bar-showhide-fringe-menu-customize ()
704 "Show customization buffer for `fringe-mode'."
705 (interactive)
706 (customize-variable 'fringe-mode))
708 (define-key menu-bar-showhide-fringe-menu [customize]
709 '(menu-item "Customize" menu-bar-showhide-fringe-menu-customize
710 :help "Detailed customization of fringe"
711 :visible (display-graphic-p)))
713 (defun menu-bar-showhide-fringe-menu-customize-reset ()
714 "Reset the fringe mode: display fringes on both sides of a window."
715 (interactive)
716 (customize-set-variable 'fringe-mode nil))
718 ;; The real definition is in fringe.el.
719 ;; This is to prevent errors in the :radio conditions below.
720 (setq fringe-mode nil)
722 (define-key menu-bar-showhide-fringe-menu [default]
723 '(menu-item "Default" menu-bar-showhide-fringe-menu-customize-reset
724 :help "Default width fringe on both left and right side"
725 :visible (display-graphic-p)
726 :button (:radio . (eq fringe-mode nil))))
728 (defun menu-bar-showhide-fringe-menu-customize-left ()
729 "Display fringes only on the left of each window."
730 (interactive)
731 (require 'fringe)
732 (customize-set-variable 'fringe-mode '(nil . 0)))
734 (define-key menu-bar-showhide-fringe-menu [left]
735 '(menu-item "On the Left" menu-bar-showhide-fringe-menu-customize-left
736 :help "Fringe only on the left side"
737 :visible (display-graphic-p)
738 :button (:radio . (equal fringe-mode '(nil . 0)))))
740 (defun menu-bar-showhide-fringe-menu-customize-right ()
741 "Display fringes only on the right of each window."
742 (interactive)
743 (require 'fringe)
744 (customize-set-variable 'fringe-mode '(0 . nil)))
746 (define-key menu-bar-showhide-fringe-menu [right]
747 '(menu-item "On the Right" menu-bar-showhide-fringe-menu-customize-right
748 :help "Fringe only on the right side"
749 :visible (display-graphic-p)
750 :button (:radio . (equal fringe-mode '(0 . nil)))))
752 (defun menu-bar-showhide-fringe-menu-customize-disable ()
753 "Do not display window fringes."
754 (interactive)
755 (require 'fringe)
756 (customize-set-variable 'fringe-mode 0))
758 (define-key menu-bar-showhide-fringe-menu [none]
759 '(menu-item "None" menu-bar-showhide-fringe-menu-customize-disable
760 :help "Turn off fringe"
761 :visible (display-graphic-p)
762 :button (:radio . (eq fringe-mode 0))))
764 (define-key menu-bar-showhide-menu [showhide-fringe]
765 (list 'menu-item "Fringe" menu-bar-showhide-fringe-menu
766 :visible `(display-graphic-p)
767 :help "Select fringe mode"))
769 (defvar menu-bar-showhide-scroll-bar-menu (make-sparse-keymap "Scroll-bar"))
771 (define-key menu-bar-showhide-scroll-bar-menu [right]
772 '(menu-item "On the Right"
773 menu-bar-right-scroll-bar
774 :help "Scroll-bar on the right side"
775 :visible (display-graphic-p)
776 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
777 (frame-parameters))) 'right))))
778 (defun menu-bar-right-scroll-bar ()
779 "Display scroll bars on the right of each window."
780 (interactive)
781 (customize-set-variable 'scroll-bar-mode 'right))
783 (define-key menu-bar-showhide-scroll-bar-menu [left]
784 '(menu-item "On the Left"
785 menu-bar-left-scroll-bar
786 :help "Scroll-bar on the left side"
787 :visible (display-graphic-p)
788 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
789 (frame-parameters))) 'left))))
791 (defun menu-bar-left-scroll-bar ()
792 "Display scroll bars on the left of each window."
793 (interactive)
794 (customize-set-variable 'scroll-bar-mode 'left))
796 (define-key menu-bar-showhide-scroll-bar-menu [none]
797 '(menu-item "None"
798 menu-bar-no-scroll-bar
799 :help "Turn off scroll-bar"
800 :visible (display-graphic-p)
801 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
802 (frame-parameters))) nil))))
804 (defun menu-bar-no-scroll-bar ()
805 "Turn off scroll bars."
806 (interactive)
807 (customize-set-variable 'scroll-bar-mode nil))
809 (define-key menu-bar-showhide-menu [showhide-scroll-bar]
810 (list 'menu-item "Scroll-bar" menu-bar-showhide-scroll-bar-menu
811 :visible `(display-graphic-p)
812 :help "Select scroll-bar mode"))
814 (define-key menu-bar-showhide-menu [menu-bar-mode]
815 '(menu-item "Menu-bar" menu-bar-mode
816 :help "Toggle menu-bar on/off"
817 :button (:toggle . menu-bar-mode)))
819 (define-key menu-bar-showhide-menu [showhide-tool-bar]
820 (list 'menu-item "Tool-bar" 'tool-bar-mode
821 :help "Turn tool-bar on/off"
822 :visible `(display-graphic-p)
823 :button `(:toggle . tool-bar-mode)))
825 (define-key menu-bar-options-menu [showhide]
826 (list 'menu-item "Show/Hide" menu-bar-showhide-menu
827 :help "Toggle on/off various display features"))
829 (define-key menu-bar-options-menu [showhide-separator]
830 '("--"))
832 (define-key menu-bar-options-menu [mule]
833 ;; It is better not to use backquote here,
834 ;; because that makes a bootstrapping problem
835 ;; if you need to recompile all the Lisp files using interpreted code.
836 (list 'menu-item "Mule (Multilingual Environment)" mule-menu-keymap
837 ;; Most of the MULE menu actually does make sense in unibyte mode,
838 ;; e.g. language selection.
839 ;;; ':visible 'default-enable-multibyte-characters
840 ':help "Default language, encodings, input method"))
841 ;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
842 ;(define-key menu-bar-options-menu [preferences]
843 ; (list 'menu-item "Preferences" menu-bar-preferences-menu
844 ; :help "Toggle important global options"))
846 (define-key menu-bar-options-menu [mule-separator]
847 '("--"))
849 (define-key menu-bar-options-menu [debug-on-quit]
850 (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
851 "Enter Debugger on Quit/C-g" "Debug on Quit %s"
852 "Enter Lisp debugger when C-g is pressed"))
853 (define-key menu-bar-options-menu [debug-on-error]
854 (menu-bar-make-toggle toggle-debug-on-error debug-on-error
855 "Enter Debugger on Error" "Debug on Error %s"
856 "Enter Lisp debugger when an error is signaled"))
857 (define-key menu-bar-options-menu [debugger-separator]
858 '("--"))
859 (define-key menu-bar-options-menu [toggle-auto-compression]
860 '(menu-item "Automatic File De/compression"
861 auto-compression-mode
862 :help "Transparently decompress compressed files"
863 :button (:toggle . (rassq 'jka-compr-handler
864 file-name-handler-alist))))
866 (define-key menu-bar-options-menu [save-place]
867 (menu-bar-make-toggle toggle-save-place-globally save-place
868 "Save Place in Files between Sessions"
869 "Saving place in files %s"
870 "Visit files of previous session when restarting Emacs"))
872 (define-key menu-bar-options-menu [uniquify]
873 (menu-bar-make-toggle toggle-uniquify-buffer-names uniquify-buffer-name-style
874 "Use Directory Names in Buffer Names"
875 "Directory name in buffer names (uniquify) %s"
876 "Uniquify buffer names by adding parent directory names"
877 (require 'uniquify)
878 (setq uniquify-buffer-name-style
879 (if (not uniquify-buffer-name-style)
880 'forward))))
882 (define-key menu-bar-options-menu [edit-options-separator]
883 '("--"))
884 (define-key menu-bar-options-menu [cua-mode]
885 '(menu-item "CUA-style cut and paste"
886 menu-bar-toggle-cua-mode
887 :help "Use C-z/C-x/C-c/C-v keys for undo/cut/copy/paste"
888 :button (:toggle . cua-mode)))
890 (defun menu-bar-toggle-cua-mode ()
891 "Toggle CUA key-binding mode.
892 When enabled, using shifted movement keys will activate the region (and
893 highlight the region using `transient-mark-mode'), and typed text replaces
894 the active selection. C-z, C-x, C-c, and C-v will undo, cut, copy, and
895 paste (in addition to the normal Emacs bindings)."
896 (interactive)
897 (cua-mode nil)
898 (customize-mark-as-set 'cua-mode)
899 (message "CUA-style cut and paste %s"
900 (if cua-mode "enabled" "disabled")))
902 (define-key menu-bar-options-menu [case-fold-search]
903 (menu-bar-make-toggle toggle-case-fold-search case-fold-search
904 "Case-Insensitive Search"
905 "Case-Insensitive Search %s"
906 "Ignore letter-case in search"))
908 (defun menu-bar-text-mode-auto-fill ()
909 (interactive)
910 (toggle-text-mode-auto-fill)
911 ;; This is somewhat questionable, as `text-mode-hook'
912 ;; might have changed outside customize.
913 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
914 (customize-mark-as-set 'text-mode-hook))
916 (define-key menu-bar-options-menu [auto-fill-mode]
917 '(menu-item "Word Wrap in Text Modes"
918 menu-bar-text-mode-auto-fill
919 :help "Automatically fill text between left and right margins (Auto Fill)"
920 :button (:toggle . (if (listp text-mode-hook)
921 (member 'turn-on-auto-fill text-mode-hook)
922 (eq 'turn-on-auto-fill text-mode-hook)))))
923 (define-key menu-bar-options-menu [truncate-lines]
924 '(menu-item "Truncate Long Lines in this Buffer"
925 toggle-truncate-lines
926 :help "Truncate long lines on the screen"
927 :button (:toggle . truncate-lines)))
929 (define-key menu-bar-options-menu [highlight-separator]
930 '("--"))
931 (define-key menu-bar-options-menu [highlight-paren-mode]
932 (menu-bar-make-mm-toggle show-paren-mode
933 "Paren Match Highlighting"
934 "Highlight matching/mismatched parentheses at cursor (Show Paren mode)"))
935 (define-key menu-bar-options-menu [transient-mark-mode]
936 (menu-bar-make-mm-toggle transient-mark-mode
937 "Active Region Highlighting"
938 "Make text in active region stand out in color (Transient Mark mode)"
939 (:enable (not cua-mode))))
940 (define-key menu-bar-options-menu [toggle-global-lazy-font-lock-mode]
941 (menu-bar-make-mm-toggle global-font-lock-mode
942 "Syntax Highlighting"
943 "Colorize text based on language syntax (Global Font Lock mode)"))
946 ;; The "Tools" menu items
948 (defun send-mail-item-name ()
949 (let* ((known-send-mail-commands '((sendmail-user-agent . "sendmail")
950 (mh-e-user-agent . "MH")
951 (message-user-agent . "Gnus Message")
952 (gnus-user-agent . "Gnus")))
953 (name (assq mail-user-agent known-send-mail-commands)))
954 (if name
955 (setq name (cdr name))
956 (setq name (symbol-name mail-user-agent))
957 (if (string-match "\\(.+\\)-user-agent" name)
958 (setq name (match-string 1 name))))
959 name))
961 (defun read-mail-item-name ()
962 (let* ((known-rmail-commands '((rmail . "RMAIL")
963 (mh-rmail . "MH")
964 (gnus . "Gnus")))
965 (known (assq read-mail-command known-rmail-commands)))
966 (if known (cdr known) (symbol-name read-mail-command))))
968 (defvar menu-bar-games-menu (make-sparse-keymap "Games"))
970 (define-key menu-bar-tools-menu [games]
971 (list 'menu-item "Games" menu-bar-games-menu))
973 (define-key menu-bar-tools-menu [separator-games]
974 '("--"))
976 (define-key menu-bar-games-menu [zone]
977 '(menu-item "Zone Out" zone
978 :help "Play tricks with Emacs display when Emacs is idle"))
979 (define-key menu-bar-games-menu [yow]
980 '(menu-item "Random Quotation" yow
981 :help "Display a random Zippy quotation"))
982 (define-key menu-bar-games-menu [tetris]
983 '(menu-item "Tetris" tetris))
984 (define-key menu-bar-games-menu [solitaire]
985 '(menu-item "Solitaire" solitaire))
986 (define-key menu-bar-games-menu [snake]
987 '(menu-item "Snake" snake
988 :help "Move snake around avoiding collisions"))
989 (define-key menu-bar-games-menu [mult]
990 '(menu-item "Multiplication Puzzle" mpuz
991 :help "Excercise brain with multiplication"))
992 (define-key menu-bar-games-menu [life]
993 '(menu-item "Life" life
994 :help "Watch how John Conway's cellular automaton evolves"))
995 (define-key menu-bar-games-menu [hanoi]
996 '(menu-item "Towers of Hanoi" hanoi
997 :help "Watch Towers-of-Hanoi puzzle solved by Emacs"))
998 (define-key menu-bar-games-menu [gomoku]
999 '(menu-item "Gomoku" gomoku
1000 :help "Mark 5 contiguous squares (like tic-tac-toe)"))
1001 (define-key menu-bar-games-menu [black-box]
1002 '(menu-item "Blackbox" blackbox
1003 :help "Find balls in a black box by shooting rays"))
1004 (define-key menu-bar-games-menu [adventure]
1005 '(menu-item "Adventure" dunnet
1006 :help "Dunnet, a text Adventure game for Emacs"))
1007 (define-key menu-bar-games-menu [5x5]
1008 '(menu-item "5x5" 5x5
1009 :help "Fill in all the squares on a 5x5 board"))
1011 (define-key menu-bar-tools-menu [simple-calculator]
1012 '(menu-item "Simple Calculator" calculator
1013 :help "Invoke the Emacs built-in quick calculator"))
1014 (define-key menu-bar-tools-menu [calc]
1015 '(menu-item "Programmable Calculator" calc
1016 :help "Invoke the Emacs built-in full scientific calculator"))
1017 (define-key menu-bar-tools-menu [calendar]
1018 '(menu-item "Display Calendar" calendar))
1020 (define-key menu-bar-tools-menu [separator-net]
1021 '("--"))
1023 (define-key menu-bar-tools-menu [directory-search]
1024 '(menu-item "Directory Search" eudc-tools-menu
1025 :help "Query directory servers via LDAP, CCSO PH/QI or BBDB"))
1026 (define-key menu-bar-tools-menu [compose-mail]
1027 (list
1028 'menu-item `(format "Send Mail (with %s)" (send-mail-item-name))
1029 'compose-mail
1030 :visible `(and mail-user-agent (not (eq mail-user-agent 'ignore)))
1031 :help "Send a mail message"))
1032 (define-key menu-bar-tools-menu [rmail]
1033 (list
1034 'menu-item `(format "Read Mail (with %s)" (read-mail-item-name))
1035 'menu-bar-read-mail
1036 :visible `(and read-mail-command (not (eq read-mail-command 'ignore)))
1037 :help "Read your mail and reply to it"))
1039 (defun menu-bar-read-mail ()
1040 "Read mail using `read-mail-command'."
1041 (interactive)
1042 (call-interactively read-mail-command))
1044 (define-key menu-bar-tools-menu [gnus]
1045 '(menu-item "Read Net News (Gnus)" gnus
1046 :help "Read network news groups"))
1048 (define-key menu-bar-tools-menu [separator-vc]
1049 '("--"))
1051 (defvar vc-menu-map (make-sparse-keymap "Version Control"))
1052 (define-key menu-bar-tools-menu [pcl-cvs]
1053 `(menu-item "PCL-CVS" ,cvs-global-menu
1054 :help "Module-level interface to CVS"))
1055 (define-key menu-bar-tools-menu [vc]
1056 (list 'menu-item "Version Control" vc-menu-map
1057 :help "Interface to RCS, CVS, SCCS"))
1059 (define-key menu-bar-tools-menu [separator-compare]
1060 '("--"))
1062 (define-key menu-bar-tools-menu [ediff-misc]
1063 '(menu-item "Ediff Miscellanea" menu-bar-ediff-misc-menu
1064 :help "Ediff manual, customization, sessions, etc."))
1065 (define-key menu-bar-tools-menu [epatch]
1066 '(menu-item "Apply Patch" menu-bar-epatch-menu))
1067 (define-key menu-bar-tools-menu [ediff-merge]
1068 '(menu-item "Merge" menu-bar-ediff-merge-menu
1069 :help "Merge different revisions of files/directories"))
1070 (define-key menu-bar-tools-menu [compare]
1071 '(menu-item "Compare (Ediff)" menu-bar-ediff-menu
1072 :help "Display differences between files/directories"))
1075 (define-key menu-bar-tools-menu [separator-spell]
1076 '("--"))
1078 (define-key menu-bar-tools-menu [spell]
1079 '(menu-item "Spell Checking" ispell-menu-map))
1081 (define-key menu-bar-tools-menu [separator-prog]
1082 '("--"))
1084 (define-key menu-bar-tools-menu [gdb]
1085 '(menu-item "Debugger (GDB)..." gdb
1086 :help "Debug a program from within Emacs with GDB"))
1087 (define-key menu-bar-tools-menu [shell-on-region]
1088 '(menu-item "Shell Command on Region..." shell-command-on-region
1089 :enable mark-active
1090 :help "Pass marked region to a shell command"))
1091 (define-key menu-bar-tools-menu [shell]
1092 '(menu-item "Shell Command..." shell-command
1093 :help "Invoke a shell command and catch its output"))
1094 (define-key menu-bar-tools-menu [compile]
1095 '(menu-item "Compile..." compile
1096 :help "Invoke compiler or Make, view compilation errors"))
1097 (define-key menu-bar-tools-menu [grep]
1098 '(menu-item "Search Files (Grep)..." grep
1099 :help "Search files for strings or regexps (with Grep)"))
1102 ;; The "Help" menu items
1104 (defvar menu-bar-describe-menu (make-sparse-keymap "Describe"))
1106 (define-key menu-bar-describe-menu [mule-diag]
1107 '(menu-item "Show All of Mule Status" mule-diag
1108 :visible default-enable-multibyte-characters
1109 :help "Display multilingual environment settings"))
1110 (define-key menu-bar-describe-menu [describe-coding-system-briefly]
1111 '(menu-item "Describe Coding System (Briefly)..."
1112 describe-current-coding-system-briefly
1113 :visible default-enable-multibyte-characters))
1114 (define-key menu-bar-describe-menu [describe-coding-system]
1115 '(menu-item "Describe Coding System..." describe-coding-system
1116 :visible default-enable-multibyte-characters))
1117 (define-key menu-bar-describe-menu [describe-input-method]
1118 '(menu-item "Describe Input Method..." describe-input-method
1119 :visible default-enable-multibyte-characters
1120 :help "Keyboard layout for specific input method"))
1121 (define-key menu-bar-describe-menu [describe-language-environment]
1122 (list 'menu-item "Describe Language Environment"
1123 describe-language-environment-map
1124 :help "Show multilingual settings for a specific language"))
1126 (define-key menu-bar-describe-menu [separator-desc-mule]
1127 '("--"))
1129 (define-key menu-bar-describe-menu [list-keybindings]
1130 '(menu-item "List Key Bindings" describe-bindings
1131 :help "Display a list of all current keybindings"))
1132 (define-key menu-bar-describe-menu [describe-current-display-table]
1133 '(menu-item "Describe Display Table" describe-current-display-table
1134 :help "Describe the current display table"))
1135 (define-key menu-bar-describe-menu [describe-face]
1136 '(menu-item "Describe Face..." describe-face
1137 :help "Display the properties of a face"))
1138 (define-key menu-bar-describe-menu [describe-variable]
1139 '(menu-item "Describe Variable..." describe-variable
1140 :help "Display documentation of variable/option"))
1141 (define-key menu-bar-describe-menu [describe-function]
1142 '(menu-item "Describe Function..." describe-function
1143 :help "Display documentation of function/command"))
1144 (define-key menu-bar-describe-menu [describe-key-1]
1145 '(menu-item "Describe Key..." describe-key
1146 ;; Users typically don't identify keys and menu items...
1147 :help "Display documentation of command bound to a \
1148 key (or menu-item)"))
1149 (define-key menu-bar-describe-menu [describe-key]
1150 '(menu-item "What's This? " describe-key
1151 ;; Users typically don't identify keys and menu items...
1152 :help "Display documentation of command bound to a \
1153 key (or menu-item)"))
1154 (define-key menu-bar-describe-menu [describe-mode]
1155 '(menu-item "Describe Buffer Modes" describe-mode
1156 :help "Describe this buffer's major and minor mode"))
1158 (defvar menu-bar-apropos-menu (make-sparse-keymap "Apropos"))
1159 (defun menu-bar-read-lispref ()
1160 "Display the Emacs Lisp Reference manual in Info mode."
1161 (interactive)
1162 (info "elisp"))
1164 (defun menu-bar-read-lispintro ()
1165 "Display the Introduction to Emacs Lisp Programming in Info mode."
1166 (interactive)
1167 (info "eintr"))
1169 (defun search-emacs-glossary ()
1170 "Display the Glossary node of the Emacs manual in Info mode."
1171 (interactive)
1172 (info "(emacs)Glossary"))
1174 (defun emacs-index-search (topic)
1175 "Look up TOPIC in the indices of the Emacs User Manual."
1176 (interactive "sSubject to look up: ")
1177 (info "emacs")
1178 (Info-index topic))
1180 (defun elisp-index-search (topic)
1181 "Look up TOPIC in the indices of the Emacs Lisp Reference Manual."
1182 (interactive "sSubject to look up: ")
1183 (info "elisp")
1184 (Info-index topic))
1186 (define-key menu-bar-apropos-menu [apropos-documentation]
1187 '(menu-item "Search Documentation Strings..." apropos-documentation
1188 :help
1189 "Find functions and variables whose doc strings match a regexp"))
1190 (define-key menu-bar-apropos-menu [apropos]
1191 '(menu-item "Find Any Object by Name..." apropos
1192 :help "Find symbols of any kind whose names match a regexp"))
1193 (define-key menu-bar-apropos-menu [apropos-value]
1194 '(menu-item "Find Options by Value..." apropos-value
1195 :help "Find variables whose values match a regexp"))
1196 (define-key menu-bar-apropos-menu [apropos-variables]
1197 '(menu-item "Find Options by Name..." apropos-variable
1198 :help "Find variables whose names match a regexp"))
1199 (define-key menu-bar-apropos-menu [apropos-commands]
1200 '(menu-item "Find Commands by Name..." apropos-command
1201 :help "Find commands whose names match a regexp"))
1202 (define-key menu-bar-apropos-menu [sep1]
1203 '("--"))
1204 (define-key menu-bar-apropos-menu [elisp-index-search]
1205 '(menu-item "Look Up Subject in ELisp Manual..." elisp-index-search
1206 :help "Find description of a subject in Emacs Lisp manual"))
1207 (define-key menu-bar-apropos-menu [emacs-index-search]
1208 '(menu-item "Look Up Subject in User Manual..." emacs-index-search
1209 :help "Find description of a subject in Emacs User manual"))
1210 (define-key menu-bar-apropos-menu [emacs-glossary]
1211 '(menu-item "Emacs Terminology" search-emacs-glossary
1212 :help "Display the Glossary section of the Emacs manual"))
1214 (defvar menu-bar-manuals-menu (make-sparse-keymap "More Manuals"))
1216 (define-key menu-bar-manuals-menu [man]
1217 '(menu-item "Read Man Page..." manual-entry
1218 :help "Man-page docs for external commands and libraries"))
1219 (define-key menu-bar-manuals-menu [sep2]
1220 '("--"))
1221 (define-key menu-bar-manuals-menu [order-emacs-manuals]
1222 '(menu-item "Ordering Manuals" view-order-manuals
1223 :help "How to order manuals from the Free Software Foundation"))
1224 (define-key menu-bar-manuals-menu [info]
1225 '(menu-item "All Other Manuals (Info)" Info-directory
1226 :help "Read any of the installed manuals"))
1227 (define-key menu-bar-manuals-menu [info-elisp]
1228 '(menu-item "Emacs Lisp Reference" menu-bar-read-lispref
1229 :help "Read the Emacs Lisp Reference manual"))
1230 (define-key menu-bar-manuals-menu [info-elintro]
1231 '(menu-item "Introduction to Emacs Lisp" menu-bar-read-lispintro
1232 :help "Read the Introduction to Emacs Lisp Programming"))
1233 (define-key menu-bar-manuals-menu [sep3]
1234 '("--"))
1235 (define-key menu-bar-manuals-menu [command]
1236 '(menu-item "Find Command in Manual" Info-goto-emacs-command-node
1237 :help "Display manual section that describes a command"))
1238 (define-key menu-bar-manuals-menu [key]
1239 '(menu-item "Find Key in Manual" Info-goto-emacs-key-command-node
1240 :help "Display manual section that describes a key"))
1242 (define-key menu-bar-help-menu [eliza]
1243 '(menu-item "Emacs Psychiatrist" doctor
1244 :help "Our doctor will help you feel better"))
1245 (define-key menu-bar-help-menu [sep4]
1246 '("--"))
1247 (define-key menu-bar-help-menu [describe-no-warranty]
1248 '(menu-item "(Non)Warranty" describe-no-warranty
1249 :help "Explain that Emacs has NO WARRANTY"))
1250 (define-key menu-bar-help-menu [describe-copying]
1251 '(menu-item "Copying Conditions" describe-copying
1252 :help "Show the Emacs license (GPL)"))
1253 (define-key menu-bar-help-menu [describe-distribution]
1254 '(menu-item "Getting New Versions" describe-distribution
1255 :help "How to get latest versions of Emacs"))
1256 (define-key menu-bar-help-menu [more]
1257 '(menu-item "Find Extra Packages"
1258 menu-bar-help-extra-packages
1259 :help "Where to find some extra packages and possible updates"))
1260 (defun menu-bar-help-extra-packages ()
1261 "Display help about some additional packages available for Emacs."
1262 (interactive)
1263 (let (enable-local-variables)
1264 (view-file (expand-file-name "MORE.STUFF"
1265 data-directory))
1266 (goto-address)))
1267 (define-key menu-bar-help-menu [about]
1268 '(menu-item "About Emacs" display-splash-screen
1269 :help "Display version number, copyright info, and basic help"))
1270 (define-key menu-bar-help-menu [sep2]
1271 '("--"))
1272 (define-key menu-bar-help-menu [finder-by-keyword]
1273 '(menu-item "Find Emacs Packages..." finder-by-keyword
1274 :help "Find packages and features by keyword"))
1275 (define-key menu-bar-help-menu [manuals]
1276 (list 'menu-item "More Manuals" menu-bar-manuals-menu
1277 :help "Search and browse on-line manuals"))
1278 (define-key menu-bar-help-menu [emacs-manual]
1279 '(menu-item "Read the Emacs Manual" info-emacs-manual
1280 :help "Full documentation of Emacs features"))
1281 (define-key menu-bar-help-menu [describe]
1282 (list 'menu-item "Describe" menu-bar-describe-menu
1283 :help "Describe commands, variables, keys"))
1284 (define-key menu-bar-help-menu [apropos]
1285 (list 'menu-item "Search Documentation" menu-bar-apropos-menu
1286 :help "Look up terms, find commands, options, etc. (Apropos)"))
1287 (define-key menu-bar-help-menu [sep1]
1288 '("--"))
1289 (define-key menu-bar-help-menu [report-emacs-bug]
1290 '(menu-item "Send Bug Report..." report-emacs-bug
1291 :help "Send e-mail to Emacs maintainers"))
1292 (define-key menu-bar-help-menu [emacs-problems]
1293 '(menu-item "Emacs Known Problems" view-emacs-problems))
1294 (define-key menu-bar-help-menu [emacs-news]
1295 '(menu-item "Emacs News" view-emacs-news
1296 :help "New features of this version"))
1297 (define-key menu-bar-help-menu [emacs-faq]
1298 '(menu-item "Emacs FAQ" view-emacs-FAQ))
1300 (defun help-with-tutorial-spec-language ()
1301 "Use the Emacs tutorial, specifying which language you want."
1302 (interactive)
1303 (help-with-tutorial t))
1305 (define-key menu-bar-help-menu [emacs-tutorial-language-specific]
1306 '(menu-item "Emacs Tutorial (choose language)..."
1307 help-with-tutorial-spec-language
1308 :help "Learn how to use Emacs (choose a language)"))
1309 (define-key menu-bar-help-menu [emacs-tutorial]
1310 '(menu-item "Emacs Tutorial" help-with-tutorial
1311 :help "Learn how to use Emacs"))
1313 (defun kill-this-buffer () ; for the menubar
1314 "Kill the current buffer."
1315 (interactive)
1316 (kill-buffer (current-buffer)))
1318 (defun kill-this-buffer-enabled-p ()
1319 (let ((count 0)
1320 (buffers (buffer-list)))
1321 (while buffers
1322 (or (string-match "^ " (buffer-name (car buffers)))
1323 (setq count (1+ count)))
1324 (setq buffers (cdr buffers)))
1325 (and (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1326 (> count 1))))
1328 (put 'dired 'menu-enable
1329 '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
1331 ;; Permit deleting frame if it would leave a visible or iconified frame.
1332 (defun delete-frame-enabled-p ()
1333 "Return non-nil if `delete-frame' should be enabled in the menu bar."
1334 (let ((frames (frame-list))
1335 (count 0))
1336 (while frames
1337 (if (frame-visible-p (car frames))
1338 (setq count (1+ count)))
1339 (setq frames (cdr frames)))
1340 (> count 1)))
1342 (defcustom yank-menu-length 20
1343 "*Maximum length to display in the yank-menu."
1344 :type 'integer
1345 :group 'mouse)
1347 (defun menu-bar-update-yank-menu (string old)
1348 (let ((front (car (cdr yank-menu)))
1349 (menu-string (if (<= (length string) yank-menu-length)
1350 string
1351 (concat
1352 (substring string 0 (/ yank-menu-length 2))
1353 "..."
1354 (substring string (- (/ yank-menu-length 2)))))))
1355 ;; Don't let the menu string be all dashes
1356 ;; because that has a special meaning in a menu.
1357 (if (string-match "\\`-+\\'" menu-string)
1358 (setq menu-string (concat menu-string " ")))
1359 ;; If we're supposed to be extending an existing string, and that
1360 ;; string really is at the front of the menu, then update it in place.
1361 (if (and old (or (eq old (car front))
1362 (string= old (car front))))
1363 (progn
1364 (setcar front string)
1365 (setcar (cdr front) menu-string))
1366 (setcdr yank-menu
1367 (cons
1368 (cons string (cons menu-string 'menu-bar-select-yank))
1369 (cdr yank-menu)))))
1370 (if (> (length (cdr yank-menu)) kill-ring-max)
1371 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
1373 (put 'menu-bar-select-yank 'apropos-inhibit t)
1374 (defun menu-bar-select-yank ()
1375 (interactive "*")
1376 (push-mark (point))
1377 (insert last-command-event))
1380 (defcustom buffers-menu-show-directories 'unless-uniquify
1381 "If non-nil, show directories in the Buffers menu for buffers that have them.
1382 The special value `unless-uniquify' means that directories will be shown
1383 unless `uniquify-buffer-name-style' is non-nil (in which case, buffer
1384 names should include enough of a buffer's directory to distinguish it
1385 from other buffers).
1387 Setting this variable directly does not take effect until next time the
1388 Buffers menu is regenerated."
1389 :set (lambda (symbol value)
1390 (set symbol value)
1391 (menu-bar-update-buffers t))
1392 :initialize 'custom-initialize-default
1393 :type '(choice (const :tag "Never" nil)
1394 (const :tag "Unless uniquify is enabled" unless-uniquify)
1395 (const :tag "Always" t))
1396 :group 'menu)
1398 (defcustom buffers-menu-show-status t
1399 "If non-nil, show modified/read-only status of buffers in the Buffers menu.
1400 Setting this variable directly does not take effect until next time the
1401 Buffers menu is regenerated."
1402 :set (lambda (symbol value)
1403 (set symbol value)
1404 (menu-bar-update-buffers t))
1405 :initialize 'custom-initialize-default
1406 :type 'boolean
1407 :group 'menu)
1409 (defvar list-buffers-directory nil)
1411 (defvar menu-bar-update-buffers-maxbuf)
1413 (defun menu-bar-select-buffer ()
1414 (interactive)
1415 (switch-to-buffer last-command-event))
1417 (defun menu-bar-select-frame ()
1418 (interactive)
1419 (let (frame)
1420 (dolist (f (frame-list))
1421 (when (equal last-command-event (frame-parameter f 'name))
1422 (setq frame f)))
1423 (make-frame-visible frame)
1424 (raise-frame frame)
1425 (select-frame frame)))
1427 (defun menu-bar-update-buffers-1 (elt)
1428 (let* ((buf (car elt))
1429 (file
1430 (and (if (eq buffers-menu-show-directories 'unless-uniquify)
1431 (or (not (boundp 'uniquify-buffer-name-style))
1432 (null uniquify-buffer-name-style))
1433 buffers-menu-show-directories)
1434 (or (buffer-file-name buf)
1435 (buffer-local-value 'list-buffers-directory buf)))))
1436 (when file
1437 (setq file (file-name-directory file)))
1438 (when (and file (> (length file) 20))
1439 (setq file (concat "..." (substring file -17))))
1440 (cons (if buffers-menu-show-status
1441 (let ((mod (if (buffer-modified-p buf) "*" ""))
1442 (ro (if (buffer-local-value 'buffer-read-only buf) "%" "")))
1443 (if file
1444 (format "%s %s%s -- %s" (cdr elt) mod ro file)
1445 (format "%s %s%s" (cdr elt) mod ro)))
1446 (if file
1447 (format "%s -- %s" (cdr elt) file)
1448 (cdr elt)))
1449 buf)))
1451 ;; Used to cache the menu entries for commands in the Buffers menu
1452 (defvar menu-bar-buffers-menu-command-entries nil)
1454 (defun menu-bar-update-buffers (&optional force)
1455 ;; If user discards the Buffers item, play along.
1456 (and (lookup-key (current-global-map) [menu-bar buffer])
1457 (or force (frame-or-buffer-changed-p))
1458 (let ((buffers (buffer-list))
1459 (frames (frame-list))
1460 buffers-menu frames-menu)
1461 ;; If requested, list only the N most recently selected buffers.
1462 (if (and (integerp buffers-menu-max-size)
1463 (> buffers-menu-max-size 1))
1464 (if (> (length buffers) buffers-menu-max-size)
1465 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
1467 ;; Make the menu of buffers proper.
1468 (setq buffers-menu
1469 (let* ((buffer-list
1470 (mapcar 'list buffers))
1471 (menu-bar-update-buffers-maxbuf 0)
1472 alist)
1473 ;; Put into each element of buffer-list
1474 ;; the name for actual display,
1475 ;; perhaps truncated in the middle.
1476 (dolist (buf buffer-list)
1477 (let ((name (buffer-name (car buf))))
1478 (setcdr buf
1479 (if (> (length name) 27)
1480 (concat (substring name 0 12)
1481 "..."
1482 (substring name -12))
1483 name))))
1484 ;; Compute the maximum length of any name.
1485 (dolist (buf buffer-list)
1486 (unless (eq ?\ (aref (cdr buf) 0))
1487 (setq menu-bar-update-buffers-maxbuf
1488 (max menu-bar-update-buffers-maxbuf
1489 (length (cdr buf))))))
1490 ;; Set ALIST to an alist of the form
1491 ;; ITEM-STRING . BUFFER
1492 (dolist (buf buffer-list)
1493 (unless (eq ?\ (aref (cdr buf) 0))
1494 (push (menu-bar-update-buffers-1 buf) alist)))
1495 ;; Now make the actual list of items, and add
1496 ;; some miscellaneous buffer commands to the end.
1497 (mapcar (lambda (pair)
1498 ;; This is somewhat risque, to use
1499 ;; the buffer name itself as the event
1500 ;; type to define, but it works.
1501 ;; It would not work to use the buffer
1502 ;; since a buffer as an event has its
1503 ;; own meaning.
1504 (nconc (list (buffer-name (cdr pair))
1505 (car pair)
1506 (cons nil nil))
1507 'menu-bar-select-buffer))
1508 (nreverse alist))))
1510 ;; Make a Frames menu if we have more than one frame.
1511 (when (cdr frames)
1512 (let ((frames-menu
1513 (cons 'keymap
1514 (cons "Select Frame"
1515 (mapcar
1516 (lambda (frame)
1517 (nconc
1518 (list (frame-parameter frame 'name)
1519 (frame-parameter frame 'name)
1520 (cons nil nil))
1521 'menu-bar-select-frame))
1522 frames)))))
1523 ;; Put it after the normal buffers
1524 (setq buffers-menu
1525 (nconc buffers-menu
1526 `((frames-separator "--")
1527 (frames menu-item "Frames" ,frames-menu))))))
1529 ;; Add in some normal commands at the end of the menu. We use
1530 ;; the copy cached in `menu-bar-buffers-menu-command-entries'
1531 ;; if it's been set already. Note that we can't use constant
1532 ;; lists for the menu-entries, because the low-level menu-code
1533 ;; modifies them.
1534 (unless menu-bar-buffers-menu-command-entries
1535 (setq menu-bar-buffers-menu-command-entries
1536 (list '(command-separator "--")
1537 (list 'next-buffer
1538 'menu-item
1539 "Next Buffer"
1540 'next-buffer
1541 :help "Switch to the \"next\" buffer in a cyclic order")
1542 (list 'prev-buffer
1543 'menu-item
1544 "Previous Buffer"
1545 'prev-buffer
1546 :help "Switch to the \"previous\" buffer in a cyclic order")
1547 (list 'select-named-buffer
1548 'menu-item
1549 "Select Named Buffer..."
1550 'switch-to-buffer
1551 :help "Prompt for a buffer name, and select that buffer in the current window")
1552 (list 'list-all-buffers
1553 'menu-item
1554 "List All Buffers"
1555 'list-buffers
1556 :help "Pop up a window listing all emacs buffers"
1557 ))))
1558 (setq buffers-menu
1559 (nconc buffers-menu menu-bar-buffers-menu-command-entries))
1561 (setq buffers-menu (cons 'keymap (cons "Select Buffer" buffers-menu)))
1562 (define-key (current-global-map) [menu-bar buffer]
1563 (cons "Buffers" buffers-menu)))))
1565 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
1567 (menu-bar-update-buffers)
1569 ;; this version is too slow
1570 ;;(defun format-buffers-menu-line (buffer)
1571 ;; "Returns a string to represent the given buffer in the Buffer menu.
1572 ;;nil means the buffer shouldn't be listed. You can redefine this."
1573 ;; (if (string-match "\\` " (buffer-name buffer))
1574 ;; nil
1575 ;; (save-excursion
1576 ;; (set-buffer buffer)
1577 ;; (let ((size (buffer-size)))
1578 ;; (format "%s%s %-19s %6s %-15s %s"
1579 ;; (if (buffer-modified-p) "*" " ")
1580 ;; (if buffer-read-only "%" " ")
1581 ;; (buffer-name)
1582 ;; size
1583 ;; mode-name
1584 ;; (or (buffer-file-name) ""))))))
1586 ;;; Set up a menu bar menu for the minibuffer.
1588 (dolist (map (list minibuffer-local-map
1589 ;; This shouldn't be necessary, but there's a funny
1590 ;; bug in keymap.c that I don't understand yet. -stef
1591 minibuffer-local-completion-map))
1592 (define-key map [menu-bar minibuf]
1593 (cons "Minibuf" (make-sparse-keymap "Minibuf"))))
1595 (let ((map minibuffer-local-completion-map))
1596 (define-key map [menu-bar minibuf ?\?]
1597 (list 'menu-item "List Completions" 'minibuffer-completion-help
1598 :help "Display all possible completions"))
1599 (define-key map [menu-bar minibuf space]
1600 (list 'menu-item "Complete Word" 'minibuffer-complete-word
1601 :help "Complete at most one word"))
1602 (define-key map [menu-bar minibuf tab]
1603 (list 'menu-item "Complete" 'minibuffer-complete
1604 :help "Complete as far as possible")))
1606 (let ((map minibuffer-local-map))
1607 (define-key map [menu-bar minibuf quit]
1608 (list 'menu-item "Quit" 'keyboard-escape-quit
1609 :help "Abort input and exit minibuffer"))
1610 (define-key map [menu-bar minibuf return]
1611 (list 'menu-item "Enter" 'exit-minibuffer
1612 :help "Terminate input and exit minibuffer")))
1614 (defcustom menu-bar-mode t
1615 "Toggle display of a menu bar on each frame.
1616 Setting this variable directly does not take effect;
1617 use either \\[customize] or the function `menu-bar-mode'."
1618 :set (lambda (symbol value)
1619 (menu-bar-mode (or value 0)))
1620 :initialize 'custom-initialize-default
1621 :type 'boolean
1622 :group 'frames)
1624 (defun menu-bar-mode (&optional flag)
1625 "Toggle display of a menu bar on each frame.
1626 This command applies to all frames that exist and frames to be
1627 created in the future.
1628 With a numeric argument, if the argument is positive,
1629 turn on menu bars; otherwise, turn off menu bars."
1630 (interactive "P")
1632 ;; Make menu-bar-mode and default-frame-alist consistent.
1633 (let ((default (assq 'menu-bar-lines default-frame-alist)))
1634 (if default
1635 (setq menu-bar-mode (not (eq (cdr default) 0)))
1636 (setq default-frame-alist
1637 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
1638 default-frame-alist))))
1640 ;; Toggle or set the mode, according to FLAG.
1641 (setq menu-bar-mode (if (null flag) (not menu-bar-mode)
1642 (> (prefix-numeric-value flag) 0)))
1644 ;; Apply it to default-frame-alist.
1645 (let ((parameter (assq 'menu-bar-lines default-frame-alist)))
1646 (if (consp parameter)
1647 (setcdr parameter (if menu-bar-mode 1 0))
1648 (setq default-frame-alist
1649 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
1650 default-frame-alist))))
1652 ;; Apply it to existing frames.
1653 (let ((frames (frame-list)))
1654 (while frames
1655 (let ((height (cdr (assq 'height (frame-parameters (car frames))))))
1656 (modify-frame-parameters (car frames)
1657 (list (cons 'menu-bar-lines
1658 (if menu-bar-mode 1 0))))
1659 (modify-frame-parameters (car frames)
1660 (list (cons 'height height))))
1661 (setq frames (cdr frames))))
1663 (when (interactive-p)
1664 (if menu-bar-mode
1665 (message "Menu-bar mode enabled.")
1666 (message "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear."))
1667 (customize-mark-as-set 'menu-bar-mode))
1669 menu-bar-mode)
1671 (provide 'menu-bar)
1673 ;;; menu-bar.el ends here