]> code.delx.au - gnu-emacs/blob - lisp/menu-bar.el
(mail-extr-all-top-level-domains): Update names.
[gnu-emacs] / lisp / menu-bar.el
1 ;;; menu-bar.el --- define a default menu bar
2
3 ;; Copyright (C) 1993, 1994, 1995, 2000, 2001, 2002 Free Software Foundation, Inc.
4
5 ;; Author: RMS
6 ;; Maintainer: FSF
7 ;; Keywords: internal, mouse
8
9 ;; This file is part of GNU Emacs.
10
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.
15
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.
20
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.
25
26 ;; Avishai Yacobi suggested some menu rearrangements.
27
28 ;;; Commentary:
29
30 ;;; Code:
31
32 ;;; User options:
33
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)
42
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"))
48
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))
53
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))
68
69 ;; This alias is for compatibility with 19.28 and before.
70 (defvar menu-bar-file-menu menu-bar-files-menu)
71
72 ;; This is referenced by some code below; it is defined in uniquify.el
73 (defvar uniquify-buffer-name-style)
74
75 \f
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"))
80
81 (define-key menu-bar-files-menu [separator-exit]
82 '("--"))
83
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"))
99
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"))
104
105 (define-key menu-bar-files-menu [split-window]
106 '(menu-item "Split Window" split-window-vertically
107 :help "Split selected window in two"))
108
109 (define-key menu-bar-files-menu [separator-window]
110 '(menu-item "--"))
111
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"))
133
134 (define-key menu-bar-files-menu [separator-print]
135 '(menu-item "--"))
136
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)
144 nil
145 (concat "\\`"
146 (regexp-quote
147 (file-name-nondirectory
148 auto-save-list-file-prefix)))
149 t))
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)
168 (buffer-file-name)
169 (not (window-minibuffer-p
170 (frame-selected-window menu-updating-frame))))
171 :help "Save current buffer to its file"))
172
173 (define-key menu-bar-files-menu [separator-save]
174 '(menu-item "--"))
175
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"))
193
194 \f
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)))
203
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)))
211
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)))
219
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)))
227
228 (defun nonincremental-repeat-search-forward ()
229 "Search forward for the previous search string."
230 (interactive)
231 (if (null search-ring)
232 (error "No previous search"))
233 (search-forward (car search-ring)))
234
235 (defun nonincremental-repeat-search-backward ()
236 "Search backward for the previous search string."
237 (interactive)
238 (if (null search-ring)
239 (error "No previous search"))
240 (search-backward (car search-ring)))
241
242 (defun nonincremental-repeat-re-search-forward ()
243 "Search forward for the previous regular expression."
244 (interactive)
245 (if (null regexp-search-ring)
246 (error "No previous search"))
247 (re-search-forward (car regexp-search-ring)))
248
249 (defun nonincremental-repeat-re-search-backward ()
250 "Search backward for the previous regular expression."
251 (interactive)
252 (if (null regexp-search-ring)
253 (error "No previous search"))
254 (re-search-backward (car regexp-search-ring)))
255
256 (defvar menu-bar-search-menu (make-sparse-keymap "Search"))
257 (defvar menu-bar-adv-search-menu
258 (make-sparse-keymap "Advanced Search/Replace"))
259
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"))
269
270 (define-key menu-bar-adv-search-menu [separator-tag-search]
271 '(menu-item "--"))
272
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]
293 '(menu-item "--"))
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"))
303
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
310 :enable search-ring
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
314 :enable search-ring
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"))
322
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"))
327
328 (define-key menu-bar-edit-menu [fill]
329 '(menu-item "Fill" fill-region
330 :enable (and mark-active (not buffer-read-only))
331 :help
332 "Fill text in region to fit between left and right margin"))
333
334 (define-key menu-bar-edit-menu [separator-bookmark]
335 '(menu-item "--"))
336
337 (define-key menu-bar-edit-menu [bookmark]
338 '(menu-item "Bookmarks" menu-bar-bookmark-map
339 :help "Record positions and jump between them"))
340
341 (defvar menu-bar-goto-menu (make-sparse-keymap "Go To"))
342
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"))
346
347 (define-key menu-bar-goto-menu [separator-tag-file]
348 '(menu-item "--"))
349
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 (lambda () (interactive) (find-tag-other-window nil t))
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"))
359 (define-key menu-bar-goto-menu [next-tag]
360 '(menu-item "Find Next Tag"
361 (lambda () (interactive) (find-tag nil t))
362 :enable (and (boundp 'tags-location-ring)
363 (not (ring-empty-p tags-location-ring)))
364 :help "Find next function/variable matching last tag name"))
365 (define-key menu-bar-goto-menu [find-tag-otherw]
366 '(menu-item "Find Tag in Other Window..." find-tag-other-window
367 :help "Find function/variable definition in another window"))
368 (define-key menu-bar-goto-menu [find-tag]
369 '(menu-item "Find Tag..." find-tag
370 :help "Find definition of function or variable"))
371
372 (define-key menu-bar-goto-menu [separator-tags]
373 '(menu-item "--"))
374
375 (define-key menu-bar-goto-menu [end-of-buf]
376 '(menu-item "Goto End of Buffer" end-of-buffer))
377 (define-key menu-bar-goto-menu [beg-of-buf]
378 '(menu-item "Goto Beginning of Buffer" beginning-of-buffer))
379 (define-key menu-bar-goto-menu [go-to-pos]
380 '(menu-item "Goto Buffer Position..." goto-char
381 :help "Read a number N and go to buffer position N"))
382 (define-key menu-bar-goto-menu [go-to-line]
383 '(menu-item "Goto Line..." goto-line
384 :help "Read a line number and go to that line"))
385
386 (define-key menu-bar-edit-menu [goto]
387 (list 'menu-item "Go To" menu-bar-goto-menu))
388
389 (define-key menu-bar-edit-menu [search]
390 (list 'menu-item "Search" menu-bar-search-menu))
391
392 (define-key menu-bar-edit-menu [separator-search]
393 '(menu-item "--"))
394
395 (define-key menu-bar-edit-menu [mark-whole-buffer]
396 '(menu-item "Select All" mark-whole-buffer
397 :help "Mark the whole buffer for a subsequent cut/copy."))
398 (define-key menu-bar-edit-menu [clear]
399 '(menu-item "Clear" delete-region
400 :enable (and mark-active
401 (not buffer-read-only)
402 (not (mouse-region-match)))
403 :help
404 "Delete the text in region between mark and current position"))
405 (defvar yank-menu (cons "Select Yank" nil))
406 (fset 'yank-menu (cons 'keymap yank-menu))
407 (define-key menu-bar-edit-menu [select-paste]
408 '(menu-item "Select and Paste" yank-menu
409 :enable (and (cdr yank-menu) (not buffer-read-only))
410 :help "Paste (yank) text cut or copied earlier"))
411 (define-key menu-bar-edit-menu [paste]
412 '(menu-item "Paste" yank
413 :enable (and
414 ;; Emacs compiled --without-x doesn't have
415 ;; x-selection-exists-p.
416 (fboundp 'x-selection-exists-p)
417 (x-selection-exists-p) (not buffer-read-only))
418 :help "Paste (yank) text most recently cut/copied"))
419 (define-key menu-bar-edit-menu [copy]
420 '(menu-item "Copy" menu-bar-kill-ring-save
421 :enable mark-active
422 :help "Copy text in region between mark and current position"
423 :keys "\\[kill-ring-save]"))
424 (define-key menu-bar-edit-menu [cut]
425 '(menu-item "Cut" kill-region
426 :enable (and mark-active (not buffer-read-only))
427 :help
428 "Cut (kill) text in region between mark and current position"))
429 (define-key menu-bar-edit-menu [undo]
430 '(menu-item "Undo" undo
431 :enable (and (not buffer-read-only)
432 (not (eq t buffer-undo-list))
433 (if (eq last-command 'undo)
434 pending-undo-list
435 (consp buffer-undo-list)))
436 :help "Undo last operation"))
437
438
439 (defun menu-bar-kill-ring-save (beg end)
440 (interactive "r")
441 (if (mouse-region-match)
442 (message "Selecting a region with the mouse does `copy' automatically")
443 (kill-ring-save beg end)))
444
445 (autoload 'ispell-menu-map "ispell" nil t 'keymap)
446
447 ;; These are alternative definitions for the cut, paste and copy
448 ;; menu items. Use them if your system expects these to use the clipboard.
449
450 (put 'clipboard-kill-region 'menu-enable 'mark-active)
451 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
452 (put 'clipboard-yank 'menu-enable
453 '(or (and (fboundp 'x-selection-exists-p) (x-selection-exists-p))
454 (x-selection-exists-p 'CLIPBOARD)))
455
456 (defun clipboard-yank ()
457 "Insert the clipboard contents, or the last stretch of killed text."
458 (interactive)
459 (let ((x-select-enable-clipboard t))
460 (yank)))
461
462 (defun clipboard-kill-ring-save (beg end)
463 "Copy region to kill ring, and save in the X clipboard."
464 (interactive "r")
465 (let ((x-select-enable-clipboard t))
466 (kill-ring-save beg end)))
467
468 (defun clipboard-kill-region (beg end)
469 "Kill the region, and save it in the X clipboard."
470 (interactive "r")
471 (let ((x-select-enable-clipboard t))
472 (kill-region beg end)))
473
474 (defun menu-bar-enable-clipboard ()
475 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
476 Do the same for the keys of the same name."
477 (interactive)
478 ;; We can't use constant list structure here because it becomes pure,
479 ;; and because it gets modified with cache data.
480 (define-key menu-bar-edit-menu [paste]
481 (cons "Paste" (cons "Paste text from clipboard" 'clipboard-yank)))
482 (define-key menu-bar-edit-menu [copy]
483 (cons "Copy" (cons "Copy text in region to the clipboard"
484 'clipboard-kill-ring-save)))
485 (define-key menu-bar-edit-menu [cut]
486 (cons "Cut" (cons "Delete text in region and copy it to the clipboard"
487 'clipboard-kill-region)))
488
489 (define-key global-map [f20] 'clipboard-kill-region)
490 (define-key global-map [f16] 'clipboard-kill-ring-save)
491 (define-key global-map [f18] 'clipboard-yank)
492 ;; X11R6 versions
493 (define-key global-map [cut] 'clipboard-kill-region)
494 (define-key global-map [copy] 'clipboard-kill-ring-save)
495 (define-key global-map [paste] 'clipboard-yank))
496 \f
497 ;; The "Options" menu items
498
499 (defvar menu-bar-custom-menu (make-sparse-keymap "Customize"))
500
501 (define-key menu-bar-custom-menu [customize-apropos-groups]
502 '(menu-item "Groups Matching Regexp..." customize-apropos-groups
503 :help "Browse groups whose names match regexp"))
504 (define-key menu-bar-custom-menu [customize-apropos-faces]
505 '(menu-item "Faces Matching Regexp..." customize-apropos-faces
506 :help "Browse faces whose names match regexp"))
507 (define-key menu-bar-custom-menu [customize-apropos-options]
508 '(menu-item "Options Matching Regexp..." customize-apropos-options
509 :help "Browse options whose names match regexp"))
510 (define-key menu-bar-custom-menu [customize-apropos]
511 '(menu-item "Settings Matching Regexp..." customize-apropos
512 :help "Browse customizable settings whose names match regexp"))
513 (define-key menu-bar-custom-menu [separator-1]
514 '("--"))
515 (define-key menu-bar-custom-menu [customize-group]
516 '(menu-item "Specific Group..." customize-group
517 :help "Customize settings of specific group"))
518 (define-key menu-bar-custom-menu [customize-face]
519 '(menu-item "Specific Face..." customize-face
520 :help "Customize attributes of specific face"))
521 (define-key menu-bar-custom-menu [customize-option]
522 '(menu-item "Specific Option..." customize-option
523 :help "Customize value of specific option"))
524 (define-key menu-bar-custom-menu [separator-2]
525 '("--"))
526 (define-key menu-bar-custom-menu [customize-changed-options]
527 '(menu-item "New Options..." customize-changed-options
528 :help "Options added or changed in recent Emacs versions"))
529 (define-key menu-bar-custom-menu [customize-saved]
530 '(menu-item "Saved Options" customize-saved
531 :help "Customize previously saved options"))
532 (define-key menu-bar-custom-menu [separator-3]
533 '("--"))
534 (define-key menu-bar-custom-menu [customize-browse]
535 '(menu-item "Browse Customization Groups" customize-browse
536 :help "Browse all customization groups"))
537 (define-key menu-bar-custom-menu [customize]
538 '(menu-item "Top-level Customization Group" customize
539 :help "The master group called `Emacs'"))
540
541 ;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
542
543 (defmacro menu-bar-make-toggle (name variable doc message help &optional props &rest body)
544 `(progn
545 (defun ,name ()
546 ,(concat "Toggle whether to " (downcase (substring help 0 1))
547 (substring help 1) ".")
548 (interactive)
549 (if ,(if body `(progn . ,body)
550 `(progn
551 (custom-load-symbol ',variable)
552 (let ((set (or (get ',variable 'custom-set) 'set-default))
553 (get (or (get ',variable 'custom-get) 'default-value)))
554 (funcall set ',variable (not (funcall get ',variable))))))
555 (message ,message "enabled")
556 (message ,message "disabled")))
557 ;; The function `customize-mark-as-set' must only be called when
558 ;; a variable is set interactively, as the purpose is to mark it
559 ;; as a candidate for "Save Options", and we do not want to save
560 ;; options the user have already set explicitly in his init
561 ;; file. Unfortunately, he could very likely call the function
562 ;; defined above there. So we put `customize-mark-as-set' in a
563 ;; lambda expression.
564 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
565 '(menu-item ,doc (lambda ()
566 (interactive)
567 (,name)
568 (customize-mark-as-set ',variable))
569 ,@(if props props)
570 :help ,help
571 :button (:toggle . (and (default-boundp ',variable)
572 (default-value ',variable))))))
573
574 ;;; Assemble all the top-level items of the "Options" menu
575 (define-key menu-bar-options-menu [customize]
576 (list 'menu-item "Customize Emacs" menu-bar-custom-menu
577 :help "Full customization of every Emacs feature"))
578
579 (defun menu-bar-options-save ()
580 "Save current values of Options menu items using Custom."
581 (interactive)
582 (let ((need-save nil))
583 ;; These are set with `customize-set-variable'.
584 (dolist (elt '(line-number-mode column-number-mode scroll-bar-mode
585 debug-on-quit debug-on-error menu-bar-mode tool-bar-mode
586 save-place uniquify-buffer-name-style fringe-mode
587 case-fold-search cua-mode show-paren-mode
588 transient-mark-mode global-font-lock-mode
589 display-time-mode auto-compression-mode
590 current-language-environment default-input-method
591 ;; Saving `text-mode-hook' is somewhat questionable,
592 ;; as we might get more than we bargain for, if
593 ;; other code may has added hooks as well.
594 ;; Nonetheless, not saving it would like be confuse
595 ;; more often.
596 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
597 text-mode-hook))
598 (and (get elt 'customized-value)
599 (customize-mark-to-save elt)
600 (setq need-save t)))
601 ;; Save if we changed anything.
602 (when need-save
603 (custom-save-all))))
604
605 (define-key menu-bar-options-menu [save]
606 '(menu-item "Save Options" menu-bar-options-save
607 :help "Save options set from the menu above"))
608
609 (define-key menu-bar-options-menu [custom-separator]
610 '("--"))
611
612 ;; The "Show/Hide" submenu of menu "Options"
613
614 (defvar menu-bar-showhide-menu (make-sparse-keymap "Show/Hide"))
615
616 (define-key menu-bar-showhide-menu [column-number-mode]
617 (menu-bar-make-toggle toggle-column-number-mode column-number-mode
618 "Show Column Numbers" "Column number mode %s"
619 "Show the current column number in the mode line"))
620
621 (define-key menu-bar-showhide-menu [line-number-mode]
622 (menu-bar-make-toggle toggle-line-number-mode line-number-mode
623 "Show Line Numbers" "Line number mode %s"
624 "Show the current line number in the mode line"))
625
626 (define-key menu-bar-showhide-menu [linecolumn-separator]
627 '("--"))
628
629 (defun showhide-date-time ()
630 "Toggle whether to show date and time in the mode-line."
631 (interactive)
632 (if (display-time-mode)
633 (message "Display-time mode enabled.")
634 (message "Display-time mode disabled.")))
635
636 (define-key menu-bar-showhide-menu [showhide-date-time]
637 '(menu-item "Date and Time" (lambda ()
638 (interactive)
639 (showhide-date-time)
640 (customize-mark-as-set 'display-time-mode))
641 :help "Display date and time in the mode line"
642 :button (:toggle . display-time-mode)))
643
644 (define-key menu-bar-showhide-menu [datetime-separator]
645 '("--"))
646
647 (define-key menu-bar-showhide-menu [showhide-speedbar]
648 '(menu-item "Speedbar" speedbar-frame-mode
649 :help "Display a Speedbar quick-navigation frame"
650 :button (:toggle
651 . (and (boundp 'speedbar-frame)
652 (frame-live-p (symbol-value 'speedbar-frame))
653 (frame-visible-p
654 (symbol-value 'speedbar-frame))))))
655
656 (defvar menu-bar-showhide-fringe-menu (make-sparse-keymap "Fringe"))
657
658 (defun menu-bar-showhide-fringe-menu-customize ()
659 "Show customization buffer for `fringe-mode'."
660 (interactive)
661 (customize-variable 'fringe-mode))
662
663 (define-key menu-bar-showhide-fringe-menu [customize]
664 '(menu-item "Customize" menu-bar-showhide-fringe-menu-customize
665 :help "Detailed customization of fringe"
666 :visible (display-graphic-p)))
667
668 (defun menu-bar-showhide-fringe-menu-customize-reset ()
669 "Reset the default fringe mode."
670 (interactive)
671 (customize-set-variable 'fringe-mode nil))
672
673 (define-key menu-bar-showhide-fringe-menu [default]
674 '(menu-item "Default" menu-bar-showhide-fringe-menu-customize-reset
675 :help "Default width fringe on both left and right side"
676 :visible (display-graphic-p)
677 :button (:radio . (or (not (boundp 'fringe-mode))
678 (eq fringe-mode nil)))))
679
680 (defun menu-bar-showhide-fringe-menu-customize-left ()
681 "Make fringes appear only on the left."
682 (interactive)
683 (require 'fringe)
684 (customize-set-variable 'fringe-mode '(nil . 0)))
685
686 (define-key menu-bar-showhide-fringe-menu [left]
687 '(menu-item "On the Left" menu-bar-showhide-fringe-menu-customize-left
688 :help "Fringe only on the left side"
689 :visible (display-graphic-p)
690 :button (:radio . (and (boundp 'fringe-mode)
691 (equal fringe-mode '(nil . 0))))))
692
693 (defun menu-bar-showhide-fringe-menu-customize-right ()
694 "Make fringes appear only on the right."
695 (interactive)
696 (require 'fringe)
697 (customize-set-variable 'fringe-mode '(0 . nil)))
698
699 (define-key menu-bar-showhide-fringe-menu [right]
700 '(menu-item "On the Right" menu-bar-showhide-fringe-menu-customize-right
701 :help "Fringe only on the right side"
702 :visible (display-graphic-p)
703 :button (:radio . (and (boundp 'fringe-mode)
704 (equal fringe-mode '(0 . nil))))))
705
706 (defun menu-bar-showhide-fringe-menu-customize-disable ()
707 "Make fringes disappear."
708 (interactive)
709 (require 'fringe)
710 (customize-set-variable 'fringe-mode 0))
711
712 (define-key menu-bar-showhide-fringe-menu [none]
713 '(menu-item "None" menu-bar-showhide-fringe-menu-customize-disable
714 :help "Turn off fringe"
715 :visible (display-graphic-p)
716 :button (:radio . (and (boundp 'fringe-mode)
717 (eq fringe-mode 0)))))
718
719 (define-key menu-bar-showhide-menu [showhide-fringe]
720 (list 'menu-item "Fringe" menu-bar-showhide-fringe-menu
721 :visible `(display-graphic-p)
722 :help "Select fringe mode"))
723
724 (defvar menu-bar-showhide-scroll-bar-menu (make-sparse-keymap "Scroll-bar"))
725
726 (define-key menu-bar-showhide-scroll-bar-menu [right]
727 '(menu-item "On the Right"
728 (lambda ()
729 (interactive)
730 (customize-set-variable 'scroll-bar-mode 'right))
731 :help "Scroll-bar on the right side"
732 :visible (display-graphic-p)
733 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
734 (frame-parameters))) 'right))))
735
736 (define-key menu-bar-showhide-scroll-bar-menu [left]
737 '(menu-item "On the Left"
738 (lambda ()
739 (interactive)
740 (customize-set-variable 'scroll-bar-mode 'left))
741 :help "Scroll-bar on the left side"
742 :visible (display-graphic-p)
743 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
744 (frame-parameters))) 'left))))
745
746 (define-key menu-bar-showhide-scroll-bar-menu [none]
747 '(menu-item "None"
748 (lambda ()
749 (interactive)
750 (customize-set-variable 'scroll-bar-mode nil))
751 :help "Turn off scroll-bar"
752 :visible (display-graphic-p)
753 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
754 (frame-parameters))) nil))))
755
756 (define-key menu-bar-showhide-menu [showhide-scroll-bar]
757 (list 'menu-item "Scroll-bar" menu-bar-showhide-scroll-bar-menu
758 :visible `(display-graphic-p)
759 :help "Select scroll-bar mode"))
760
761 (defun showhide-menu-bar ()
762 "Toggle whether to turn menu-bar on/off."
763 (interactive)
764 (menu-bar-mode)
765 (if menu-bar-mode
766 (message "Menu-bar mode enabled.")
767 (message "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear."))
768 (customize-mark-as-set 'menu-bar-mode))
769
770 (define-key menu-bar-showhide-menu [showhide-menu-bar]
771 '(menu-item "Menu-bar" showhide-menu-bar
772 :help "Toggle menu-bar on/off"
773 :button (:toggle . menu-bar-mode)))
774
775 (defun showhide-toolbar ()
776 "Toggle whether to turn tool-bar on/off."
777 (interactive)
778 (if (tool-bar-mode)
779 (message "Tool-bar mode enabled.")
780 (message "Tool-bar mode disabled."))
781 (customize-mark-as-set 'tool-bar-mode))
782
783 (define-key menu-bar-showhide-menu [showhide-tool-bar]
784 (list 'menu-item "Tool-bar" 'showhide-toolbar
785 :help "Turn tool-bar on/off"
786 :visible `(display-graphic-p)
787 :button `(:toggle . tool-bar-mode)))
788
789 (define-key menu-bar-options-menu [showhide]
790 (list 'menu-item "Show/Hide" menu-bar-showhide-menu
791 :help "Toggle on/off various display features"))
792
793 (define-key menu-bar-options-menu [showhide-separator]
794 '("--"))
795
796 (define-key menu-bar-options-menu [mule]
797 ;; It is better not to use backquote here,
798 ;; because that makes a bootstrapping problem
799 ;; if you need to recompile all the Lisp files using interpreted code.
800 (list 'menu-item "Mule (Multilingual Environment)" mule-menu-keymap
801 ;; Most of the MULE menu actually does make sense in unibyte mode,
802 ;; e.g. language selection.
803 ;;; ':visible 'default-enable-multibyte-characters
804 ':help "Default language, encodings, input method"))
805 ;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
806 ;(define-key menu-bar-options-menu [preferences]
807 ; (list 'menu-item "Preferences" menu-bar-preferences-menu
808 ; :help "Toggle important global options"))
809
810 (define-key menu-bar-options-menu [mule-separator]
811 '("--"))
812
813 (define-key menu-bar-options-menu [debug-on-quit]
814 (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
815 "Enter Debugger on Quit/C-g" "Debug on Quit %s"
816 "Enter Lisp debugger when C-g is pressed"))
817 (define-key menu-bar-options-menu [debug-on-error]
818 (menu-bar-make-toggle toggle-debug-on-error debug-on-error
819 "Enter Debugger on Error" "Debug on Error %s"
820 "Enter Lisp debugger when an error is signaled"))
821 (define-key menu-bar-options-menu [debugger-separator]
822 '("--"))
823 (define-key menu-bar-options-menu [toggle-auto-compression]
824 '(menu-item "Automatic File De/compression"
825 (lambda ()
826 (interactive)
827 (auto-compression-mode)
828 (customize-mark-as-set 'auto-compression-mode))
829 :help "Transparently decompress compressed files"
830 :button (:toggle . (rassq 'jka-compr-handler
831 file-name-handler-alist))))
832 (define-key menu-bar-options-menu [save-place]
833 (menu-bar-make-toggle toggle-save-place-globally save-place
834 "Save Place in Files between Sessions"
835 "Saving place in files %s"
836 "Save Emacs state for next session"))
837
838 (define-key menu-bar-options-menu [uniquify]
839 (menu-bar-make-toggle toggle-uniquify-buffer-names uniquify-buffer-name-style
840 "Use Directory Names in Buffer Names"
841 "Directory name in buffer names (uniquify) %s"
842 "Uniquify buffer names by adding parent directory names"
843 () ; no props
844 (require 'uniquify)
845 (setq uniquify-buffer-name-style
846 (if (not uniquify-buffer-name-style)
847 'forward))))
848
849 (define-key menu-bar-options-menu [edit-options-separator]
850 '("--"))
851 (define-key menu-bar-options-menu [cua-mode]
852 '(menu-item "CUA-style cut and paste"
853 (lambda ()
854 (interactive)
855 (cua-mode nil)
856 (customize-mark-as-set 'cua-mode)
857 (message "CUA-style cut and paste %s"
858 (if cua-mode "enabled" "disabled")))
859 :help "Use C-z/C-x/C-c/C-v keys for undo/cut/copy/paste"
860 :button (:toggle . cua-mode)))
861 (define-key menu-bar-options-menu [case-fold-search]
862 (menu-bar-make-toggle toggle-case-fold-search case-fold-search
863 "Case-Insensitive Search"
864 "Case-Insensitive Search %s"
865 "Ignore letter-case in search"))
866 (define-key menu-bar-options-menu [auto-fill-mode]
867 '(menu-item "Word Wrap in Text Modes"
868 (lambda ()
869 (interactive)
870 (toggle-text-mode-auto-fill)
871 ;; This is somewhat questionable, as `text-mode-hook'
872 ;; might have changed outside customize.
873 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
874 (customize-mark-as-set 'text-mode-hook))
875 :help "Automatically fill text between left and right margins (Auto Fill)"
876 :button (:toggle . (if (listp text-mode-hook)
877 (member 'turn-on-auto-fill text-mode-hook)
878 (eq 'turn-on-auto-fill text-mode-hook)))))
879 (define-key menu-bar-options-menu [truncate-lines]
880 '(menu-item "Truncate Long Lines in this Buffer"
881 (lambda ()
882 (interactive)
883 (setq truncate-lines (not truncate-lines))
884 (set-buffer-modified-p (buffer-modified-p))
885 (message "Truncate long lines %s"
886 (if truncate-lines "enabled" "disabled")))
887 :help "Truncate long lines on the screen"
888 :button (:toggle . truncate-lines)))
889
890 (define-key menu-bar-options-menu [highlight-separator]
891 '("--"))
892 (define-key menu-bar-options-menu [highlight-paren-mode]
893 (menu-bar-make-toggle toggle-highlight-paren-mode show-paren-mode
894 "Paren Match Highlighting"
895 "Show Paren mode %s"
896 "Highlight matching/mismatched parentheses at cursor (Show Paren mode)"))
897 (define-key menu-bar-options-menu [transient-mark-mode]
898 (menu-bar-make-toggle toggle-transient-mark-mode transient-mark-mode
899 "Active Region Highlighting"
900 "Transient Mark mode %s"
901 "Make text in active region stand out in color (Transient Mark mode)"
902 (:enable (not cua-mode))))
903 (define-key menu-bar-options-menu [toggle-global-lazy-font-lock-mode]
904 (menu-bar-make-toggle toggle-global-lazy-font-lock-mode global-font-lock-mode
905 "Syntax Highlighting"
906 "Global Font Lock mode %s"
907 "Colorize text based on language syntax (Global Font Lock mode)"))
908
909 \f
910 ;; The "Tools" menu items
911
912 (defun send-mail-item-name ()
913 (let* ((known-send-mail-commands '((sendmail-user-agent . "sendmail")
914 (mh-e-user-agent . "MH")
915 (message-user-agent . "Gnus Message")
916 (gnus-user-agent . "Gnus")))
917 (name (assq mail-user-agent known-send-mail-commands)))
918 (if name
919 (setq name (cdr name))
920 (setq name (symbol-name mail-user-agent))
921 (if (string-match "\\(.+\\)-user-agent" name)
922 (setq name (match-string 1 name))))
923 name))
924
925 (defun read-mail-item-name ()
926 (let* ((known-rmail-commands '((rmail . "RMAIL")
927 (mh-rmail . "MH")
928 (gnus . "Gnus")))
929 (known (assq read-mail-command known-rmail-commands)))
930 (if known (cdr known) (symbol-name read-mail-command))))
931
932 (defvar menu-bar-games-menu (make-sparse-keymap "Games"))
933
934 (define-key menu-bar-tools-menu [games]
935 (list 'menu-item "Games" menu-bar-games-menu))
936
937 (define-key menu-bar-tools-menu [separator-games]
938 '("--"))
939
940 (define-key menu-bar-games-menu [zone]
941 '(menu-item "Zone Out" zone
942 :help "Play tricks with Emacs display when Emacs is idle"))
943 (define-key menu-bar-games-menu [yow]
944 '(menu-item "Random Quotation" yow
945 :help "Display a random Zippy quotation"))
946 (define-key menu-bar-games-menu [tetris]
947 '(menu-item "Tetris" tetris))
948 (define-key menu-bar-games-menu [solitaire]
949 '(menu-item "Solitaire" solitaire))
950 (define-key menu-bar-games-menu [snake]
951 '(menu-item "Snake" snake
952 :help "Move snake around avoiding collisions"))
953 (define-key menu-bar-games-menu [mult]
954 '(menu-item "Multiplication Puzzle" mpuz
955 :help "Excercise brain with multiplication"))
956 (define-key menu-bar-games-menu [life]
957 '(menu-item "Life" life
958 :help "Watch how John Conway's cellular automaton evolves"))
959 (define-key menu-bar-games-menu [hanoi]
960 '(menu-item "Towers of Hanoi" hanoi
961 :help "Watch Towers-of-Hanoi puzzle solved by Emacs"))
962 (define-key menu-bar-games-menu [gomoku]
963 '(menu-item "Gomoku" gomoku
964 :help "Mark 5 contiguous squares (like tic-tac-toe)"))
965 (define-key menu-bar-games-menu [black-box]
966 '(menu-item "Blackbox" blackbox
967 :help "Find balls in a black box by shooting rays"))
968 (define-key menu-bar-games-menu [adventure]
969 '(menu-item "Adventure" dunnet
970 :help "Dunnet, a text Adventure game for Emacs"))
971 (define-key menu-bar-games-menu [5x5]
972 '(menu-item "5x5" 5x5
973 :help "Fill in all the squares on a 5x5 board"))
974
975 (define-key menu-bar-tools-menu [simple-calculator]
976 '(menu-item "Simple Calculator" calculator
977 :help "Invoke the Emacs built-in quick calculator"))
978 (define-key menu-bar-tools-menu [calc]
979 '(menu-item "Programmable Calculator" calc
980 :help "Invoke the Emacs built-in full scientific calculator"))
981 (define-key menu-bar-tools-menu [calendar]
982 '(menu-item "Display Calendar" calendar))
983
984 (define-key menu-bar-tools-menu [separator-net]
985 '("--"))
986
987 (define-key menu-bar-tools-menu [directory-search]
988 '(menu-item "Directory Search" eudc-tools-menu
989 :help "Query directory servers via LDAP, CCSO PH/QI or BBDB"))
990 (define-key menu-bar-tools-menu [compose-mail]
991 (list
992 'menu-item `(format "Send Mail (with %s)" (send-mail-item-name))
993 'compose-mail
994 :visible `(and mail-user-agent (not (eq mail-user-agent 'ignore)))
995 :help "Send a mail message"))
996 (define-key menu-bar-tools-menu [rmail]
997 (list
998 'menu-item `(format "Read Mail (with %s)" (read-mail-item-name))
999 (lambda ()
1000 (interactive)
1001 (call-interactively read-mail-command))
1002 :visible `(and read-mail-command (not (eq read-mail-command 'ignore)))
1003 :help "Read your mail and reply to it"))
1004 (define-key menu-bar-tools-menu [gnus]
1005 '(menu-item "Read Net News (Gnus)" gnus
1006 :help "Read network news groups"))
1007
1008 (define-key menu-bar-tools-menu [separator-vc]
1009 '("--"))
1010
1011 (defvar vc-menu-map (make-sparse-keymap "Version Control"))
1012 (define-key menu-bar-tools-menu [pcl-cvs]
1013 `(menu-item "PCL-CVS" ,cvs-global-menu
1014 :help "Module-level interface to CVS"))
1015 (define-key menu-bar-tools-menu [vc]
1016 (list 'menu-item "Version Control" vc-menu-map
1017 :help "Interface to RCS, CVS, SCCS"))
1018
1019 (define-key menu-bar-tools-menu [separator-compare]
1020 '("--"))
1021
1022 (define-key menu-bar-tools-menu [ediff-misc]
1023 '(menu-item "Ediff Miscellanea" menu-bar-ediff-misc-menu
1024 :help "Ediff manual, customization, sessions, etc."))
1025 (define-key menu-bar-tools-menu [epatch]
1026 '(menu-item "Apply Patch" menu-bar-epatch-menu))
1027 (define-key menu-bar-tools-menu [ediff-merge]
1028 '(menu-item "Merge" menu-bar-ediff-merge-menu
1029 :help "Merge different revisions of files/directories"))
1030 (define-key menu-bar-tools-menu [compare]
1031 '(menu-item "Compare (Ediff)" menu-bar-ediff-menu
1032 :help "Display differences between files/directories"))
1033
1034
1035 (define-key menu-bar-tools-menu [separator-spell]
1036 '("--"))
1037
1038 (define-key menu-bar-tools-menu [spell]
1039 '(menu-item "Spell Checking" ispell-menu-map))
1040
1041 (define-key menu-bar-tools-menu [separator-prog]
1042 '("--"))
1043
1044 (define-key menu-bar-tools-menu [gdb]
1045 '(menu-item "Debugger (GDB)..." gdb
1046 :help "Debug a program from within Emacs with GDB"))
1047 (define-key menu-bar-tools-menu [shell-on-region]
1048 '(menu-item "Shell Command on Region..." shell-command-on-region
1049 :enable mark-active
1050 :help "Pass marked region to a shell command"))
1051 (define-key menu-bar-tools-menu [shell]
1052 '(menu-item "Shell Command..." shell-command
1053 :help "Invoke a shell command and catch its output"))
1054 (define-key menu-bar-tools-menu [compile]
1055 '(menu-item "Compile..." compile
1056 :help "Invoke compiler or Make, view compilation errors"))
1057 (define-key menu-bar-tools-menu [grep]
1058 '(menu-item "Search Files (Grep)..." grep
1059 :help "Search files for strings or regexps (with Grep)"))
1060
1061 \f
1062 ;; The "Help" menu items
1063
1064 (defvar menu-bar-describe-menu (make-sparse-keymap "Describe"))
1065
1066 (define-key menu-bar-describe-menu [mule-diag]
1067 '(menu-item "Show All of Mule Status" mule-diag
1068 :visible default-enable-multibyte-characters
1069 :help "Display multilingual environment settings"))
1070 (define-key menu-bar-describe-menu [describe-coding-system-briefly]
1071 '(menu-item "Describe Coding System (Briefly)..."
1072 describe-current-coding-system-briefly
1073 :visible default-enable-multibyte-characters))
1074 (define-key menu-bar-describe-menu [describe-coding-system]
1075 '(menu-item "Describe Coding System..." describe-coding-system
1076 :visible default-enable-multibyte-characters))
1077 (define-key menu-bar-describe-menu [describe-input-method]
1078 '(menu-item "Describe Input Method..." describe-input-method
1079 :visible default-enable-multibyte-characters
1080 :help "Keyboard layout for specific input method"))
1081 (define-key menu-bar-describe-menu [describe-language-environment]
1082 (list 'menu-item "Describe Language Environment"
1083 describe-language-environment-map
1084 :help "Show multilingual settings for a specific language"))
1085
1086 (define-key menu-bar-describe-menu [separator-desc-mule]
1087 '("--"))
1088
1089 (define-key menu-bar-describe-menu [list-keybindings]
1090 '(menu-item "List Key Bindings" describe-bindings
1091 :help "Display a list of all current keybindings"))
1092 (define-key menu-bar-describe-menu [describe-current-display-table]
1093 '(menu-item "Describe Display Table" describe-current-display-table
1094 :help "Describe the current display table"))
1095 (define-key menu-bar-describe-menu [describe-face]
1096 '(menu-item "Describe Face..." describe-face
1097 :help "Display the properties of a face"))
1098 (define-key menu-bar-describe-menu [describe-variable]
1099 '(menu-item "Describe Variable..." describe-variable
1100 :help "Display documentation of variable/option"))
1101 (define-key menu-bar-describe-menu [describe-function]
1102 '(menu-item "Describe Function..." describe-function
1103 :help "Display documentation of function/command"))
1104 (define-key menu-bar-describe-menu [describe-key]
1105 '(menu-item "Describe Key..." describe-key
1106 ;; Users typically don't identify keys and menu items...
1107 :help "Display documentation of command bound to a \
1108 key (or menu-item)"))
1109 (define-key menu-bar-describe-menu [describe-mode]
1110 '(menu-item "Describe Buffer Modes" describe-mode
1111 :help "Describe this buffer's major and minor mode"))
1112
1113 (defvar menu-bar-apropos-menu (make-sparse-keymap "Apropos"))
1114 (defun menu-bar-read-lispref ()
1115 "Display the Emacs Lisp Reference manual in Info mode."
1116 (interactive)
1117 (info "elisp"))
1118
1119 (defun menu-bar-read-lispintro ()
1120 "Display the Introduction to Emacs Lisp Programming in Info mode."
1121 (interactive)
1122 (info "eintr"))
1123
1124 (defun menu-bar-read-emacs-man ()
1125 "Display Emacs User Manual in Info mode."
1126 (interactive)
1127 (info "emacs"))
1128
1129 (defun search-emacs-glossary ()
1130 "Display the Glossary node of the Emacs manual in Info mode."
1131 (interactive)
1132 (info "(emacs)Glossary"))
1133
1134 (defun emacs-index-search (topic)
1135 "Look up TOPIC in the indices of the Emacs User Manual."
1136 (interactive "sSubject to look up: ")
1137 (info "emacs")
1138 (Info-index topic))
1139
1140 (defun elisp-index-search (topic)
1141 "Look up TOPIC in the indices of the Emacs Lisp Reference Manual."
1142 (interactive "sSubject to look up: ")
1143 (info "elisp")
1144 (Info-index topic))
1145
1146 (define-key menu-bar-apropos-menu [apropos-documentation]
1147 '(menu-item "Search Documentation Strings..." apropos-documentation
1148 :help
1149 "Find functions and variables whose doc strings match a regexp"))
1150 (define-key menu-bar-apropos-menu [apropos]
1151 '(menu-item "Find Any Object by Name..." apropos
1152 :help "Find symbols of any kind whose names match a regexp"))
1153 (define-key menu-bar-apropos-menu [apropos-value]
1154 '(menu-item "Find Options by Value..." apropos-value
1155 :help "Find variables whose values match a regexp"))
1156 (define-key menu-bar-apropos-menu [apropos-variables]
1157 '(menu-item "Find Options by Name..." apropos-variable
1158 :help "Find variables whose names match a regexp"))
1159 (define-key menu-bar-apropos-menu [apropos-commands]
1160 '(menu-item "Find Commands by Name..." apropos-command
1161 :help "Find commands whose names match a regexp"))
1162 (define-key menu-bar-apropos-menu [sep1]
1163 '("--"))
1164 (define-key menu-bar-apropos-menu [elisp-index-search]
1165 '(menu-item "Look Up Subject in ELisp Manual..." elisp-index-search
1166 :help "Find description of a subject in Emacs Lisp manual"))
1167 (define-key menu-bar-apropos-menu [emacs-index-search]
1168 '(menu-item "Look Up Subject in User Manual..." emacs-index-search
1169 :help "Find description of a subject in Emacs User manual"))
1170 (define-key menu-bar-apropos-menu [emacs-glossary]
1171 '(menu-item "Emacs Terminology" search-emacs-glossary
1172 :help "Display the Glossary section of the Emacs manual"))
1173
1174 (defvar menu-bar-manuals-menu (make-sparse-keymap "More Manuals"))
1175
1176 (define-key menu-bar-manuals-menu [man]
1177 '(menu-item "Read Man Page..." manual-entry
1178 :help "Man-page docs for external commands and libraries"))
1179 (define-key menu-bar-manuals-menu [sep2]
1180 '("--"))
1181 (define-key menu-bar-manuals-menu [order-emacs-manuals]
1182 '(menu-item "Ordering Manuals" view-order-manuals
1183 :help "How to order manuals from the Free Software Foundation"))
1184 (define-key menu-bar-manuals-menu [info]
1185 '(menu-item "All Other Manuals (Info)" Info-directory
1186 :help "Read any of the installed manuals"))
1187 (define-key menu-bar-manuals-menu [info-elisp]
1188 '(menu-item "Emacs Lisp Reference" menu-bar-read-lispref
1189 :help "Read the Emacs Lisp Reference manual"))
1190 (define-key menu-bar-manuals-menu [info-elintro]
1191 '(menu-item "Introduction to Emacs Lisp" menu-bar-read-lispintro
1192 :help "Read the Introduction to Emacs Lisp Programming"))
1193 (define-key menu-bar-manuals-menu [sep3]
1194 '("--"))
1195 (define-key menu-bar-manuals-menu [command]
1196 '(menu-item "Find Command in Manual" Info-goto-emacs-command-node
1197 :help "Display manual section that describes a command"))
1198 (define-key menu-bar-manuals-menu [key]
1199 '(menu-item "Find Key in Manual" Info-goto-emacs-key-command-node
1200 :help "Display manual section that describes a key"))
1201
1202 (define-key menu-bar-help-menu [eliza]
1203 '(menu-item "Emacs Psychiatrist" doctor
1204 :help "Our doctor will help you feel better"))
1205 (define-key menu-bar-help-menu [sep4]
1206 '("--"))
1207 (define-key menu-bar-help-menu [describe-no-warranty]
1208 '(menu-item "(Non)Warranty" describe-no-warranty
1209 :help "Explain that Emacs has NO WARRANTY"))
1210 (define-key menu-bar-help-menu [describe-copying]
1211 '(menu-item "Copying Conditions" describe-copying
1212 :help "Show the Emacs license (GPL)"))
1213 (define-key menu-bar-help-menu [describe-distribution]
1214 '(menu-item "Getting New Versions" describe-distribution
1215 :help "How to get latest versions of Emacs"))
1216 (define-key menu-bar-help-menu [more]
1217 '(menu-item "Find Extra Packages"
1218 (lambda ()
1219 (interactive)
1220 (let (enable-local-variables)
1221 (view-file (expand-file-name "MORE.STUFF"
1222 data-directory))
1223 (goto-address)))
1224 :help "Where to find some extra packages and possible updates"))
1225 (define-key menu-bar-help-menu [about]
1226 '(menu-item "About Emacs" display-splash-screen
1227 :help "Display version number, copyright info, and basic help"))
1228 (define-key menu-bar-help-menu [sep2]
1229 '("--"))
1230 (define-key menu-bar-help-menu [finder-by-keyword]
1231 '(menu-item "Find Emacs Packages..." finder-by-keyword
1232 :help "Find packages and features by keyword"))
1233 (define-key menu-bar-help-menu [manuals]
1234 (list 'menu-item "More Manuals" menu-bar-manuals-menu
1235 :help "Search and browse on-line manuals"))
1236 (define-key menu-bar-help-menu [emacs-manual]
1237 '(menu-item "Read the Emacs Manual" menu-bar-read-emacs-man
1238 :help "Full documentation of Emacs features"))
1239 (define-key menu-bar-help-menu [describe]
1240 (list 'menu-item "Describe" menu-bar-describe-menu
1241 :help "Describe commands, variables, keys"))
1242 (define-key menu-bar-help-menu [apropos]
1243 (list 'menu-item "Search Documentation" menu-bar-apropos-menu
1244 :help "Look up terms, find commands, options, etc. (Apropos)"))
1245 (define-key menu-bar-help-menu [sep1]
1246 '("--"))
1247 (define-key menu-bar-help-menu [report-emacs-bug]
1248 '(menu-item "Send Bug Report..." report-emacs-bug
1249 :help "Send e-mail to Emacs maintainers"))
1250 (define-key menu-bar-help-menu [emacs-problems]
1251 '(menu-item "Emacs Known Problems" view-emacs-problems))
1252 (define-key menu-bar-help-menu [emacs-news]
1253 '(menu-item "Emacs News" view-emacs-news
1254 :help "New features of this version"))
1255 (define-key menu-bar-help-menu [emacs-faq]
1256 '(menu-item "Emacs FAQ" view-emacs-FAQ))
1257 (define-key menu-bar-help-menu [emacs-tutorial-language-specific]
1258 '(menu-item "Emacs Tutorial (choose language)..."
1259 (lambda () (interactive) (help-with-tutorial t))
1260 :help "Learn how to use Emacs (choose a language)"))
1261 (define-key menu-bar-help-menu [emacs-tutorial]
1262 '(menu-item "Emacs Tutorial" help-with-tutorial
1263 :help "Learn how to use Emacs"))
1264
1265 (defun kill-this-buffer () ; for the menubar
1266 "Kill the current buffer."
1267 (interactive)
1268 (kill-buffer (current-buffer)))
1269
1270 (defun kill-this-buffer-enabled-p ()
1271 (let ((count 0)
1272 (buffers (buffer-list)))
1273 (while buffers
1274 (or (string-match "^ " (buffer-name (car buffers)))
1275 (setq count (1+ count)))
1276 (setq buffers (cdr buffers)))
1277 (and (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1278 (> count 1))))
1279
1280 (put 'dired 'menu-enable
1281 '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
1282
1283 ;; Permit deleting frame if it would leave a visible or iconified frame.
1284 (defun delete-frame-enabled-p ()
1285 "Return non-nil if `delete-frame' should be enabled in the menu bar."
1286 (let ((frames (frame-list))
1287 (count 0))
1288 (while frames
1289 (if (frame-visible-p (car frames))
1290 (setq count (1+ count)))
1291 (setq frames (cdr frames)))
1292 (> count 1)))
1293
1294 (defcustom yank-menu-length 20
1295 "*Maximum length to display in the yank-menu."
1296 :type 'integer
1297 :group 'mouse)
1298
1299 (defun menu-bar-update-yank-menu (string old)
1300 (let ((front (car (cdr yank-menu)))
1301 (menu-string (if (<= (length string) yank-menu-length)
1302 string
1303 (concat
1304 (substring string 0 (/ yank-menu-length 2))
1305 "..."
1306 (substring string (- (/ yank-menu-length 2)))))))
1307 ;; Don't let the menu string be all dashes
1308 ;; because that has a special meaning in a menu.
1309 (if (string-match "\\`-+\\'" menu-string)
1310 (setq menu-string (concat menu-string " ")))
1311 ;; If we're supposed to be extending an existing string, and that
1312 ;; string really is at the front of the menu, then update it in place.
1313 (if (and old (or (eq old (car front))
1314 (string= old (car front))))
1315 (progn
1316 (setcar front string)
1317 (setcar (cdr front) menu-string))
1318 (setcdr yank-menu
1319 (cons
1320 (cons string (cons menu-string 'menu-bar-select-yank))
1321 (cdr yank-menu)))))
1322 (if (> (length (cdr yank-menu)) kill-ring-max)
1323 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
1324
1325 (put 'menu-bar-select-yank 'apropos-inhibit t)
1326 (defun menu-bar-select-yank ()
1327 (interactive "*")
1328 (push-mark (point))
1329 (insert last-command-event))
1330
1331 \f
1332 (defcustom buffers-menu-show-directories 'unless-uniquify
1333 "If non-nil, show directories in the Buffers menu for buffers that have them.
1334 The special value `unless-uniquify' means that directories will be shown
1335 unless `uniquify-buffer-name-style' is non-nil (in which case, buffer
1336 names should include enough of a buffer's directory to distinguish it
1337 from other buffers).
1338
1339 Setting this variable directly does not take effect until next time the
1340 Buffers menu is regenerated."
1341 :set (lambda (symbol value)
1342 (set symbol value)
1343 (menu-bar-update-buffers t))
1344 :initialize 'custom-initialize-default
1345 :type '(choice (const :tag "Never" nil)
1346 (const :tag "Unless uniquify is enabled" unless-uniquify)
1347 (const :tag "Always" t))
1348 :group 'menu)
1349
1350 (defcustom buffers-menu-show-status t
1351 "If non-nil, show modified/read-only status of buffers in the Buffers menu.
1352 Setting this variable directly does not take effect until next time the
1353 Buffers menu is regenerated."
1354 :set (lambda (symbol value)
1355 (set symbol value)
1356 (menu-bar-update-buffers t))
1357 :initialize 'custom-initialize-default
1358 :type 'boolean
1359 :group 'menu)
1360
1361 (defvar list-buffers-directory nil)
1362
1363 (defvar menu-bar-update-buffers-maxbuf)
1364
1365 (defun menu-bar-select-buffer ()
1366 (interactive)
1367 (switch-to-buffer last-command-event))
1368
1369 (defun menu-bar-select-frame ()
1370 (interactive)
1371 (let (frame)
1372 (dolist (f (frame-list))
1373 (when (equal last-command-event (frame-parameter f 'name))
1374 (setq frame f)))
1375 (make-frame-visible frame)
1376 (raise-frame frame)
1377 (select-frame frame)))
1378
1379 (defun menu-bar-update-buffers-1 (elt)
1380 (let* ((buf (car elt))
1381 (file
1382 (and (if (eq buffers-menu-show-directories 'unless-uniquify)
1383 (or (not (boundp 'uniquify-buffer-name-style))
1384 (null uniquify-buffer-name-style))
1385 buffers-menu-show-directories)
1386 (or (buffer-file-name buf)
1387 (buffer-local-value 'list-buffers-directory buf)))))
1388 (when file
1389 (setq file (file-name-directory file)))
1390 (when (and file (> (length file) 20))
1391 (setq file (concat "..." (substring file -17))))
1392 (cons (if buffers-menu-show-status
1393 (let ((mod (if (buffer-modified-p buf) "*" ""))
1394 (ro (if (buffer-local-value 'buffer-read-only buf) "%" "")))
1395 (if file
1396 (format "%s %s%s -- %s" (cdr elt) mod ro file)
1397 (format "%s %s%s" (cdr elt) mod ro)))
1398 (if file
1399 (format "%s -- %s" (cdr elt) file)
1400 (cdr elt)))
1401 buf)))
1402
1403 ;; Used to cache the menu entries for commands in the Buffers menu
1404 (defvar menu-bar-buffers-menu-command-entries nil)
1405
1406 (defun menu-bar-update-buffers (&optional force)
1407 ;; If user discards the Buffers item, play along.
1408 (and (lookup-key (current-global-map) [menu-bar buffer])
1409 (or force (frame-or-buffer-changed-p))
1410 (let ((buffers (buffer-list))
1411 (frames (frame-list))
1412 buffers-menu frames-menu)
1413 ;; If requested, list only the N most recently selected buffers.
1414 (if (and (integerp buffers-menu-max-size)
1415 (> buffers-menu-max-size 1))
1416 (if (> (length buffers) buffers-menu-max-size)
1417 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
1418
1419 ;; Make the menu of buffers proper.
1420 (setq buffers-menu
1421 (let* ((buffer-list
1422 (mapcar 'list buffers))
1423 (menu-bar-update-buffers-maxbuf 0)
1424 alist)
1425 ;; Put into each element of buffer-list
1426 ;; the name for actual display,
1427 ;; perhaps truncated in the middle.
1428 (dolist (buf buffer-list)
1429 (let ((name (buffer-name (car buf))))
1430 (setcdr buf
1431 (if (> (length name) 27)
1432 (concat (substring name 0 12)
1433 "..."
1434 (substring name -12))
1435 name))))
1436 ;; Compute the maximum length of any name.
1437 (dolist (buf buffer-list)
1438 (unless (eq ?\ (aref (cdr buf) 0))
1439 (setq menu-bar-update-buffers-maxbuf
1440 (max menu-bar-update-buffers-maxbuf
1441 (length (cdr buf))))))
1442 ;; Set ALIST to an alist of the form
1443 ;; ITEM-STRING . BUFFER
1444 (dolist (buf buffer-list)
1445 (unless (eq ?\ (aref (cdr buf) 0))
1446 (push (menu-bar-update-buffers-1 buf) alist)))
1447 ;; Now make the actual list of items, and add
1448 ;; some miscellaneous buffer commands to the end.
1449 (mapcar (lambda (pair)
1450 ;; This is somewhat risque, to use
1451 ;; the buffer name itself as the event
1452 ;; type to define, but it works.
1453 ;; It would not work to use the buffer
1454 ;; since a buffer as an event has its
1455 ;; own meaning.
1456 (nconc (list (buffer-name (cdr pair))
1457 (car pair)
1458 (cons nil nil))
1459 'menu-bar-select-buffer))
1460 (nreverse alist))))
1461
1462 ;; Make a Frames menu if we have more than one frame.
1463 (when (cdr frames)
1464 (let ((frames-menu
1465 (cons 'keymap
1466 (cons "Select Frame"
1467 (mapcar
1468 (lambda (frame)
1469 (nconc
1470 (list (frame-parameter frame 'name)
1471 (frame-parameter frame 'name)
1472 (cons nil nil))
1473 'menu-bar-select-frame))
1474 frames)))))
1475 ;; Put it after the normal buffers
1476 (setq buffers-menu
1477 (nconc buffers-menu
1478 `((frames-separator "--")
1479 (frames menu-item "Frames" ,frames-menu))))))
1480
1481 ;; Add in some normal commands at the end of the menu. We use
1482 ;; the copy cached in `menu-bar-buffers-menu-command-entries'
1483 ;; if it's been set already. Note that we can't use constant
1484 ;; lists for the menu-entries, because the low-level menu-code
1485 ;; modifies them.
1486 (unless menu-bar-buffers-menu-command-entries
1487 (setq menu-bar-buffers-menu-command-entries
1488 (list '(command-separator "--")
1489 (list 'next-buffer
1490 'menu-item
1491 "Next Buffer"
1492 'next-buffer
1493 :help "Switch to the \"next\" buffer in a cyclic order")
1494 (list 'prev-buffer
1495 'menu-item
1496 "Previous Buffer"
1497 'prev-buffer
1498 :help "Switch to the \"previous\" buffer in a cyclic order")
1499 (list 'select-named-buffer
1500 'menu-item
1501 "Select Named Buffer..."
1502 'switch-to-buffer
1503 :help "Prompt for a buffer name, and select that buffer in the current window")
1504 (list 'list-all-buffers
1505 'menu-item
1506 "List All Buffers"
1507 'list-buffers
1508 :help "Pop up a window listing all emacs buffers"
1509 ))))
1510 (setq buffers-menu
1511 (nconc buffers-menu menu-bar-buffers-menu-command-entries))
1512
1513 (setq buffers-menu (cons 'keymap (cons "Select Buffer" buffers-menu)))
1514 (define-key (current-global-map) [menu-bar buffer]
1515 (cons "Buffers" buffers-menu)))))
1516
1517 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
1518
1519 (menu-bar-update-buffers)
1520
1521 ;; this version is too slow
1522 ;;;(defun format-buffers-menu-line (buffer)
1523 ;;; "Returns a string to represent the given buffer in the Buffer menu.
1524 ;;;nil means the buffer shouldn't be listed. You can redefine this."
1525 ;;; (if (string-match "\\` " (buffer-name buffer))
1526 ;;; nil
1527 ;;; (save-excursion
1528 ;;; (set-buffer buffer)
1529 ;;; (let ((size (buffer-size)))
1530 ;;; (format "%s%s %-19s %6s %-15s %s"
1531 ;;; (if (buffer-modified-p) "*" " ")
1532 ;;; (if buffer-read-only "%" " ")
1533 ;;; (buffer-name)
1534 ;;; size
1535 ;;; mode-name
1536 ;;; (or (buffer-file-name) ""))))))
1537 \f
1538 ;;; Set up a menu bar menu for the minibuffer.
1539
1540 (dolist (map (list minibuffer-local-map
1541 ;; This shouldn't be necessary, but there's a funny
1542 ;; bug in keymap.c that I don't understand yet. -stef
1543 minibuffer-local-completion-map))
1544 (define-key map [menu-bar minibuf]
1545 (cons "Minibuf" (make-sparse-keymap "Minibuf"))))
1546
1547 (let ((map minibuffer-local-completion-map))
1548 (define-key map [menu-bar minibuf ?\?]
1549 (list 'menu-item "List Completions" 'minibuffer-completion-help
1550 :help "Display all possible completions"))
1551 (define-key map [menu-bar minibuf space]
1552 (list 'menu-item "Complete Word" 'minibuffer-complete-word
1553 :help "Complete at most one word"))
1554 (define-key map [menu-bar minibuf tab]
1555 (list 'menu-item "Complete" 'minibuffer-complete
1556 :help "Complete as far as possible")))
1557
1558 (let ((map minibuffer-local-map))
1559 (define-key map [menu-bar minibuf quit]
1560 (list 'menu-item "Quit" 'keyboard-escape-quit
1561 :help "Abort input and exit minibuffer"))
1562 (define-key map [menu-bar minibuf return]
1563 (list 'menu-item "Enter" 'exit-minibuffer
1564 :help "Terminate input and exit minibuffer")))
1565 \f
1566 (defcustom menu-bar-mode t
1567 "Toggle display of a menu bar on each frame.
1568 Setting this variable directly does not take effect;
1569 use either \\[customize] or the function `menu-bar-mode'."
1570 :set (lambda (symbol value)
1571 (menu-bar-mode (or value 0)))
1572 :initialize 'custom-initialize-default
1573 :type 'boolean
1574 :group 'frames)
1575
1576 (defun menu-bar-mode (&optional flag)
1577 "Toggle display of a menu bar on each frame.
1578 This command applies to all frames that exist and frames to be
1579 created in the future.
1580 With a numeric argument, if the argument is positive,
1581 turn on menu bars; otherwise, turn off menu bars."
1582 (interactive "P")
1583
1584 ;; Make menu-bar-mode and default-frame-alist consistent.
1585 (let ((default (assq 'menu-bar-lines default-frame-alist)))
1586 (if default
1587 (setq menu-bar-mode (not (eq (cdr default) 0)))
1588 (setq default-frame-alist
1589 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
1590 default-frame-alist))))
1591
1592 ;; Toggle or set the mode, according to FLAG.
1593 (setq menu-bar-mode (if (null flag) (not menu-bar-mode)
1594 (> (prefix-numeric-value flag) 0)))
1595
1596 ;; Apply it to default-frame-alist.
1597 (let ((parameter (assq 'menu-bar-lines default-frame-alist)))
1598 (if (consp parameter)
1599 (setcdr parameter (if menu-bar-mode 1 0))
1600 (setq default-frame-alist
1601 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
1602 default-frame-alist))))
1603
1604 ;; Apply it to existing frames.
1605 (let ((frames (frame-list)))
1606 (while frames
1607 (let ((height (cdr (assq 'height (frame-parameters (car frames))))))
1608 (modify-frame-parameters (car frames)
1609 (list (cons 'menu-bar-lines
1610 (if menu-bar-mode 1 0))))
1611 (modify-frame-parameters (car frames)
1612 (list (cons 'height height))))
1613 (setq frames (cdr frames)))))
1614
1615 (provide 'menu-bar)
1616
1617 ;;; menu-bar.el ends here