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