Switch to recommended form of GPLv3 permissions notice.
[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
9a3558cb
DN
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
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"))
1096(define-key menu-bar-games-menu [tetris]
1097 '(menu-item "Tetris" tetris
1098 :help "Falling blocks game"))
1099(define-key menu-bar-games-menu [solitaire]
1100 '(menu-item "Solitaire" solitaire
1101 :help "Get rid of all the stones"))
1102(define-key menu-bar-games-menu [snake]
1103 '(menu-item "Snake" snake
1104 :help "Move snake around avoiding collisions"))
1105(define-key menu-bar-games-menu [pong]
1106 '(menu-item "Pong" pong
1107 :help "Bounce the ball to your opponent"))
1108(define-key menu-bar-games-menu [mult]
1109 '(menu-item "Multiplication Puzzle" mpuz
1110 :help "Exercise brain with multiplication"))
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)"))
1120(define-key menu-bar-games-menu [bubbles]
1121 '(menu-item "Bubbles" bubbles
1122 :help "Remove all bubbles using the fewest moves"))
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
bfeee9d1
DN
1133(defvar menu-bar-encryption-decryption-menu
1134 (make-sparse-keymap "Encryption/Decryption"))
1135
1136(define-key menu-bar-tools-menu [encryption-decryption]
1137 (list 'menu-item "Encryption/Decryption" menu-bar-encryption-decryption-menu))
1138
1139(define-key menu-bar-tools-menu [separator-encryption-decryption]
1140 '("--"))
1141
1142(define-key menu-bar-encryption-decryption-menu [insert-keys]
1143 '(menu-item "Insert Keys" epa-insert-keys
1144 :help "Insert public keys after the current point"))
1145
1146(define-key menu-bar-encryption-decryption-menu [export-keys]
1147 '(menu-item "Export Keys" epa-export-keys
1148 :help "Export public keys to a file"))
1149
1150(define-key menu-bar-encryption-decryption-menu [import-keys-region]
1151 '(menu-item "Import Keys from Region" epa-import-keys-region
1152 :help "Import public keys from the current region"))
1153
1154(define-key menu-bar-encryption-decryption-menu [import-keys]
9a3558cb 1155 '(menu-item "Import Keys from File..." epa-import-keys
bfeee9d1
DN
1156 :help "Import public keys from a file"))
1157
1158(define-key menu-bar-encryption-decryption-menu [list-keys]
1159 '(menu-item "List Keys" epa-list-keys
1160 :help "Browse your public keyring"))
1161
1162(define-key menu-bar-encryption-decryption-menu [separator-keys]
1163 '("--"))
1164
bfeee9d1
DN
1165(define-key menu-bar-encryption-decryption-menu [sign-region]
1166 '(menu-item "Sign Region" epa-sign-region
1167 :help "Create digital signature of the current region"))
1168
bfeee9d1
DN
1169(define-key menu-bar-encryption-decryption-menu [verify-region]
1170 '(menu-item "Verify Region" epa-verify-region
1171 :help "Verify digital signature of the current region"))
1172
9a3558cb
DN
1173(define-key menu-bar-encryption-decryption-menu [encrypt-region]
1174 '(menu-item "Encrypt Region" epa-encrypt-region
1175 :help "Encrypt the current region"))
bfeee9d1
DN
1176
1177(define-key menu-bar-encryption-decryption-menu [decrypt-region]
1178 '(menu-item "Decrypt Region" epa-decrypt-region
1179 :help "Decrypt the current region"))
1180
9a3558cb
DN
1181(define-key menu-bar-encryption-decryption-menu [separator-file]
1182 '("--"))
bfeee9d1 1183
9a3558cb
DN
1184(define-key menu-bar-encryption-decryption-menu [sign-file]
1185 '(menu-item "Sign File..." epa-sign-file
1186 :help "Create digital signature of a file"))
7f315c7c 1187
9a3558cb
DN
1188(define-key menu-bar-encryption-decryption-menu [verify-file]
1189 '(menu-item "Verify File..." epa-verify-file
1190 :help "Verify digital signature of a file"))
7f315c7c 1191
9a3558cb
DN
1192(define-key menu-bar-encryption-decryption-menu [encrypt-file]
1193 '(menu-item "Encrypt File..." epa-encrypt-file
1194 :help "Encrypt a file"))
7f315c7c 1195
9a3558cb
DN
1196(define-key menu-bar-encryption-decryption-menu [decrypt-file]
1197 '(menu-item "Decrypt File..." epa-decrypt-file
1198 :help "Decrypt a file"))
7f315c7c 1199
1edd6ac4
CW
1200(define-key menu-bar-tools-menu [simple-calculator]
1201 '(menu-item "Simple Calculator" calculator
1202 :help "Invoke the Emacs built-in quick calculator"))
1203(define-key menu-bar-tools-menu [calc]
1204 '(menu-item "Programmable Calculator" calc
1205 :help "Invoke the Emacs built-in full scientific calculator"))
506c6d61 1206(define-key menu-bar-tools-menu [calendar]
5ead5d5e
CY
1207 '(menu-item "Calendar" calendar
1208 :help "Invoke the Emacs built-in calendar"))
9a45aa3d
EZ
1209
1210(define-key menu-bar-tools-menu [separator-net]
1211 '("--"))
1212
7f315c7c 1213(define-key menu-bar-tools-menu [directory-search]
ad9f6125 1214 '(menu-item "Directory Search" eudc-tools-menu))
506c6d61 1215(define-key menu-bar-tools-menu [compose-mail]
e4ca8f8c
EZ
1216 (list
1217 'menu-item `(format "Send Mail (with %s)" (send-mail-item-name))
1218 'compose-mail
1219 :visible `(and mail-user-agent (not (eq mail-user-agent 'ignore)))
1220 :help "Send a mail message"))
506c6d61 1221(define-key menu-bar-tools-menu [rmail]
0a1f9f1d
EZ
1222 (list
1223 'menu-item `(format "Read Mail (with %s)" (read-mail-item-name))
277e0f9d 1224 'menu-bar-read-mail
e4ca8f8c 1225 :visible `(and read-mail-command (not (eq read-mail-command 'ignore)))
0a1f9f1d 1226 :help "Read your mail and reply to it"))
277e0f9d
RS
1227
1228(defun menu-bar-read-mail ()
724f328c 1229 "Read mail using `read-mail-command'."
277e0f9d
RS
1230 (interactive)
1231 (call-interactively read-mail-command))
1232
7f315c7c 1233(define-key menu-bar-tools-menu [gnus]
0a1f9f1d 1234 '(menu-item "Read Net News (Gnus)" gnus
7f315c7c
EZ
1235 :help "Read network news groups"))
1236
1237(define-key menu-bar-tools-menu [separator-vc]
1238 '("--"))
1239
eccd9bd5 1240(define-key menu-bar-tools-menu [pcl-cvs]
ad9f6125 1241 '(menu-item "PCL-CVS" cvs-global-menu))
dc172b73 1242(define-key menu-bar-tools-menu [vc] nil) ;Create the place for the VC menu.
7f315c7c
EZ
1243
1244(define-key menu-bar-tools-menu [separator-compare]
1245 '("--"))
1246
1247(define-key menu-bar-tools-menu [ediff-misc]
ad9f6125 1248 '(menu-item "Ediff Miscellanea" menu-bar-ediff-misc-menu))
7f315c7c
EZ
1249(define-key menu-bar-tools-menu [epatch]
1250 '(menu-item "Apply Patch" menu-bar-epatch-menu))
1251(define-key menu-bar-tools-menu [ediff-merge]
ad9f6125 1252 '(menu-item "Merge" menu-bar-ediff-merge-menu))
7f315c7c 1253(define-key menu-bar-tools-menu [compare]
ad9f6125 1254 '(menu-item "Compare (Ediff)" menu-bar-ediff-menu))
7f315c7c
EZ
1255
1256(define-key menu-bar-tools-menu [separator-spell]
1257 '("--"))
1258
1259(define-key menu-bar-tools-menu [spell]
1260 '(menu-item "Spell Checking" ispell-menu-map))
1261
1262(define-key menu-bar-tools-menu [separator-prog]
1263 '("--"))
1264
1265(define-key menu-bar-tools-menu [gdb]
39328775
RS
1266 '(menu-item "Debugger (GDB)..." gdb
1267 :help "Debug a program from within Emacs with GDB"))
7f315c7c
EZ
1268(define-key menu-bar-tools-menu [shell-on-region]
1269 '(menu-item "Shell Command on Region..." shell-command-on-region
1270 :enable mark-active
1271 :help "Pass marked region to a shell command"))
1272(define-key menu-bar-tools-menu [shell]
1273 '(menu-item "Shell Command..." shell-command
1274 :help "Invoke a shell command and catch its output"))
1275(define-key menu-bar-tools-menu [compile]
1276 '(menu-item "Compile..." compile
1277 :help "Invoke compiler or Make, view compilation errors"))
1278(define-key menu-bar-tools-menu [grep]
1b45944f
CY
1279 '(menu-item "Search Files (Grep)..." grep
1280 :help "Search files for strings or regexps (with Grep)"))
7f315c7c
EZ
1281
1282\f
1283;; The "Help" menu items
1284
e5683624
RS
1285(defvar menu-bar-describe-menu (make-sparse-keymap "Describe"))
1286
7f315c7c
EZ
1287(define-key menu-bar-describe-menu [mule-diag]
1288 '(menu-item "Show All of Mule Status" mule-diag
1289 :visible default-enable-multibyte-characters
1290 :help "Display multilingual environment settings"))
df5bde6d 1291(define-key menu-bar-describe-menu [describe-coding-system-briefly]
f5e0def7 1292 '(menu-item "Describe Coding System (Briefly)"
df5bde6d
SS
1293 describe-current-coding-system-briefly
1294 :visible default-enable-multibyte-characters))
7f315c7c
EZ
1295(define-key menu-bar-describe-menu [describe-coding-system]
1296 '(menu-item "Describe Coding System..." describe-coding-system
1297 :visible default-enable-multibyte-characters))
1298(define-key menu-bar-describe-menu [describe-input-method]
1299 '(menu-item "Describe Input Method..." describe-input-method
1300 :visible default-enable-multibyte-characters
1301 :help "Keyboard layout for specific input method"))
1302(define-key menu-bar-describe-menu [describe-language-environment]
506c6d61 1303 (list 'menu-item "Describe Language Environment"
ad9f6125 1304 describe-language-environment-map))
7f315c7c
EZ
1305
1306(define-key menu-bar-describe-menu [separator-desc-mule]
506c6d61 1307 '("--"))
7f315c7c
EZ
1308
1309(define-key menu-bar-describe-menu [list-keybindings]
1310 '(menu-item "List Key Bindings" describe-bindings
eeb935fd 1311 :help "Display all current keybindings (keyboard shortcuts)"))
df5bde6d
SS
1312(define-key menu-bar-describe-menu [describe-current-display-table]
1313 '(menu-item "Describe Display Table" describe-current-display-table
1314 :help "Describe the current display table"))
1315(define-key menu-bar-describe-menu [describe-face]
1316 '(menu-item "Describe Face..." describe-face
1317 :help "Display the properties of a face"))
e5683624 1318(define-key menu-bar-describe-menu [describe-variable]
7f315c7c
EZ
1319 '(menu-item "Describe Variable..." describe-variable
1320 :help "Display documentation of variable/option"))
e5683624 1321(define-key menu-bar-describe-menu [describe-function]
7f315c7c
EZ
1322 '(menu-item "Describe Function..." describe-function
1323 :help "Display documentation of function/command"))
686e63b3 1324(define-key menu-bar-describe-menu [describe-key-1]
c6a816df 1325 '(menu-item "Describe Key or Mouse Operation..." describe-key
506c6d61 1326 ;; Users typically don't identify keys and menu items...
686e63b3 1327 :help "Display documentation of command bound to a \
c6a816df 1328key, a click, or a menu-item"))
df5bde6d
SS
1329(define-key menu-bar-describe-menu [describe-mode]
1330 '(menu-item "Describe Buffer Modes" describe-mode
1331 :help "Describe this buffer's major and minor mode"))
1332
9f3bfa54
EZ
1333(defvar menu-bar-search-documentation-menu
1334 (make-sparse-keymap "Search Documentation"))
5275d6a8
EZ
1335(defun menu-bar-read-lispref ()
1336 "Display the Emacs Lisp Reference manual in Info mode."
1337 (interactive)
1338 (info "elisp"))
1339
1340(defun menu-bar-read-lispintro ()
1341 "Display the Introduction to Emacs Lisp Programming in Info mode."
1342 (interactive)
1343 (info "eintr"))
1344
5275d6a8
EZ
1345(defun search-emacs-glossary ()
1346 "Display the Glossary node of the Emacs manual in Info mode."
1347 (interactive)
1348 (info "(emacs)Glossary"))
1349
1350(defun emacs-index-search (topic)
1351 "Look up TOPIC in the indices of the Emacs User Manual."
1352 (interactive "sSubject to look up: ")
1353 (info "emacs")
1354 (Info-index topic))
1355
1356(defun elisp-index-search (topic)
1357 "Look up TOPIC in the indices of the Emacs Lisp Reference Manual."
1358 (interactive "sSubject to look up: ")
1359 (info "elisp")
1360 (Info-index topic))
df5bde6d 1361
9f3bfa54 1362(define-key menu-bar-search-documentation-menu [search-documentation-strings]
5275d6a8
EZ
1363 '(menu-item "Search Documentation Strings..." apropos-documentation
1364 :help
1365 "Find functions and variables whose doc strings match a regexp"))
9f3bfa54 1366(define-key menu-bar-search-documentation-menu [find-any-object-by-name]
5275d6a8
EZ
1367 '(menu-item "Find Any Object by Name..." apropos
1368 :help "Find symbols of any kind whose names match a regexp"))
9f3bfa54 1369(define-key menu-bar-search-documentation-menu [find-option-by-value]
5275d6a8
EZ
1370 '(menu-item "Find Options by Value..." apropos-value
1371 :help "Find variables whose values match a regexp"))
9f3bfa54 1372(define-key menu-bar-search-documentation-menu [find-options-by-name]
5275d6a8
EZ
1373 '(menu-item "Find Options by Name..." apropos-variable
1374 :help "Find variables whose names match a regexp"))
9f3bfa54 1375(define-key menu-bar-search-documentation-menu [find-commands-by-name]
5275d6a8
EZ
1376 '(menu-item "Find Commands by Name..." apropos-command
1377 :help "Find commands whose names match a regexp"))
9f3bfa54 1378(define-key menu-bar-search-documentation-menu [sep1]
5275d6a8 1379 '("--"))
9f3bfa54 1380(define-key menu-bar-search-documentation-menu [lookup-command-in-manual]
e7682d92
EZ
1381 '(menu-item "Look Up Command in User Manual..." Info-goto-emacs-command-node
1382 :help "Display manual section that describes a command"))
9f3bfa54 1383(define-key menu-bar-search-documentation-menu [lookup-key-in-manual]
e7682d92
EZ
1384 '(menu-item "Look Up Key in User Manual..." Info-goto-emacs-key-command-node
1385 :help "Display manual section that describes a key"))
9f3bfa54 1386(define-key menu-bar-search-documentation-menu [lookup-subject-in-elisp-manual]
5275d6a8
EZ
1387 '(menu-item "Look Up Subject in ELisp Manual..." elisp-index-search
1388 :help "Find description of a subject in Emacs Lisp manual"))
9f3bfa54 1389(define-key menu-bar-search-documentation-menu [lookup-subject-in-emacs-manual]
5275d6a8
EZ
1390 '(menu-item "Look Up Subject in User Manual..." emacs-index-search
1391 :help "Find description of a subject in Emacs User manual"))
9f3bfa54 1392(define-key menu-bar-search-documentation-menu [emacs-terminology]
5275d6a8
EZ
1393 '(menu-item "Emacs Terminology" search-emacs-glossary
1394 :help "Display the Glossary section of the Emacs manual"))
1395
1396(defvar menu-bar-manuals-menu (make-sparse-keymap "More Manuals"))
e5683624
RS
1397
1398(define-key menu-bar-manuals-menu [man]
7f315c7c
EZ
1399 '(menu-item "Read Man Page..." manual-entry
1400 :help "Man-page docs for external commands and libraries"))
e5683624
RS
1401(define-key menu-bar-manuals-menu [sep2]
1402 '("--"))
5275d6a8
EZ
1403(define-key menu-bar-manuals-menu [order-emacs-manuals]
1404 '(menu-item "Ordering Manuals" view-order-manuals
1405 :help "How to order manuals from the Free Software Foundation"))
9f3bfa54 1406(define-key menu-bar-manuals-menu [lookup-subject-in-all-manuals]
372ef0ab
EZ
1407 '(menu-item "Lookup Subject in all manuals..." info-apropos
1408 :help "Find description of a subject in all installed manuals"))
9f3bfa54 1409(define-key menu-bar-manuals-menu [other-manuals]
5275d6a8 1410 '(menu-item "All Other Manuals (Info)" Info-directory
7f315c7c 1411 :help "Read any of the installed manuals"))
9f3bfa54 1412(define-key menu-bar-manuals-menu [emacs-lisp-reference]
5275d6a8
EZ
1413 '(menu-item "Emacs Lisp Reference" menu-bar-read-lispref
1414 :help "Read the Emacs Lisp Reference manual"))
9f3bfa54 1415(define-key menu-bar-manuals-menu [emac-lisp-intro]
5275d6a8
EZ
1416 '(menu-item "Introduction to Emacs Lisp" menu-bar-read-lispintro
1417 :help "Read the Introduction to Emacs Lisp Programming"))
bacb2d12 1418
a064691f 1419(define-key menu-bar-help-menu [about-gnu-project]
ac1818b5 1420 '(menu-item "About GNU" describe-gnu-project
3a155dd6 1421 :help "About the GNU System, GNU Project, and GNU/Linux"))
a064691f 1422(define-key menu-bar-help-menu [about-emacs]
3a155dd6
JL
1423 '(menu-item "About Emacs" about-emacs
1424 :help "Display version number, copyright info, and basic help"))
5275d6a8 1425(define-key menu-bar-help-menu [sep4]
7f315c7c 1426 '("--"))
f3e1e0dd 1427(define-key menu-bar-help-menu [describe-no-warranty]
7f315c7c
EZ
1428 '(menu-item "(Non)Warranty" describe-no-warranty
1429 :help "Explain that Emacs has NO WARRANTY"))
f3e1e0dd 1430(define-key menu-bar-help-menu [describe-copying]
7f315c7c
EZ
1431 '(menu-item "Copying Conditions" describe-copying
1432 :help "Show the Emacs license (GPL)"))
9f3bfa54 1433(define-key menu-bar-help-menu [getting-new-versions]
7f315c7c
EZ
1434 '(menu-item "Getting New Versions" describe-distribution
1435 :help "How to get latest versions of Emacs"))
277e0f9d
RS
1436(defun menu-bar-help-extra-packages ()
1437 "Display help about some additional packages available for Emacs."
1438 (interactive)
1439 (let (enable-local-variables)
1440 (view-file (expand-file-name "MORE.STUFF"
1441 data-directory))
1442 (goto-address)))
e5683624
RS
1443(define-key menu-bar-help-menu [sep2]
1444 '("--"))
a064691f 1445(define-key menu-bar-help-menu [external-packages]
3a155dd6
JL
1446 '(menu-item "External Packages" menu-bar-help-extra-packages
1447 :help "Lisp packages distributed separately for use in Emacs"))
9f3bfa54 1448(define-key menu-bar-help-menu [find-emacs-packages]
bd649ca3 1449 '(menu-item "Find Emacs Packages" finder-by-keyword
7f315c7c 1450 :help "Find packages and features by keyword"))
9f3bfa54 1451(define-key menu-bar-help-menu [more-manuals]
ad9f6125 1452 (list 'menu-item "More Manuals" menu-bar-manuals-menu))
5275d6a8 1453(define-key menu-bar-help-menu [emacs-manual]
277e0f9d 1454 '(menu-item "Read the Emacs Manual" info-emacs-manual
5275d6a8 1455 :help "Full documentation of Emacs features"))
e5683624 1456(define-key menu-bar-help-menu [describe]
ad9f6125 1457 (list 'menu-item "Describe" menu-bar-describe-menu))
9f3bfa54
EZ
1458(define-key menu-bar-help-menu [search-documentation]
1459 (list 'menu-item "Search Documentation" menu-bar-search-documentation-menu))
e5683624
RS
1460(define-key menu-bar-help-menu [sep1]
1461 '("--"))
a064691f 1462(define-key menu-bar-help-menu [emacs-psychotherapist]
3a155dd6
JL
1463 '(menu-item "Emacs Psychotherapist" doctor
1464 :help "Our doctor will help you feel better"))
9f3bfa54 1465(define-key menu-bar-help-menu [send-emacs-bug-report]
7f315c7c
EZ
1466 '(menu-item "Send Bug Report..." report-emacs-bug
1467 :help "Send e-mail to Emacs maintainers"))
9f3bfa54 1468(define-key menu-bar-help-menu [emacs-known-problems]
5ead5d5e
CY
1469 '(menu-item "Emacs Known Problems" view-emacs-problems
1470 :help "Read about known problems with Emacs"))
7f315c7c
EZ
1471(define-key menu-bar-help-menu [emacs-news]
1472 '(menu-item "Emacs News" view-emacs-news
1473 :help "New features of this version"))
1474(define-key menu-bar-help-menu [emacs-faq]
5ead5d5e
CY
1475 '(menu-item "Emacs FAQ" view-emacs-FAQ
1476 :help "Frequently asked (and answered) questions about Emacs"))
277e0f9d
RS
1477
1478(defun help-with-tutorial-spec-language ()
1479 "Use the Emacs tutorial, specifying which language you want."
f1180544 1480 (interactive)
277e0f9d
RS
1481 (help-with-tutorial t))
1482
451ec4e3
GM
1483(define-key menu-bar-help-menu [emacs-tutorial-language-specific]
1484 '(menu-item "Emacs Tutorial (choose language)..."
277e0f9d 1485 help-with-tutorial-spec-language
451ec4e3 1486 :help "Learn how to use Emacs (choose a language)"))
7f315c7c
EZ
1487(define-key menu-bar-help-menu [emacs-tutorial]
1488 '(menu-item "Emacs Tutorial" help-with-tutorial
1489 :help "Learn how to use Emacs"))
889560ed 1490
92752c3a
EZ
1491(defun menu-bar-menu-frame-live-and-visible-p ()
1492 "Return non-nil if the menu frame is alive and visible.
1493The menu frame is the frame for which we are updating the menu."
55d42133 1494 (let ((menu-frame (or menu-updating-frame (selected-frame))))
92752c3a
EZ
1495 (and (frame-live-p menu-frame)
1496 (frame-visible-p menu-frame))))
1497
1498(defun menu-bar-non-minibuffer-window-p ()
1499 "Return non-nil if selected window of the menu frame is not a minibuf window.
1500
1501See the documentation of `menu-bar-menu-frame-live-and-visible-p'
1502for the definition of the menu frame."
55d42133 1503 (let ((menu-frame (or menu-updating-frame (selected-frame))))
92752c3a
EZ
1504 (not (window-minibuffer-p (frame-selected-window menu-frame)))))
1505
6eee5abf 1506(defun kill-this-buffer () ; for the menu bar
a86b330f
JL
1507 "Kill the current buffer.
1508When called in the minibuffer, get out of the minibuffer
1509using `abort-recursive-edit'."
db774a16 1510 (interactive)
a86b330f
JL
1511 (if (menu-bar-non-minibuffer-window-p)
1512 (kill-buffer (current-buffer))
1513 (abort-recursive-edit)))
db774a16 1514
2f1139a4
RS
1515(defun kill-this-buffer-enabled-p ()
1516 (let ((count 0)
1517 (buffers (buffer-list)))
1518 (while buffers
1519 (or (string-match "^ " (buffer-name (car buffers)))
1520 (setq count (1+ count)))
1521 (setq buffers (cdr buffers)))
a86b330f
JL
1522 (or (not (menu-bar-non-minibuffer-window-p))
1523 (> count 1))))
1f50590a 1524
92752c3a 1525(put 'dired 'menu-enable '(menu-bar-non-minibuffer-window-p))
1f50590a 1526
a0213a97 1527;; Permit deleting frame if it would leave a visible or iconified frame.
82a74107
KH
1528(defun delete-frame-enabled-p ()
1529 "Return non-nil if `delete-frame' should be enabled in the menu bar."
1530 (let ((frames (frame-list))
27aa8132
RS
1531 (count 0))
1532 (while frames
1533 (if (frame-visible-p (car frames))
1534 (setq count (1+ count)))
1535 (setq frames (cdr frames)))
1536 (> count 1)))
2f1139a4 1537
30e19aee
RS
1538(defcustom yank-menu-length 20
1539 "*Maximum length to display in the yank-menu."
1540 :type 'integer
d3434a5b 1541 :group 'menu)
3dd92899
KH
1542
1543(defun menu-bar-update-yank-menu (string old)
1544 (let ((front (car (cdr yank-menu)))
1545 (menu-string (if (<= (length string) yank-menu-length)
1546 string
c3e1d435
RS
1547 (concat
1548 (substring string 0 (/ yank-menu-length 2))
1549 "..."
1550 (substring string (- (/ yank-menu-length 2)))))))
7c70a955
RS
1551 ;; Don't let the menu string be all dashes
1552 ;; because that has a special meaning in a menu.
1553 (if (string-match "\\`-+\\'" menu-string)
1554 (setq menu-string (concat menu-string " ")))
3dd92899
KH
1555 ;; If we're supposed to be extending an existing string, and that
1556 ;; string really is at the front of the menu, then update it in place.
1557 (if (and old (or (eq old (car front))
1558 (string= old (car front))))
dfabc98f 1559 (progn
3dd92899
KH
1560 (setcar front string)
1561 (setcar (cdr front) menu-string))
1562 (setcdr yank-menu
1563 (cons
1564 (cons string (cons menu-string 'menu-bar-select-yank))
1565 (cdr yank-menu)))))
1566 (if (> (length (cdr yank-menu)) kill-ring-max)
1567 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
1568
4cca6fbd 1569(put 'menu-bar-select-yank 'apropos-inhibit t)
3dd92899 1570(defun menu-bar-select-yank ()
5fb64ecc
EZ
1571 "Insert the stretch of previously-killed text selected from menu.
1572The menu shows all the killed text sequences stored in `kill-ring'."
3dd92899
KH
1573 (interactive "*")
1574 (push-mark (point))
1575 (insert last-command-event))
68310f2a 1576
40954111 1577\f
d3434a5b
JL
1578;;; Buffers Menu
1579
1580(defcustom buffers-menu-max-size 10
1581 "*Maximum number of entries which may appear on the Buffers menu.
1582If this is 10, then only the ten most-recently-selected buffers are shown.
1583If this is nil, then all buffers are shown.
1584A large number or nil slows down menu responsiveness."
1585 :type '(choice integer
1586 (const :tag "All" nil))
1587 :group 'menu)
1588
1589(defcustom buffers-menu-buffer-name-length 30
1590 "*Maximum length of the buffer name on the Buffers menu.
1591If this is a number, then buffer names are truncated to this length.
1592If this is nil, then buffer names are shown in full.
1593A large number or nil makes the menu too wide."
1594 :type '(choice integer
1595 (const :tag "Full length" nil))
1596 :group 'menu)
1597
68310f2a
MB
1598(defcustom buffers-menu-show-directories 'unless-uniquify
1599 "If non-nil, show directories in the Buffers menu for buffers that have them.
1600The special value `unless-uniquify' means that directories will be shown
1601unless `uniquify-buffer-name-style' is non-nil (in which case, buffer
1602names should include enough of a buffer's directory to distinguish it
1603from other buffers).
1604
1605Setting this variable directly does not take effect until next time the
1606Buffers menu is regenerated."
1607 :set (lambda (symbol value)
1608 (set symbol value)
1609 (menu-bar-update-buffers t))
1610 :initialize 'custom-initialize-default
1611 :type '(choice (const :tag "Never" nil)
1612 (const :tag "Unless uniquify is enabled" unless-uniquify)
1613 (const :tag "Always" t))
1614 :group 'menu)
1615
1616(defcustom buffers-menu-show-status t
1617 "If non-nil, show modified/read-only status of buffers in the Buffers menu.
1618Setting this variable directly does not take effect until next time the
1619Buffers menu is regenerated."
1620 :set (lambda (symbol value)
1621 (set symbol value)
1622 (menu-bar-update-buffers t))
1623 :initialize 'custom-initialize-default
1624 :type 'boolean
1625 :group 'menu)
1626
d0690d12
RS
1627(defvar list-buffers-directory nil)
1628
ed10603b
SM
1629(defun menu-bar-select-frame (frame)
1630 (make-frame-visible frame)
1631 (raise-frame frame)
1632 (select-frame frame))
09642d97 1633
c171b42f 1634(defun menu-bar-update-buffers-1 (elt)
68703c11
MB
1635 (let* ((buf (car elt))
1636 (file
68310f2a
MB
1637 (and (if (eq buffers-menu-show-directories 'unless-uniquify)
1638 (or (not (boundp 'uniquify-buffer-name-style))
1639 (null uniquify-buffer-name-style))
1640 buffers-menu-show-directories)
68703c11 1641 (or (buffer-file-name buf)
68310f2a 1642 (buffer-local-value 'list-buffers-directory buf)))))
68703c11
MB
1643 (when file
1644 (setq file (file-name-directory file)))
1645 (when (and file (> (length file) 20))
1646 (setq file (concat "..." (substring file -17))))
68310f2a
MB
1647 (cons (if buffers-menu-show-status
1648 (let ((mod (if (buffer-modified-p buf) "*" ""))
1649 (ro (if (buffer-local-value 'buffer-read-only buf) "%" "")))
1650 (if file
1651 (format "%s %s%s -- %s" (cdr elt) mod ro file)
1652 (format "%s %s%s" (cdr elt) mod ro)))
1653 (if file
1654 (format "%s -- %s" (cdr elt) file)
1655 (cdr elt)))
68703c11
MB
1656 buf)))
1657
887d3c94
MB
1658;; Used to cache the menu entries for commands in the Buffers menu
1659(defvar menu-bar-buffers-menu-command-entries nil)
1660
ee1dbceb 1661(defun menu-bar-update-buffers (&optional force)
29397c58 1662 ;; If user discards the Buffers item, play along.
4d587a6c 1663 (and (lookup-key (current-global-map) [menu-bar buffer])
ee1dbceb 1664 (or force (frame-or-buffer-changed-p))
29397c58
RS
1665 (let ((buffers (buffer-list))
1666 (frames (frame-list))
bf902855 1667 buffers-menu)
29397c58
RS
1668 ;; If requested, list only the N most recently selected buffers.
1669 (if (and (integerp buffers-menu-max-size)
1670 (> buffers-menu-max-size 1))
1671 (if (> (length buffers) buffers-menu-max-size)
1672 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
1673
1674 ;; Make the menu of buffers proper.
1675 (setq buffers-menu
ed10603b 1676 (let (alist)
8b621d39
MB
1677 ;; Put into each element of buffer-list
1678 ;; the name for actual display,
1679 ;; perhaps truncated in the middle.
ed10603b
SM
1680 (dolist (buf buffers)
1681 (let ((name (buffer-name buf)))
1682 (unless (eq ?\s (aref name 0))
1683 (push (menu-bar-update-buffers-1
1684 (cons buf
d3434a5b
JL
1685 (if (and (integerp buffers-menu-buffer-name-length)
1686 (> (length name) buffers-menu-buffer-name-length))
1687 (concat
1688 (substring
1689 name 0 (/ buffers-menu-buffer-name-length 2))
1690 "..."
1691 (substring
1692 name (- (/ buffers-menu-buffer-name-length 2))))
1693 name)
1694 ))
ed10603b
SM
1695 alist))))
1696 ;; Now make the actual list of items.
1697 (let ((buffers-vec (make-vector (length alist) nil))
1698 (i (length alist)))
1699 (dolist (pair alist)
1700 (setq i (1- i))
1701 (aset buffers-vec i
1702 (nconc (list (car pair)
8b621d39 1703 (cons nil nil))
ed10603b
SM
1704 `(lambda ()
1705 (interactive)
1706 (switch-to-buffer ,(cdr pair))))))
1707 (list buffers-vec))))
29397c58
RS
1708
1709 ;; Make a Frames menu if we have more than one frame.
8b621d39 1710 (when (cdr frames)
ed10603b
SM
1711 (let* ((frames-vec (make-vector (length frames) nil))
1712 (frames-menu
1713 (cons 'keymap
1714 (list "Select Frame" frames-vec)))
1715 (i 0))
1716 (dolist (frame frames)
1717 (aset frames-vec i
1718 (nconc
1719 (list
1720 (frame-parameter frame 'name)
1721 (cons nil nil))
1722 `(lambda ()
1723 (interactive) (menu-bar-select-frame ,frame))))
1724 (setq i (1+ i)))
8b621d39
MB
1725 ;; Put it after the normal buffers
1726 (setq buffers-menu
1727 (nconc buffers-menu
1728 `((frames-separator "--")
1729 (frames menu-item "Frames" ,frames-menu))))))
1730
887d3c94
MB
1731 ;; Add in some normal commands at the end of the menu. We use
1732 ;; the copy cached in `menu-bar-buffers-menu-command-entries'
1733 ;; if it's been set already. Note that we can't use constant
1734 ;; lists for the menu-entries, because the low-level menu-code
1735 ;; modifies them.
1736 (unless menu-bar-buffers-menu-command-entries
1737 (setq menu-bar-buffers-menu-command-entries
1738 (list '(command-separator "--")
332b907c
RS
1739 (list 'next-buffer
1740 'menu-item
1741 "Next Buffer"
1742 'next-buffer
1743 :help "Switch to the \"next\" buffer in a cyclic order")
a74f9094 1744 (list 'previous-buffer
332b907c
RS
1745 'menu-item
1746 "Previous Buffer"
a74f9094 1747 'previous-buffer
332b907c 1748 :help "Switch to the \"previous\" buffer in a cyclic order")
887d3c94
MB
1749 (list 'select-named-buffer
1750 'menu-item
1751 "Select Named Buffer..."
1752 'switch-to-buffer
1753 :help "Prompt for a buffer name, and select that buffer in the current window")
1754 (list 'list-all-buffers
1755 'menu-item
1756 "List All Buffers"
1757 'list-buffers
4f00f90f 1758 :help "Pop up a window listing all Emacs buffers"
887d3c94 1759 ))))
8b621d39 1760 (setq buffers-menu
887d3c94 1761 (nconc buffers-menu menu-bar-buffers-menu-command-entries))
8b621d39 1762
bf902855
SM
1763 ;; We used to "(define-key (current-global-map) [menu-bar buffer]"
1764 ;; but that did not do the right thing when the [menu-bar buffer]
1765 ;; entry above had been moved (e.g. to a parent keymap).
1766 (setcdr global-buffers-menu-map (cons "Select Buffer" buffers-menu)))))
09642d97
RS
1767
1768(add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
2f1139a4 1769
3f557298
RS
1770(menu-bar-update-buffers)
1771
40954111 1772;; this version is too slow
a9d96061
SM
1773;;(defun format-buffers-menu-line (buffer)
1774;; "Returns a string to represent the given buffer in the Buffer menu.
1775;;nil means the buffer shouldn't be listed. You can redefine this."
1776;; (if (string-match "\\` " (buffer-name buffer))
1777;; nil
1778;; (save-excursion
1779;; (set-buffer buffer)
1780;; (let ((size (buffer-size)))
1781;; (format "%s%s %-19s %6s %-15s %s"
1782;; (if (buffer-modified-p) "*" " ")
1783;; (if buffer-read-only "%" " ")
1784;; (buffer-name)
1785;; size
1786;; mode-name
1787;; (or (buffer-file-name) ""))))))
40954111 1788\f
25b048ee
RS
1789;;; Set up a menu bar menu for the minibuffer.
1790
32993295
SM
1791(dolist (map (list minibuffer-local-map
1792 ;; This shouldn't be necessary, but there's a funny
1793 ;; bug in keymap.c that I don't understand yet. -stef
d918e2dc
SM
1794 minibuffer-local-completion-map))
1795 (define-key map [menu-bar minibuf]
1796 (cons "Minibuf" (make-sparse-keymap "Minibuf"))))
1797
32993295 1798(let ((map minibuffer-local-completion-map))
d918e2dc
SM
1799 (define-key map [menu-bar minibuf ?\?]
1800 (list 'menu-item "List Completions" 'minibuffer-completion-help
1801 :help "Display all possible completions"))
1802 (define-key map [menu-bar minibuf space]
1803 (list 'menu-item "Complete Word" 'minibuffer-complete-word
1804 :help "Complete at most one word"))
1805 (define-key map [menu-bar minibuf tab]
1806 (list 'menu-item "Complete" 'minibuffer-complete
1807 :help "Complete as far as possible")))
1808
32993295 1809(let ((map minibuffer-local-map))
d918e2dc 1810 (define-key map [menu-bar minibuf quit]
94e73757 1811 (list 'menu-item "Quit" 'abort-recursive-edit
d918e2dc
SM
1812 :help "Abort input and exit minibuffer"))
1813 (define-key map [menu-bar minibuf return]
1814 (list 'menu-item "Enter" 'exit-minibuffer
94e73757 1815 :key-sequence "\r"
56a8f9c5
JL
1816 :help "Terminate input and exit minibuffer"))
1817 (define-key map [menu-bar minibuf isearch-forward]
1818 (list 'menu-item "Isearch History Forward" 'isearch-forward
1819 :help "Incrementally search minibuffer history forward"))
1820 (define-key map [menu-bar minibuf isearch-backward]
1821 (list 'menu-item "Isearch History Backward" 'isearch-backward
1822 :help "Incrementally search minibuffer history backward"))
1823 (define-key map [menu-bar minibuf next]
1824 (list 'menu-item "Next History Item" 'next-history-element
1825 :help "Put next minibuffer history element in the minibuffer"))
1826 (define-key map [menu-bar minibuf previous]
1827 (list 'menu-item "Previous History Item" 'previous-history-element
1828 :help "Put previous minibuffer history element in the minibuffer")))
25b048ee 1829\f
8ab9589d 1830;;;###autoload
ffda926c 1831;; This comment is taken from tool-bar.el near
8ab9589d
JD
1832;; (put 'tool-bar-mode ...)
1833;; We want to pretend the menu bar by standard is on, as this will make
1834;; customize consider disabling the menu bar a customization, and save
1835;; that. We could do this for real by setting :init-value below, but
1836;; that would overwrite disabling the tool bar from X resources.
1837(put 'menu-bar-mode 'standard-value '(t))
1838
8ab9589d 1839(define-minor-mode menu-bar-mode
dfd29450 1840 "Toggle display of a menu bar on each frame.
057d49d1
RS
1841This command applies to all frames that exist and frames to be
1842created in the future.
e1d18ad8
RS
1843With a numeric argument, if the argument is positive,
1844turn on menu bars; otherwise, turn off menu bars."
8ab9589d
JD
1845 :init-value nil
1846 :global t
1847 :group 'frames
095fe281 1848
7b7d6615 1849 ;; Make menu-bar-mode and default-frame-alist consistent.
095fe281
KL
1850 (modify-all-frames-parameters (list (cons 'menu-bar-lines
1851 (if menu-bar-mode 1 0))))
8ab9589d
JD
1852
1853 ;; Make the message appear when Emacs is idle. We can not call message
1854 ;; directly. The minor-mode message "Menu-bar mode disabled" comes
1855 ;; after this function returns, overwriting any message we do here.
1856 (when (and (interactive-p) (not menu-bar-mode))
1857 (run-with-idle-timer 0 nil 'message
1858 "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear."))
09bfa5ca 1859 menu-bar-mode)
1db87953 1860
6a5af08f
KL
1861(defun toggle-menu-bar-mode-from-frame (&optional arg)
1862 "Toggle menu bar on or off, based on the status of the current frame.
1863See `menu-bar-mode' for more information."
1864 (interactive (list (or current-prefix-arg 'toggle)))
1865 (if (eq arg 'toggle)
1866 (menu-bar-mode (if (> (frame-parameter nil 'menu-bar-lines) 0) 0 1))
1867 (menu-bar-mode arg)))
1868
f464330b
JB
1869(declare-function x-menu-bar-open "term/x-win" (&optional frame))
1870
14ab3a40
KL
1871(defun menu-bar-open (&optional frame)
1872 "Start key navigation of the menu bar in FRAME.
1873
1874This function decides which method to use to access the menu
1875depending on FRAME's terminal device. On X displays, it calls
1876`x-menu-bar-open'; otherwise it calls `tmm-menubar'.
1877
1878If FRAME is nil or not given, use the selected frame."
1879 (interactive)
1880 (if (eq window-system 'x)
1881 (x-menu-bar-open frame)
1882 (with-selected-frame (or frame (selected-frame))
1883 (tmm-menubar))))
1884
1885(global-set-key [f10] 'menu-bar-open)
1886
bffa5d4d
RS
1887(provide 'menu-bar)
1888
bf902855 1889;; arch-tag: 6e6a3c22-4ec4-4d3d-8190-583f8ef94ced
235aa29b 1890;;; menu-bar.el ends here