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