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