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