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