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