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