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