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