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