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