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