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