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