1 ;;; menu-bar.el --- define a default menu bar
3 ;; Copyright (C) 1993, 1994, 1995, 2000, 2001, 2002 Free Software Foundation, Inc.
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)
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.
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))
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
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]
84 ;; Don't use delete-frame as event name because that is a special
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]
112 (define-key menu-bar-files-menu [ps-print-region]
113 '(menu-item "Postscript Print Region (B+W)" ps-print-region
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
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
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]
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
141 (file-name-directory auto-save-list-file-prefix))
143 (file-name-directory auto-save-list-file-prefix)
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-name)
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)
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]
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
196 (defun nonincremental-search-forward (string)
197 "Read a string and search for it nonincrementally."
198 (interactive "sSearch for string: ")
199 (if (equal string "")
200 (search-forward (car search-ring))
201 (isearch-update-ring string nil)
202 (search-forward string)))
204 (defun nonincremental-search-backward (string)
205 "Read a string and search backward for it nonincrementally."
206 (interactive "sSearch for string: ")
207 (if (equal string "")
208 (search-backward (car search-ring))
209 (isearch-update-ring string nil)
210 (search-backward string)))
212 (defun nonincremental-re-search-forward (string)
213 "Read a regular expression and search for it nonincrementally."
214 (interactive "sSearch for regexp: ")
215 (if (equal string "")
216 (re-search-forward (car regexp-search-ring))
217 (isearch-update-ring string t)
218 (re-search-forward string)))
220 (defun nonincremental-re-search-backward (string)
221 "Read a regular expression and search backward for it nonincrementally."
222 (interactive "sSearch for regexp: ")
223 (if (equal string "")
224 (re-search-backward (car regexp-search-ring))
225 (isearch-update-ring string t)
226 (re-search-backward string)))
228 (defun nonincremental-repeat-search-forward ()
229 "Search forward for the previous search string."
231 (if (null search-ring)
232 (error "No previous search"))
233 (search-forward (car search-ring)))
235 (defun nonincremental-repeat-search-backward ()
236 "Search backward for the previous search string."
238 (if (null search-ring)
239 (error "No previous search"))
240 (search-backward (car search-ring)))
242 (defun nonincremental-repeat-re-search-forward ()
243 "Search forward for the previous regular expression."
245 (if (null regexp-search-ring)
246 (error "No previous search"))
247 (re-search-forward (car regexp-search-ring)))
249 (defun nonincremental-repeat-re-search-backward ()
250 "Search backward for the previous regular expression."
252 (if (null regexp-search-ring)
253 (error "No previous search"))
254 (re-search-backward (car regexp-search-ring)))
256 (defvar menu-bar-search-menu (make-sparse-keymap "Search"))
257 (defvar menu-bar-adv-search-menu
258 (make-sparse-keymap "Advanced Search/Replace"))
260 (define-key menu-bar-adv-search-menu [tags-continue]
261 '(menu-item "Continue Tags Search/Replace" tags-loop-continue
262 :help "Continue last tags search/replace operation"))
263 (define-key menu-bar-adv-search-menu [tags-repl]
264 '(menu-item "Replace in all tagged files" tags-query-replace
265 :help "Interactively replace a regexp in all tagged files"))
266 (define-key menu-bar-adv-search-menu [tags-srch]
267 '(menu-item "Search in all tagged files" tags-search
268 :help "Search for a regexp in all tagged files"))
270 (define-key menu-bar-adv-search-menu [separator-tag-search]
273 (define-key menu-bar-adv-search-menu [query-replace-regexp]
274 '(menu-item "Replace Regexp..." query-replace-regexp
275 :enable (not buffer-read-only)
276 :help "Replace regular expression, ask about each occurrence"))
277 (define-key menu-bar-adv-search-menu [repeat-regexp-back]
278 '(menu-item "Repeat Regexp Backwards"
279 nonincremental-repeat-re-search-backward
280 :enable regexp-search-ring
281 :help "Repeat last regular expression search backwards"))
282 (define-key menu-bar-adv-search-menu [repeat-regexp-fwd]
283 '(menu-item "Repeat Regexp" nonincremental-repeat-re-search-forward
284 :enable regexp-search-ring
285 :help "Repeat last regular expression search forward"))
286 (define-key menu-bar-adv-search-menu [re-search-backward]
287 '(menu-item "Search Regexp Backwards..." nonincremental-re-search-backward
288 :help "Search backwards for a regular expression"))
289 (define-key menu-bar-adv-search-menu [re-search-forward]
290 '(menu-item "Search Regexp..." nonincremental-re-search-forward
291 :help "Search forward for a regular expression"))
292 (define-key menu-bar-adv-search-menu [separator-tag-isearch]
294 (define-key menu-bar-adv-search-menu [isearch-backward]
295 '(menu-item "Incremental Search Backwards..." isearch-backward
296 :help "Search backwards for a string as you type it"))
297 (define-key menu-bar-adv-search-menu [isearch-forward]
298 '(menu-item "Incremental Search..." isearch-forward
299 :help "Search forward for a string as you type it"))
300 (define-key menu-bar-search-menu [re-search]
301 (list 'menu-item "Advanced Search/Replace" menu-bar-adv-search-menu
302 :help "Regexp and Tags search and replace"))
304 (define-key menu-bar-search-menu [query-replace]
305 '(menu-item "Replace..." query-replace
306 :enable (not buffer-read-only)
307 :help "Replace string interactively, ask about each occurrence"))
308 (define-key menu-bar-search-menu [repeat-search-back]
309 '(menu-item "Repeat Backwards" nonincremental-repeat-search-backward
311 :help "Repeat last search backwards"))
312 (define-key menu-bar-search-menu [repeat-search-fwd]
313 '(menu-item "Repeat Search" nonincremental-repeat-search-forward
315 :help "Repeat last search forward"))
316 (define-key menu-bar-search-menu [search-backward]
317 '(menu-item "Search Backwards..." nonincremental-search-backward
318 :help "Search backwards for a string"))
319 (define-key menu-bar-search-menu [search-forward]
320 '(menu-item "Search..." nonincremental-search-forward
321 :help "Search forward for a string"))
323 ;;; Assemble the top-level Edit menu items.
324 (define-key menu-bar-edit-menu [props]
325 '(menu-item "Text Properties" facemenu-menu
326 :help "Change properties of text in region"))
328 (define-key menu-bar-edit-menu [fill]
329 '(menu-item "Fill" fill-region
330 :enable (and mark-active (not buffer-read-only))
332 "Fill text in region to fit between left and right margin"))
334 (define-key menu-bar-edit-menu [separator-bookmark]
337 (define-key menu-bar-edit-menu [bookmark]
338 '(menu-item "Bookmarks" menu-bar-bookmark-map
339 :help "Record positions and jump between them"))
341 (defvar menu-bar-goto-menu (make-sparse-keymap "Go To"))
343 (define-key menu-bar-goto-menu [set-tags-name]
344 '(menu-item "Set Tags File Name" visit-tags-table
345 :help "Tell Tags commands which tag table file to use"))
347 (define-key menu-bar-goto-menu [separator-tag-file]
350 (define-key menu-bar-goto-menu [apropos-tags]
351 '(menu-item "Tags Apropos" tags-apropos
352 :help "Find function/variables whose names match regexp"))
353 (define-key menu-bar-goto-menu [next-tag-otherw]
354 '(menu-item "Next Tag in Other Window"
355 menu-bar-next-tag-other-window
356 :enable (and (boundp 'tags-location-ring)
357 (not (ring-empty-p tags-location-ring)))
358 :help "Find next function/variable matching last tag name in another window"))
360 (defun menu-bar-next-tag-other-window ()
361 "Find the next definition of the tag already specified."
363 (find-tag-other-window nil t))
365 (defun menu-bar-next-tag ()
366 "Find the next definition of the tag already specified."
370 (define-key menu-bar-goto-menu [next-tag]
371 '(menu-item "Find Next Tag"
373 :enable (and (boundp 'tags-location-ring)
374 (not (ring-empty-p tags-location-ring)))
375 :help "Find next function/variable matching last tag name"))
376 (define-key menu-bar-goto-menu [find-tag-otherw]
377 '(menu-item "Find Tag in Other Window..." find-tag-other-window
378 :help "Find function/variable definition in another window"))
379 (define-key menu-bar-goto-menu [find-tag]
380 '(menu-item "Find Tag..." find-tag
381 :help "Find definition of function or variable"))
383 (define-key menu-bar-goto-menu [separator-tags]
386 (define-key menu-bar-goto-menu [end-of-buf]
387 '(menu-item "Goto End of Buffer" end-of-buffer))
388 (define-key menu-bar-goto-menu [beg-of-buf]
389 '(menu-item "Goto Beginning of Buffer" beginning-of-buffer))
390 (define-key menu-bar-goto-menu [go-to-pos]
391 '(menu-item "Goto Buffer Position..." goto-char
392 :help "Read a number N and go to buffer position N"))
393 (define-key menu-bar-goto-menu [go-to-line]
394 '(menu-item "Goto Line..." goto-line
395 :help "Read a line number and go to that line"))
397 (define-key menu-bar-edit-menu [goto]
398 (list 'menu-item "Go To" menu-bar-goto-menu))
400 (define-key menu-bar-edit-menu [search]
401 (list 'menu-item "Search" menu-bar-search-menu))
403 (define-key menu-bar-edit-menu [separator-search]
406 (define-key menu-bar-edit-menu [mark-whole-buffer]
407 '(menu-item "Select All" mark-whole-buffer
408 :help "Mark the whole buffer for a subsequent cut/copy."))
409 (define-key menu-bar-edit-menu [clear]
410 '(menu-item "Clear" delete-region
411 :enable (and mark-active
412 (not buffer-read-only)
413 (not (mouse-region-match)))
415 "Delete the text in region between mark and current position"))
416 (defvar yank-menu (cons "Select Yank" nil))
417 (fset 'yank-menu (cons 'keymap yank-menu))
418 (define-key menu-bar-edit-menu [select-paste]
419 '(menu-item "Select and Paste" yank-menu
420 :enable (and (cdr yank-menu) (not buffer-read-only))
421 :help "Paste (yank) text cut or copied earlier"))
422 (define-key menu-bar-edit-menu [paste]
423 '(menu-item "Paste" yank
425 ;; Emacs compiled --without-x doesn't have
426 ;; x-selection-exists-p.
427 (fboundp 'x-selection-exists-p)
428 (x-selection-exists-p) (not buffer-read-only))
429 :help "Paste (yank) text most recently cut/copied"))
430 (define-key menu-bar-edit-menu [copy]
431 '(menu-item "Copy" menu-bar-kill-ring-save
433 :help "Copy text in region between mark and current position"
434 :keys "\\[kill-ring-save]"))
435 (define-key menu-bar-edit-menu [cut]
436 '(menu-item "Cut" kill-region
437 :enable (and mark-active (not buffer-read-only))
439 "Cut (kill) text in region between mark and current position"))
440 (define-key menu-bar-edit-menu [undo]
441 '(menu-item "Undo" undo
442 :enable (and (not buffer-read-only)
443 (not (eq t buffer-undo-list))
444 (if (eq last-command 'undo)
446 (consp buffer-undo-list)))
447 :help "Undo last operation"))
450 (defun menu-bar-kill-ring-save (beg end)
452 (if (mouse-region-match)
453 (message "Selecting a region with the mouse does `copy' automatically")
454 (kill-ring-save beg end)))
456 (autoload 'ispell-menu-map "ispell" nil t 'keymap)
458 ;; These are alternative definitions for the cut, paste and copy
459 ;; menu items. Use them if your system expects these to use the clipboard.
461 (put 'clipboard-kill-region 'menu-enable 'mark-active)
462 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
463 (put 'clipboard-yank 'menu-enable
464 '(or (and (fboundp 'x-selection-exists-p) (x-selection-exists-p))
465 (x-selection-exists-p 'CLIPBOARD)))
467 (defun clipboard-yank ()
468 "Insert the clipboard contents, or the last stretch of killed text."
470 (let ((x-select-enable-clipboard t))
473 (defun clipboard-kill-ring-save (beg end)
474 "Copy region to kill ring, and save in the X clipboard."
476 (let ((x-select-enable-clipboard t))
477 (kill-ring-save beg end)))
479 (defun clipboard-kill-region (beg end)
480 "Kill the region, and save it in the X clipboard."
482 (let ((x-select-enable-clipboard t))
483 (kill-region beg end)))
485 (defun menu-bar-enable-clipboard ()
486 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
487 Do the same for the keys of the same name."
489 ;; We can't use constant list structure here because it becomes pure,
490 ;; and because it gets modified with cache data.
491 (define-key menu-bar-edit-menu [paste]
492 (cons "Paste" (cons "Paste text from clipboard" 'clipboard-yank)))
493 (define-key menu-bar-edit-menu [copy]
494 (cons "Copy" (cons "Copy text in region to the clipboard"
495 'clipboard-kill-ring-save)))
496 (define-key menu-bar-edit-menu [cut]
497 (cons "Cut" (cons "Delete text in region and copy it to the clipboard"
498 'clipboard-kill-region)))
500 (define-key global-map [f20] 'clipboard-kill-region)
501 (define-key global-map [f16] 'clipboard-kill-ring-save)
502 (define-key global-map [f18] 'clipboard-yank)
504 (define-key global-map [cut] 'clipboard-kill-region)
505 (define-key global-map [copy] 'clipboard-kill-ring-save)
506 (define-key global-map [paste] 'clipboard-yank))
508 ;; The "Options" menu items
510 (defvar menu-bar-custom-menu (make-sparse-keymap "Customize"))
512 (define-key menu-bar-custom-menu [customize-apropos-groups]
513 '(menu-item "Groups Matching Regexp..." customize-apropos-groups
514 :help "Browse groups whose names match regexp"))
515 (define-key menu-bar-custom-menu [customize-apropos-faces]
516 '(menu-item "Faces Matching Regexp..." customize-apropos-faces
517 :help "Browse faces whose names match regexp"))
518 (define-key menu-bar-custom-menu [customize-apropos-options]
519 '(menu-item "Options Matching Regexp..." customize-apropos-options
520 :help "Browse options whose names match regexp"))
521 (define-key menu-bar-custom-menu [customize-apropos]
522 '(menu-item "Settings Matching Regexp..." customize-apropos
523 :help "Browse customizable settings whose names match regexp"))
524 (define-key menu-bar-custom-menu [separator-1]
526 (define-key menu-bar-custom-menu [customize-group]
527 '(menu-item "Specific Group..." customize-group
528 :help "Customize settings of specific group"))
529 (define-key menu-bar-custom-menu [customize-face]
530 '(menu-item "Specific Face..." customize-face
531 :help "Customize attributes of specific face"))
532 (define-key menu-bar-custom-menu [customize-option]
533 '(menu-item "Specific Option..." customize-option
534 :help "Customize value of specific option"))
535 (define-key menu-bar-custom-menu [separator-2]
537 (define-key menu-bar-custom-menu [customize-changed-options]
538 '(menu-item "New Options..." customize-changed-options
539 :help "Options added or changed in recent Emacs versions"))
540 (define-key menu-bar-custom-menu [customize-saved]
541 '(menu-item "Saved Options" customize-saved
542 :help "Customize previously saved options"))
543 (define-key menu-bar-custom-menu [separator-3]
545 (define-key menu-bar-custom-menu [customize-browse]
546 '(menu-item "Browse Customization Groups" customize-browse
547 :help "Browse all customization groups"))
548 (define-key menu-bar-custom-menu [customize]
549 '(menu-item "Top-level Customization Group" customize
550 :help "The master group called `Emacs'"))
552 ;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
554 (defmacro menu-bar-make-mm-toggle (fname doc help &optional props)
555 "Make a menu-item for a global minor mode toggle.
556 FNAME is the minor mode's name (variable and function).
557 DOC is the text to use the menu entry.
558 HELP is the text to use for the tooltip.
559 PROPS are additional properties."
560 `'(menu-item ,doc ,fname
563 :button (:toggle . (and (default-boundp ',fname)
564 (default-value ',fname)))))
566 (defmacro menu-bar-make-toggle (name variable doc message help &rest body)
569 ,(concat "Toggle whether to " (downcase (substring help 0 1))
570 (substring help 1) ".")
572 (if ,(if body `(progn . ,body)
574 (custom-load-symbol ',variable)
575 (let ((set (or (get ',variable 'custom-set) 'set-default))
576 (get (or (get ',variable 'custom-get) 'default-value)))
577 (funcall set ',variable (not (funcall get ',variable))))))
578 (message ,message "enabled")
579 (message ,message "disabled"))
580 ;; The function `customize-mark-as-set' must only be called when
581 ;; a variable is set interactively, as the purpose is to mark it as
582 ;; a candidate for "Save Options", and we do not want to save options
583 ;; the user have already set explicitly in his init file.
584 (if (interactive-p) (customize-mark-as-set ',variable)))
585 '(menu-item ,doc ,name
587 :button (:toggle . (and (default-boundp ',variable)
588 (default-value ',variable))))))
590 ;;; Assemble all the top-level items of the "Options" menu
591 (define-key menu-bar-options-menu [customize]
592 (list 'menu-item "Customize Emacs" menu-bar-custom-menu
593 :help "Full customization of every Emacs feature"))
595 (defun menu-bar-options-save ()
596 "Save current values of Options menu items using Custom."
598 (let ((need-save nil))
599 ;; These are set with `customize-set-variable'.
600 (dolist (elt '(line-number-mode column-number-mode scroll-bar-mode
601 debug-on-quit debug-on-error menu-bar-mode tool-bar-mode
602 save-place uniquify-buffer-name-style fringe-mode
603 case-fold-search cua-mode show-paren-mode
604 transient-mark-mode global-font-lock-mode
605 display-time-mode auto-compression-mode
606 current-language-environment default-input-method
607 ;; Saving `text-mode-hook' is somewhat questionable,
608 ;; as we might get more than we bargain for, if
609 ;; other code may has added hooks as well.
610 ;; Nonetheless, not saving it would like be confuse
612 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
614 (and (get elt 'customized-value)
615 (customize-mark-to-save elt)
617 ;; Save if we changed anything.
621 (define-key menu-bar-options-menu [save]
622 '(menu-item "Save Options" menu-bar-options-save
623 :help "Save options set from the menu above"))
625 (define-key menu-bar-options-menu [custom-separator]
628 ;; The "Show/Hide" submenu of menu "Options"
630 (defvar menu-bar-showhide-menu (make-sparse-keymap "Show/Hide"))
632 (define-key menu-bar-showhide-menu [column-number-mode]
633 (menu-bar-make-mm-toggle column-number-mode
634 "Show Column Numbers"
635 "Show the current column number in the mode line"))
637 (define-key menu-bar-showhide-menu [line-number-mode]
638 (menu-bar-make-mm-toggle line-number-mode
640 "Show the current line number in the mode line"))
642 (define-key menu-bar-showhide-menu [linecolumn-separator]
645 (defun showhide-date-time ()
646 "Toggle whether to show date and time in the mode-line."
648 (if (display-time-mode)
649 (message "Display-time mode enabled.")
650 (message "Display-time mode disabled."))
651 (customize-mark-as-set 'display-time-mode))
653 (define-key menu-bar-showhide-menu [showhide-date-time]
654 '(menu-item "Date and Time" showhide-date-time
655 :help "Display date and time in the mode line"
656 :button (:toggle . display-time-mode)))
658 (define-key menu-bar-showhide-menu [datetime-separator]
661 (define-key menu-bar-showhide-menu [showhide-speedbar]
662 '(menu-item "Speedbar" speedbar-frame-mode
663 :help "Display a Speedbar quick-navigation frame"
665 . (and (boundp 'speedbar-frame)
666 (frame-live-p (symbol-value 'speedbar-frame))
668 (symbol-value 'speedbar-frame))))))
670 (defvar menu-bar-showhide-fringe-menu (make-sparse-keymap "Fringe"))
672 (defun menu-bar-showhide-fringe-menu-customize ()
673 "Show customization buffer for `fringe-mode'."
675 (customize-variable 'fringe-mode))
677 (define-key menu-bar-showhide-fringe-menu [customize]
678 '(menu-item "Customize" menu-bar-showhide-fringe-menu-customize
679 :help "Detailed customization of fringe"
680 :visible (display-graphic-p)))
682 (defun menu-bar-showhide-fringe-menu-customize-reset ()
683 "Reset the fringe mode: display fringes on both sides of a window."
685 (customize-set-variable 'fringe-mode nil))
687 ;; The real definition is in fringe.el.
688 ;; This is to prevent errors in the :radio conditions below.
689 (setq fringe-mode nil)
691 (define-key menu-bar-showhide-fringe-menu [default]
692 '(menu-item "Default" menu-bar-showhide-fringe-menu-customize-reset
693 :help "Default width fringe on both left and right side"
694 :visible (display-graphic-p)
695 :button (:radio . (eq fringe-mode nil))))
697 (defun menu-bar-showhide-fringe-menu-customize-left ()
698 "Display fringes only on the left of each window."
701 (customize-set-variable 'fringe-mode '(nil . 0)))
703 (define-key menu-bar-showhide-fringe-menu [left]
704 '(menu-item "On the Left" menu-bar-showhide-fringe-menu-customize-left
705 :help "Fringe only on the left side"
706 :visible (display-graphic-p)
707 :button (:radio . (equal fringe-mode '(nil . 0)))))
709 (defun menu-bar-showhide-fringe-menu-customize-right ()
710 "Display fringes only on the right of each window."
713 (customize-set-variable 'fringe-mode '(0 . nil)))
715 (define-key menu-bar-showhide-fringe-menu [right]
716 '(menu-item "On the Right" menu-bar-showhide-fringe-menu-customize-right
717 :help "Fringe only on the right side"
718 :visible (display-graphic-p)
719 :button (:radio . (equal fringe-mode '(0 . nil)))))
721 (defun menu-bar-showhide-fringe-menu-customize-disable ()
722 "Do not display window fringes."
725 (customize-set-variable 'fringe-mode 0))
727 (define-key menu-bar-showhide-fringe-menu [none]
728 '(menu-item "None" menu-bar-showhide-fringe-menu-customize-disable
729 :help "Turn off fringe"
730 :visible (display-graphic-p)
731 :button (:radio . (eq fringe-mode 0))))
733 (define-key menu-bar-showhide-menu [showhide-fringe]
734 (list 'menu-item "Fringe" menu-bar-showhide-fringe-menu
735 :visible `(display-graphic-p)
736 :help "Select fringe mode"))
738 (defvar menu-bar-showhide-scroll-bar-menu (make-sparse-keymap "Scroll-bar"))
740 (define-key menu-bar-showhide-scroll-bar-menu [right]
741 '(menu-item "On the Right"
742 menu-bar-right-scroll-bar
743 :help "Scroll-bar on the right side"
744 :visible (display-graphic-p)
745 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
746 (frame-parameters))) 'right))))
747 (defun menu-bar-right-scroll-bar ()
748 "Display scroll bars on the right of each window."
750 (customize-set-variable 'scroll-bar-mode 'right))
752 (define-key menu-bar-showhide-scroll-bar-menu [left]
753 '(menu-item "On the Left"
754 menu-bar-left-scroll-bar
755 :help "Scroll-bar on the left side"
756 :visible (display-graphic-p)
757 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
758 (frame-parameters))) 'left))))
760 (defun menu-bar-left-scroll-bar ()
761 "Display scroll bars on the left of each window."
763 (customize-set-variable 'scroll-bar-mode 'right))
765 (define-key menu-bar-showhide-scroll-bar-menu [none]
767 menu-bar-no-scroll-bar
768 :help "Turn off scroll-bar"
769 :visible (display-graphic-p)
770 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
771 (frame-parameters))) nil))))
773 (defun menu-bar-no-scroll-bar ()
774 "Turn off scroll bars."
776 (customize-set-variable 'scroll-bar-mode nil))
778 (define-key menu-bar-showhide-menu [showhide-scroll-bar]
779 (list 'menu-item "Scroll-bar" menu-bar-showhide-scroll-bar-menu
780 :visible `(display-graphic-p)
781 :help "Select scroll-bar mode"))
783 (define-key menu-bar-showhide-menu [menu-bar-mode]
784 '(menu-item "Menu-bar" menu-bar-mode
785 :help "Toggle menu-bar on/off"
786 :button (:toggle . menu-bar-mode)))
788 (define-key menu-bar-showhide-menu [showhide-tool-bar]
789 (list 'menu-item "Tool-bar" 'tool-bar-mode
790 :help "Turn tool-bar on/off"
791 :visible `(display-graphic-p)
792 :button `(:toggle . tool-bar-mode)))
794 (define-key menu-bar-options-menu [showhide]
795 (list 'menu-item "Show/Hide" menu-bar-showhide-menu
796 :help "Toggle on/off various display features"))
798 (define-key menu-bar-options-menu [showhide-separator]
801 (define-key menu-bar-options-menu [mule]
802 ;; It is better not to use backquote here,
803 ;; because that makes a bootstrapping problem
804 ;; if you need to recompile all the Lisp files using interpreted code.
805 (list 'menu-item "Mule (Multilingual Environment)" mule-menu-keymap
806 ;; Most of the MULE menu actually does make sense in unibyte mode,
807 ;; e.g. language selection.
808 ;;; ':visible 'default-enable-multibyte-characters
809 ':help "Default language, encodings, input method"))
810 ;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
811 ;(define-key menu-bar-options-menu [preferences]
812 ; (list 'menu-item "Preferences" menu-bar-preferences-menu
813 ; :help "Toggle important global options"))
815 (define-key menu-bar-options-menu [mule-separator]
818 (define-key menu-bar-options-menu [debug-on-quit]
819 (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
820 "Enter Debugger on Quit/C-g" "Debug on Quit %s"
821 "Enter Lisp debugger when C-g is pressed"))
822 (define-key menu-bar-options-menu [debug-on-error]
823 (menu-bar-make-toggle toggle-debug-on-error debug-on-error
824 "Enter Debugger on Error" "Debug on Error %s"
825 "Enter Lisp debugger when an error is signaled"))
826 (define-key menu-bar-options-menu [debugger-separator]
828 (define-key menu-bar-options-menu [toggle-auto-compression]
829 '(menu-item "Automatic File De/compression"
830 auto-compression-mode
831 :help "Transparently decompress compressed files"
832 :button (:toggle . (rassq 'jka-compr-handler
833 file-name-handler-alist))))
835 (define-key menu-bar-options-menu [save-place]
836 (menu-bar-make-toggle toggle-save-place-globally save-place
837 "Save Place in Files between Sessions"
838 "Saving place in files %s"
839 "Save Emacs state for next session"))
841 (define-key menu-bar-options-menu [uniquify]
842 (menu-bar-make-toggle toggle-uniquify-buffer-names uniquify-buffer-name-style
843 "Use Directory Names in Buffer Names"
844 "Directory name in buffer names (uniquify) %s"
845 "Uniquify buffer names by adding parent directory names"
847 (setq uniquify-buffer-name-style
848 (if (not uniquify-buffer-name-style)
851 (define-key menu-bar-options-menu [edit-options-separator]
853 (define-key menu-bar-options-menu [cua-mode]
854 '(menu-item "CUA-style cut and paste"
855 menu-bar-toggle-cua-mode
856 :help "Use C-z/C-x/C-c/C-v keys for undo/cut/copy/paste"
857 :button (:toggle . cua-mode)))
859 (defun menu-bar-toggle-cua-mode ()
860 "Toggle CUA key-binding mode.
861 When enabled, using shifted movement keys will activate the region (and
862 highlight the region using `transient-mark-mode'), and typed text replaces
863 the active selection. C-z, C-x, C-c, and C-v will undo, cut, copy, and
864 paste (in addition to the normal Emacs bindings)."
867 (customize-mark-as-set 'cua-mode)
868 (message "CUA-style cut and paste %s"
869 (if cua-mode "enabled" "disabled")))
871 (define-key menu-bar-options-menu [case-fold-search]
872 (menu-bar-make-toggle toggle-case-fold-search case-fold-search
873 "Case-Insensitive Search"
874 "Case-Insensitive Search %s"
875 "Ignore letter-case in search"))
877 (defun menu-bar-text-mode-auto-fill ()
879 (toggle-text-mode-auto-fill)
880 ;; This is somewhat questionable, as `text-mode-hook'
881 ;; might have changed outside customize.
882 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
883 (customize-mark-as-set 'text-mode-hook))
885 (define-key menu-bar-options-menu [auto-fill-mode]
886 '(menu-item "Word Wrap in Text Modes"
887 menu-bar-text-mode-auto-fill
888 :help "Automatically fill text between left and right margins (Auto Fill)"
889 :button (:toggle . (if (listp text-mode-hook)
890 (member 'turn-on-auto-fill text-mode-hook)
891 (eq 'turn-on-auto-fill text-mode-hook)))))
892 (define-key menu-bar-options-menu [truncate-lines]
893 '(menu-item "Truncate Long Lines in this Buffer"
894 toggle-truncate-lines
895 :help "Truncate long lines on the screen"
896 :button (:toggle . truncate-lines)))
898 (define-key menu-bar-options-menu [highlight-separator]
900 (define-key menu-bar-options-menu [highlight-paren-mode]
901 (menu-bar-make-mm-toggle show-paren-mode
902 "Paren Match Highlighting"
903 "Highlight matching/mismatched parentheses at cursor (Show Paren mode)"))
904 (define-key menu-bar-options-menu [transient-mark-mode]
905 (menu-bar-make-mm-toggle transient-mark-mode
906 "Active Region Highlighting"
907 "Make text in active region stand out in color (Transient Mark mode)"
908 (:enable (not cua-mode))))
909 (define-key menu-bar-options-menu [toggle-global-lazy-font-lock-mode]
910 (menu-bar-make-mm-toggle global-font-lock-mode
911 "Syntax Highlighting"
912 "Colorize text based on language syntax (Global Font Lock mode)"))
915 ;; The "Tools" menu items
917 (defun send-mail-item-name ()
918 (let* ((known-send-mail-commands '((sendmail-user-agent . "sendmail")
919 (mh-e-user-agent . "MH")
920 (message-user-agent . "Gnus Message")
921 (gnus-user-agent . "Gnus")))
922 (name (assq mail-user-agent known-send-mail-commands)))
924 (setq name (cdr name))
925 (setq name (symbol-name mail-user-agent))
926 (if (string-match "\\(.+\\)-user-agent" name)
927 (setq name (match-string 1 name))))
930 (defun read-mail-item-name ()
931 (let* ((known-rmail-commands '((rmail . "RMAIL")
934 (known (assq read-mail-command known-rmail-commands)))
935 (if known (cdr known) (symbol-name read-mail-command))))
937 (defvar menu-bar-games-menu (make-sparse-keymap "Games"))
939 (define-key menu-bar-tools-menu [games]
940 (list 'menu-item "Games" menu-bar-games-menu))
942 (define-key menu-bar-tools-menu [separator-games]
945 (define-key menu-bar-games-menu [zone]
946 '(menu-item "Zone Out" zone
947 :help "Play tricks with Emacs display when Emacs is idle"))
948 (define-key menu-bar-games-menu [yow]
949 '(menu-item "Random Quotation" yow
950 :help "Display a random Zippy quotation"))
951 (define-key menu-bar-games-menu [tetris]
952 '(menu-item "Tetris" tetris))
953 (define-key menu-bar-games-menu [solitaire]
954 '(menu-item "Solitaire" solitaire))
955 (define-key menu-bar-games-menu [snake]
956 '(menu-item "Snake" snake
957 :help "Move snake around avoiding collisions"))
958 (define-key menu-bar-games-menu [mult]
959 '(menu-item "Multiplication Puzzle" mpuz
960 :help "Excercise brain with multiplication"))
961 (define-key menu-bar-games-menu [life]
962 '(menu-item "Life" life
963 :help "Watch how John Conway's cellular automaton evolves"))
964 (define-key menu-bar-games-menu [hanoi]
965 '(menu-item "Towers of Hanoi" hanoi
966 :help "Watch Towers-of-Hanoi puzzle solved by Emacs"))
967 (define-key menu-bar-games-menu [gomoku]
968 '(menu-item "Gomoku" gomoku
969 :help "Mark 5 contiguous squares (like tic-tac-toe)"))
970 (define-key menu-bar-games-menu [black-box]
971 '(menu-item "Blackbox" blackbox
972 :help "Find balls in a black box by shooting rays"))
973 (define-key menu-bar-games-menu [adventure]
974 '(menu-item "Adventure" dunnet
975 :help "Dunnet, a text Adventure game for Emacs"))
976 (define-key menu-bar-games-menu [5x5]
977 '(menu-item "5x5" 5x5
978 :help "Fill in all the squares on a 5x5 board"))
980 (define-key menu-bar-tools-menu [simple-calculator]
981 '(menu-item "Simple Calculator" calculator
982 :help "Invoke the Emacs built-in quick calculator"))
983 (define-key menu-bar-tools-menu [calc]
984 '(menu-item "Programmable Calculator" calc
985 :help "Invoke the Emacs built-in full scientific calculator"))
986 (define-key menu-bar-tools-menu [calendar]
987 '(menu-item "Display Calendar" calendar))
989 (define-key menu-bar-tools-menu [separator-net]
992 (define-key menu-bar-tools-menu [directory-search]
993 '(menu-item "Directory Search" eudc-tools-menu
994 :help "Query directory servers via LDAP, CCSO PH/QI or BBDB"))
995 (define-key menu-bar-tools-menu [compose-mail]
997 'menu-item `(format "Send Mail (with %s)" (send-mail-item-name))
999 :visible `(and mail-user-agent (not (eq mail-user-agent 'ignore)))
1000 :help "Send a mail message"))
1001 (define-key menu-bar-tools-menu [rmail]
1003 'menu-item `(format "Read Mail (with %s)" (read-mail-item-name))
1005 :visible `(and read-mail-command (not (eq read-mail-command 'ignore)))
1006 :help "Read your mail and reply to it"))
1008 (defun menu-bar-read-mail ()
1009 "Read mail using `read-mail-command'."
1011 (call-interactively read-mail-command))
1013 (define-key menu-bar-tools-menu [gnus]
1014 '(menu-item "Read Net News (Gnus)" gnus
1015 :help "Read network news groups"))
1017 (define-key menu-bar-tools-menu [separator-vc]
1020 (defvar vc-menu-map (make-sparse-keymap "Version Control"))
1021 (define-key menu-bar-tools-menu [pcl-cvs]
1022 `(menu-item "PCL-CVS" ,cvs-global-menu
1023 :help "Module-level interface to CVS"))
1024 (define-key menu-bar-tools-menu [vc]
1025 (list 'menu-item "Version Control" vc-menu-map
1026 :help "Interface to RCS, CVS, SCCS"))
1028 (define-key menu-bar-tools-menu [separator-compare]
1031 (define-key menu-bar-tools-menu [ediff-misc]
1032 '(menu-item "Ediff Miscellanea" menu-bar-ediff-misc-menu
1033 :help "Ediff manual, customization, sessions, etc."))
1034 (define-key menu-bar-tools-menu [epatch]
1035 '(menu-item "Apply Patch" menu-bar-epatch-menu))
1036 (define-key menu-bar-tools-menu [ediff-merge]
1037 '(menu-item "Merge" menu-bar-ediff-merge-menu
1038 :help "Merge different revisions of files/directories"))
1039 (define-key menu-bar-tools-menu [compare]
1040 '(menu-item "Compare (Ediff)" menu-bar-ediff-menu
1041 :help "Display differences between files/directories"))
1044 (define-key menu-bar-tools-menu [separator-spell]
1047 (define-key menu-bar-tools-menu [spell]
1048 '(menu-item "Spell Checking" ispell-menu-map))
1050 (define-key menu-bar-tools-menu [separator-prog]
1053 (define-key menu-bar-tools-menu [gdb]
1054 '(menu-item "Debugger (GDB)..." gdb
1055 :help "Debug a program from within Emacs with GDB"))
1056 (define-key menu-bar-tools-menu [shell-on-region]
1057 '(menu-item "Shell Command on Region..." shell-command-on-region
1059 :help "Pass marked region to a shell command"))
1060 (define-key menu-bar-tools-menu [shell]
1061 '(menu-item "Shell Command..." shell-command
1062 :help "Invoke a shell command and catch its output"))
1063 (define-key menu-bar-tools-menu [compile]
1064 '(menu-item "Compile..." compile
1065 :help "Invoke compiler or Make, view compilation errors"))
1066 (define-key menu-bar-tools-menu [grep]
1067 '(menu-item "Search Files (Grep)..." grep
1068 :help "Search files for strings or regexps (with Grep)"))
1071 ;; The "Help" menu items
1073 (defvar menu-bar-describe-menu (make-sparse-keymap "Describe"))
1075 (define-key menu-bar-describe-menu [mule-diag]
1076 '(menu-item "Show All of Mule Status" mule-diag
1077 :visible default-enable-multibyte-characters
1078 :help "Display multilingual environment settings"))
1079 (define-key menu-bar-describe-menu [describe-coding-system-briefly]
1080 '(menu-item "Describe Coding System (Briefly)..."
1081 describe-current-coding-system-briefly
1082 :visible default-enable-multibyte-characters))
1083 (define-key menu-bar-describe-menu [describe-coding-system]
1084 '(menu-item "Describe Coding System..." describe-coding-system
1085 :visible default-enable-multibyte-characters))
1086 (define-key menu-bar-describe-menu [describe-input-method]
1087 '(menu-item "Describe Input Method..." describe-input-method
1088 :visible default-enable-multibyte-characters
1089 :help "Keyboard layout for specific input method"))
1090 (define-key menu-bar-describe-menu [describe-language-environment]
1091 (list 'menu-item "Describe Language Environment"
1092 describe-language-environment-map
1093 :help "Show multilingual settings for a specific language"))
1095 (define-key menu-bar-describe-menu [separator-desc-mule]
1098 (define-key menu-bar-describe-menu [list-keybindings]
1099 '(menu-item "List Key Bindings" describe-bindings
1100 :help "Display a list of all current keybindings"))
1101 (define-key menu-bar-describe-menu [describe-current-display-table]
1102 '(menu-item "Describe Display Table" describe-current-display-table
1103 :help "Describe the current display table"))
1104 (define-key menu-bar-describe-menu [describe-face]
1105 '(menu-item "Describe Face..." describe-face
1106 :help "Display the properties of a face"))
1107 (define-key menu-bar-describe-menu [describe-variable]
1108 '(menu-item "Describe Variable..." describe-variable
1109 :help "Display documentation of variable/option"))
1110 (define-key menu-bar-describe-menu [describe-function]
1111 '(menu-item "Describe Function..." describe-function
1112 :help "Display documentation of function/command"))
1113 (define-key menu-bar-describe-menu [describe-key]
1114 '(menu-item "Describe Key..." describe-key
1115 ;; Users typically don't identify keys and menu items...
1116 :help "Display documentation of command bound to a \
1117 key (or menu-item)"))
1118 (define-key menu-bar-describe-menu [describe-mode]
1119 '(menu-item "Describe Buffer Modes" describe-mode
1120 :help "Describe this buffer's major and minor mode"))
1122 (defvar menu-bar-apropos-menu (make-sparse-keymap "Apropos"))
1123 (defun menu-bar-read-lispref ()
1124 "Display the Emacs Lisp Reference manual in Info mode."
1128 (defun menu-bar-read-lispintro ()
1129 "Display the Introduction to Emacs Lisp Programming in Info mode."
1133 (defun search-emacs-glossary ()
1134 "Display the Glossary node of the Emacs manual in Info mode."
1136 (info "(emacs)Glossary"))
1138 (defun emacs-index-search (topic)
1139 "Look up TOPIC in the indices of the Emacs User Manual."
1140 (interactive "sSubject to look up: ")
1144 (defun elisp-index-search (topic)
1145 "Look up TOPIC in the indices of the Emacs Lisp Reference Manual."
1146 (interactive "sSubject to look up: ")
1150 (define-key menu-bar-apropos-menu [apropos-documentation]
1151 '(menu-item "Search Documentation Strings..." apropos-documentation
1153 "Find functions and variables whose doc strings match a regexp"))
1154 (define-key menu-bar-apropos-menu [apropos]
1155 '(menu-item "Find Any Object by Name..." apropos
1156 :help "Find symbols of any kind whose names match a regexp"))
1157 (define-key menu-bar-apropos-menu [apropos-value]
1158 '(menu-item "Find Options by Value..." apropos-value
1159 :help "Find variables whose values match a regexp"))
1160 (define-key menu-bar-apropos-menu [apropos-variables]
1161 '(menu-item "Find Options by Name..." apropos-variable
1162 :help "Find variables whose names match a regexp"))
1163 (define-key menu-bar-apropos-menu [apropos-commands]
1164 '(menu-item "Find Commands by Name..." apropos-command
1165 :help "Find commands whose names match a regexp"))
1166 (define-key menu-bar-apropos-menu [sep1]
1168 (define-key menu-bar-apropos-menu [elisp-index-search]
1169 '(menu-item "Look Up Subject in ELisp Manual..." elisp-index-search
1170 :help "Find description of a subject in Emacs Lisp manual"))
1171 (define-key menu-bar-apropos-menu [emacs-index-search]
1172 '(menu-item "Look Up Subject in User Manual..." emacs-index-search
1173 :help "Find description of a subject in Emacs User manual"))
1174 (define-key menu-bar-apropos-menu [emacs-glossary]
1175 '(menu-item "Emacs Terminology" search-emacs-glossary
1176 :help "Display the Glossary section of the Emacs manual"))
1178 (defvar menu-bar-manuals-menu (make-sparse-keymap "More Manuals"))
1180 (define-key menu-bar-manuals-menu [man]
1181 '(menu-item "Read Man Page..." manual-entry
1182 :help "Man-page docs for external commands and libraries"))
1183 (define-key menu-bar-manuals-menu [sep2]
1185 (define-key menu-bar-manuals-menu [order-emacs-manuals]
1186 '(menu-item "Ordering Manuals" view-order-manuals
1187 :help "How to order manuals from the Free Software Foundation"))
1188 (define-key menu-bar-manuals-menu [info]
1189 '(menu-item "All Other Manuals (Info)" Info-directory
1190 :help "Read any of the installed manuals"))
1191 (define-key menu-bar-manuals-menu [info-elisp]
1192 '(menu-item "Emacs Lisp Reference" menu-bar-read-lispref
1193 :help "Read the Emacs Lisp Reference manual"))
1194 (define-key menu-bar-manuals-menu [info-elintro]
1195 '(menu-item "Introduction to Emacs Lisp" menu-bar-read-lispintro
1196 :help "Read the Introduction to Emacs Lisp Programming"))
1197 (define-key menu-bar-manuals-menu [sep3]
1199 (define-key menu-bar-manuals-menu [command]
1200 '(menu-item "Find Command in Manual" Info-goto-emacs-command-node
1201 :help "Display manual section that describes a command"))
1202 (define-key menu-bar-manuals-menu [key]
1203 '(menu-item "Find Key in Manual" Info-goto-emacs-key-command-node
1204 :help "Display manual section that describes a key"))
1206 (define-key menu-bar-help-menu [eliza]
1207 '(menu-item "Emacs Psychiatrist" doctor
1208 :help "Our doctor will help you feel better"))
1209 (define-key menu-bar-help-menu [sep4]
1211 (define-key menu-bar-help-menu [describe-no-warranty]
1212 '(menu-item "(Non)Warranty" describe-no-warranty
1213 :help "Explain that Emacs has NO WARRANTY"))
1214 (define-key menu-bar-help-menu [describe-copying]
1215 '(menu-item "Copying Conditions" describe-copying
1216 :help "Show the Emacs license (GPL)"))
1217 (define-key menu-bar-help-menu [describe-distribution]
1218 '(menu-item "Getting New Versions" describe-distribution
1219 :help "How to get latest versions of Emacs"))
1220 (define-key menu-bar-help-menu [more]
1221 '(menu-item "Find Extra Packages"
1222 menu-bar-help-extra-packages
1223 :help "Where to find some extra packages and possible updates"))
1224 (defun menu-bar-help-extra-packages ()
1225 "Display help about some additional packages available for Emacs."
1227 (let (enable-local-variables)
1228 (view-file (expand-file-name "MORE.STUFF"
1231 (define-key menu-bar-help-menu [about]
1232 '(menu-item "About Emacs" display-splash-screen
1233 :help "Display version number, copyright info, and basic help"))
1234 (define-key menu-bar-help-menu [sep2]
1236 (define-key menu-bar-help-menu [finder-by-keyword]
1237 '(menu-item "Find Emacs Packages..." finder-by-keyword
1238 :help "Find packages and features by keyword"))
1239 (define-key menu-bar-help-menu [manuals]
1240 (list 'menu-item "More Manuals" menu-bar-manuals-menu
1241 :help "Search and browse on-line manuals"))
1242 (define-key menu-bar-help-menu [emacs-manual]
1243 '(menu-item "Read the Emacs Manual" info-emacs-manual
1244 :help "Full documentation of Emacs features"))
1245 (define-key menu-bar-help-menu [describe]
1246 (list 'menu-item "Describe" menu-bar-describe-menu
1247 :help "Describe commands, variables, keys"))
1248 (define-key menu-bar-help-menu [apropos]
1249 (list 'menu-item "Search Documentation" menu-bar-apropos-menu
1250 :help "Look up terms, find commands, options, etc. (Apropos)"))
1251 (define-key menu-bar-help-menu [sep1]
1253 (define-key menu-bar-help-menu [report-emacs-bug]
1254 '(menu-item "Send Bug Report..." report-emacs-bug
1255 :help "Send e-mail to Emacs maintainers"))
1256 (define-key menu-bar-help-menu [emacs-problems]
1257 '(menu-item "Emacs Known Problems" view-emacs-problems))
1258 (define-key menu-bar-help-menu [emacs-news]
1259 '(menu-item "Emacs News" view-emacs-news
1260 :help "New features of this version"))
1261 (define-key menu-bar-help-menu [emacs-faq]
1262 '(menu-item "Emacs FAQ" view-emacs-FAQ))
1264 (defun help-with-tutorial-spec-language ()
1265 "Use the Emacs tutorial, specifying which language you want."
1267 (help-with-tutorial t))
1269 (define-key menu-bar-help-menu [emacs-tutorial-language-specific]
1270 '(menu-item "Emacs Tutorial (choose language)..."
1271 help-with-tutorial-spec-language
1272 :help "Learn how to use Emacs (choose a language)"))
1273 (define-key menu-bar-help-menu [emacs-tutorial]
1274 '(menu-item "Emacs Tutorial" help-with-tutorial
1275 :help "Learn how to use Emacs"))
1277 (defun kill-this-buffer () ; for the menubar
1278 "Kill the current buffer."
1280 (kill-buffer (current-buffer)))
1282 (defun kill-this-buffer-enabled-p ()
1284 (buffers (buffer-list)))
1286 (or (string-match "^ " (buffer-name (car buffers)))
1287 (setq count (1+ count)))
1288 (setq buffers (cdr buffers)))
1289 (and (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1292 (put 'dired 'menu-enable
1293 '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
1295 ;; Permit deleting frame if it would leave a visible or iconified frame.
1296 (defun delete-frame-enabled-p ()
1297 "Return non-nil if `delete-frame' should be enabled in the menu bar."
1298 (let ((frames (frame-list))
1301 (if (frame-visible-p (car frames))
1302 (setq count (1+ count)))
1303 (setq frames (cdr frames)))
1306 (defcustom yank-menu-length 20
1307 "*Maximum length to display in the yank-menu."
1311 (defun menu-bar-update-yank-menu (string old)
1312 (let ((front (car (cdr yank-menu)))
1313 (menu-string (if (<= (length string) yank-menu-length)
1316 (substring string 0 (/ yank-menu-length 2))
1318 (substring string (- (/ yank-menu-length 2)))))))
1319 ;; Don't let the menu string be all dashes
1320 ;; because that has a special meaning in a menu.
1321 (if (string-match "\\`-+\\'" menu-string)
1322 (setq menu-string (concat menu-string " ")))
1323 ;; If we're supposed to be extending an existing string, and that
1324 ;; string really is at the front of the menu, then update it in place.
1325 (if (and old (or (eq old (car front))
1326 (string= old (car front))))
1328 (setcar front string)
1329 (setcar (cdr front) menu-string))
1332 (cons string (cons menu-string 'menu-bar-select-yank))
1334 (if (> (length (cdr yank-menu)) kill-ring-max)
1335 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
1337 (put 'menu-bar-select-yank 'apropos-inhibit t)
1338 (defun menu-bar-select-yank ()
1341 (insert last-command-event))
1344 (defcustom buffers-menu-show-directories 'unless-uniquify
1345 "If non-nil, show directories in the Buffers menu for buffers that have them.
1346 The special value `unless-uniquify' means that directories will be shown
1347 unless `uniquify-buffer-name-style' is non-nil (in which case, buffer
1348 names should include enough of a buffer's directory to distinguish it
1349 from other buffers).
1351 Setting this variable directly does not take effect until next time the
1352 Buffers menu is regenerated."
1353 :set (lambda (symbol value)
1355 (menu-bar-update-buffers t))
1356 :initialize 'custom-initialize-default
1357 :type '(choice (const :tag "Never" nil)
1358 (const :tag "Unless uniquify is enabled" unless-uniquify)
1359 (const :tag "Always" t))
1362 (defcustom buffers-menu-show-status t
1363 "If non-nil, show modified/read-only status of buffers in the Buffers menu.
1364 Setting this variable directly does not take effect until next time the
1365 Buffers menu is regenerated."
1366 :set (lambda (symbol value)
1368 (menu-bar-update-buffers t))
1369 :initialize 'custom-initialize-default
1373 (defvar list-buffers-directory nil)
1375 (defvar menu-bar-update-buffers-maxbuf)
1377 (defun menu-bar-select-buffer ()
1379 (switch-to-buffer last-command-event))
1381 (defun menu-bar-select-frame ()
1384 (dolist (f (frame-list))
1385 (when (equal last-command-event (frame-parameter f 'name))
1387 (make-frame-visible frame)
1389 (select-frame frame)))
1391 (defun menu-bar-update-buffers-1 (elt)
1392 (let* ((buf (car elt))
1394 (and (if (eq buffers-menu-show-directories 'unless-uniquify)
1395 (or (not (boundp 'uniquify-buffer-name-style))
1396 (null uniquify-buffer-name-style))
1397 buffers-menu-show-directories)
1398 (or (buffer-file-name buf)
1399 (buffer-local-value 'list-buffers-directory buf)))))
1401 (setq file (file-name-directory file)))
1402 (when (and file (> (length file) 20))
1403 (setq file (concat "..." (substring file -17))))
1404 (cons (if buffers-menu-show-status
1405 (let ((mod (if (buffer-modified-p buf) "*" ""))
1406 (ro (if (buffer-local-value 'buffer-read-only buf) "%" "")))
1408 (format "%s %s%s -- %s" (cdr elt) mod ro file)
1409 (format "%s %s%s" (cdr elt) mod ro)))
1411 (format "%s -- %s" (cdr elt) file)
1415 ;; Used to cache the menu entries for commands in the Buffers menu
1416 (defvar menu-bar-buffers-menu-command-entries nil)
1418 (defun menu-bar-update-buffers (&optional force)
1419 ;; If user discards the Buffers item, play along.
1420 (and (lookup-key (current-global-map) [menu-bar buffer])
1421 (or force (frame-or-buffer-changed-p))
1422 (let ((buffers (buffer-list))
1423 (frames (frame-list))
1424 buffers-menu frames-menu)
1425 ;; If requested, list only the N most recently selected buffers.
1426 (if (and (integerp buffers-menu-max-size)
1427 (> buffers-menu-max-size 1))
1428 (if (> (length buffers) buffers-menu-max-size)
1429 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
1431 ;; Make the menu of buffers proper.
1434 (mapcar 'list buffers))
1435 (menu-bar-update-buffers-maxbuf 0)
1437 ;; Put into each element of buffer-list
1438 ;; the name for actual display,
1439 ;; perhaps truncated in the middle.
1440 (dolist (buf buffer-list)
1441 (let ((name (buffer-name (car buf))))
1443 (if (> (length name) 27)
1444 (concat (substring name 0 12)
1446 (substring name -12))
1448 ;; Compute the maximum length of any name.
1449 (dolist (buf buffer-list)
1450 (unless (eq ?\ (aref (cdr buf) 0))
1451 (setq menu-bar-update-buffers-maxbuf
1452 (max menu-bar-update-buffers-maxbuf
1453 (length (cdr buf))))))
1454 ;; Set ALIST to an alist of the form
1455 ;; ITEM-STRING . BUFFER
1456 (dolist (buf buffer-list)
1457 (unless (eq ?\ (aref (cdr buf) 0))
1458 (push (menu-bar-update-buffers-1 buf) alist)))
1459 ;; Now make the actual list of items, and add
1460 ;; some miscellaneous buffer commands to the end.
1461 (mapcar (lambda (pair)
1462 ;; This is somewhat risque, to use
1463 ;; the buffer name itself as the event
1464 ;; type to define, but it works.
1465 ;; It would not work to use the buffer
1466 ;; since a buffer as an event has its
1468 (nconc (list (buffer-name (cdr pair))
1471 'menu-bar-select-buffer))
1474 ;; Make a Frames menu if we have more than one frame.
1478 (cons "Select Frame"
1482 (list (frame-parameter frame 'name)
1483 (frame-parameter frame 'name)
1485 'menu-bar-select-frame))
1487 ;; Put it after the normal buffers
1490 `((frames-separator "--")
1491 (frames menu-item "Frames" ,frames-menu))))))
1493 ;; Add in some normal commands at the end of the menu. We use
1494 ;; the copy cached in `menu-bar-buffers-menu-command-entries'
1495 ;; if it's been set already. Note that we can't use constant
1496 ;; lists for the menu-entries, because the low-level menu-code
1498 (unless menu-bar-buffers-menu-command-entries
1499 (setq menu-bar-buffers-menu-command-entries
1500 (list '(command-separator "--")
1505 :help "Switch to the \"next\" buffer in a cyclic order")
1510 :help "Switch to the \"previous\" buffer in a cyclic order")
1511 (list 'select-named-buffer
1513 "Select Named Buffer..."
1515 :help "Prompt for a buffer name, and select that buffer in the current window")
1516 (list 'list-all-buffers
1520 :help "Pop up a window listing all emacs buffers"
1523 (nconc buffers-menu menu-bar-buffers-menu-command-entries))
1525 (setq buffers-menu (cons 'keymap (cons "Select Buffer" buffers-menu)))
1526 (define-key (current-global-map) [menu-bar buffer]
1527 (cons "Buffers" buffers-menu)))))
1529 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
1531 (menu-bar-update-buffers)
1533 ;; this version is too slow
1534 ;;(defun format-buffers-menu-line (buffer)
1535 ;; "Returns a string to represent the given buffer in the Buffer menu.
1536 ;;nil means the buffer shouldn't be listed. You can redefine this."
1537 ;; (if (string-match "\\` " (buffer-name buffer))
1540 ;; (set-buffer buffer)
1541 ;; (let ((size (buffer-size)))
1542 ;; (format "%s%s %-19s %6s %-15s %s"
1543 ;; (if (buffer-modified-p) "*" " ")
1544 ;; (if buffer-read-only "%" " ")
1548 ;; (or (buffer-file-name) ""))))))
1550 ;;; Set up a menu bar menu for the minibuffer.
1552 (dolist (map (list minibuffer-local-map
1553 ;; This shouldn't be necessary, but there's a funny
1554 ;; bug in keymap.c that I don't understand yet. -stef
1555 minibuffer-local-completion-map))
1556 (define-key map [menu-bar minibuf]
1557 (cons "Minibuf" (make-sparse-keymap "Minibuf"))))
1559 (let ((map minibuffer-local-completion-map))
1560 (define-key map [menu-bar minibuf ?\?]
1561 (list 'menu-item "List Completions" 'minibuffer-completion-help
1562 :help "Display all possible completions"))
1563 (define-key map [menu-bar minibuf space]
1564 (list 'menu-item "Complete Word" 'minibuffer-complete-word
1565 :help "Complete at most one word"))
1566 (define-key map [menu-bar minibuf tab]
1567 (list 'menu-item "Complete" 'minibuffer-complete
1568 :help "Complete as far as possible")))
1570 (let ((map minibuffer-local-map))
1571 (define-key map [menu-bar minibuf quit]
1572 (list 'menu-item "Quit" 'keyboard-escape-quit
1573 :help "Abort input and exit minibuffer"))
1574 (define-key map [menu-bar minibuf return]
1575 (list 'menu-item "Enter" 'exit-minibuffer
1576 :help "Terminate input and exit minibuffer")))
1578 (defcustom menu-bar-mode t
1579 "Toggle display of a menu bar on each frame.
1580 Setting this variable directly does not take effect;
1581 use either \\[customize] or the function `menu-bar-mode'."
1582 :set (lambda (symbol value)
1583 (menu-bar-mode (or value 0)))
1584 :initialize 'custom-initialize-default
1588 (defun menu-bar-mode (&optional flag)
1589 "Toggle display of a menu bar on each frame.
1590 This command applies to all frames that exist and frames to be
1591 created in the future.
1592 With a numeric argument, if the argument is positive,
1593 turn on menu bars; otherwise, turn off menu bars."
1596 ;; Make menu-bar-mode and default-frame-alist consistent.
1597 (let ((default (assq 'menu-bar-lines default-frame-alist)))
1599 (setq menu-bar-mode (not (eq (cdr default) 0)))
1600 (setq default-frame-alist
1601 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
1602 default-frame-alist))))
1604 ;; Toggle or set the mode, according to FLAG.
1605 (setq menu-bar-mode (if (null flag) (not menu-bar-mode)
1606 (> (prefix-numeric-value flag) 0)))
1608 ;; Apply it to default-frame-alist.
1609 (let ((parameter (assq 'menu-bar-lines default-frame-alist)))
1610 (if (consp parameter)
1611 (setcdr parameter (if menu-bar-mode 1 0))
1612 (setq default-frame-alist
1613 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
1614 default-frame-alist))))
1616 ;; Apply it to existing frames.
1617 (let ((frames (frame-list)))
1619 (let ((height (cdr (assq 'height (frame-parameters (car frames))))))
1620 (modify-frame-parameters (car frames)
1621 (list (cons 'menu-bar-lines
1622 (if menu-bar-mode 1 0))))
1623 (modify-frame-parameters (car frames)
1624 (list (cons 'height height))))
1625 (setq frames (cdr frames))))
1627 (when (interactive-p)
1629 (message "Menu-bar mode enabled.")
1630 (message "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear."))
1631 (customize-mark-as-set 'menu-bar-mode))
1637 ;;; menu-bar.el ends here