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