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