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