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