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