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