Fix bug #1077 with popping new frames from a minibuffer-only frame.
[emacs.git] / lisp / menu-bar.el
blob4708c52e12ede51a44a92ada025e49462892548d
1 ;;; menu-bar.el --- define a default menu bar
3 ;; Copyright (C) 1993, 1994, 1995, 2000, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: RMS
7 ;; Maintainer: FSF
8 ;; Keywords: internal, mouse
9 ;; Package: emacs
11 ;; This file is part of GNU Emacs.
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.
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.
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/>.
26 ;; Avishai Yacobi suggested some menu rearrangements.
28 ;;; Commentary:
30 ;;; Code:
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"))
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"))))
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)))
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))
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)))
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")
89 ;; This is referenced by some code below; it is defined in uniquify.el
90 (defvar uniquify-buffer-name-style)
92 ;; From emulation/cua-base.el; used below
93 (defvar cua-enable-cua-keys)
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")))
101 (define-key menu-bar-file-menu [separator-exit]
102 menu-bar-separator)
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")))
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")))
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")))
131 (define-key menu-bar-file-menu [separator-window]
132 menu-bar-separator)
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")))
159 (define-key menu-bar-file-menu [separator-print]
160 menu-bar-separator)
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)
170 (concat "\\`"
171 (regexp-quote
172 (file-name-nondirectory
173 auto-save-list-file-prefix)))
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")))
197 (define-key menu-bar-file-menu [separator-save]
198 menu-bar-separator)
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))))
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")))
233 ;; The "Edit" menu items
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.")
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)))
250 (error "No previous search"))))
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)))
263 (error "No previous search"))))
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)))
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)))
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)))
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)))
301 (defvar menu-bar-search-menu (make-sparse-keymap "Search"))
303 ;; The Edit->Search->Incremental Search menu
304 (defvar menu-bar-i-search-menu
305 (make-sparse-keymap "Incremental Search"))
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")))
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)
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)
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)
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")))
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")))
365 ;; The Edit->Replace submenu
367 (defvar menu-bar-replace-menu (make-sparse-keymap "Replace"))
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)
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")))
387 ;;; Assemble the top-level Edit menu items.
388 (define-key menu-bar-edit-menu [props]
389 `(menu-item ,(purecopy "Text Properties") facemenu-menu))
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)))
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")))
402 (define-key menu-bar-edit-menu [separator-bookmark]
403 menu-bar-separator)
405 (define-key menu-bar-edit-menu [bookmark]
406 `(menu-item ,(purecopy "Bookmarks") menu-bar-bookmark-map))
408 (defvar menu-bar-goto-menu (make-sparse-keymap "Go To"))
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")))
414 (define-key menu-bar-goto-menu [separator-tag-file]
415 menu-bar-separator)
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")))
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))
432 (defun menu-bar-next-tag ()
433 "Find the next definition of the tag already specified."
434 (interactive)
435 (find-tag nil t))
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")))
450 (define-key menu-bar-goto-menu [separator-tags]
451 menu-bar-separator)
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")))
464 (define-key menu-bar-edit-menu [goto]
465 `(menu-item ,(purecopy "Go To") ,menu-bar-goto-menu))
467 (define-key menu-bar-edit-menu [replace]
468 `(menu-item ,(purecopy "Replace") ,menu-bar-replace-menu))
470 (define-key menu-bar-edit-menu [search]
471 `(menu-item ,(purecopy "Search") ,menu-bar-search-menu))
473 (define-key menu-bar-edit-menu [separator-search]
474 menu-bar-separator)
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 (not (mouse-region-match)))
484 :help
485 ,(purecopy "Delete the text in region between mark and current position")))
486 (defvar yank-menu (cons (purecopy "Select Yank") nil))
487 (fset 'yank-menu (cons 'keymap yank-menu))
488 (define-key menu-bar-edit-menu (if (featurep 'ns) [select-paste]
489 [paste-from-menu])
490 ;; ns-win.el said: Change text to be more consistent with
491 ;; surrounding menu items `paste', etc."
492 `(menu-item ,(purecopy (if (featurep 'ns) "Select and Paste"
493 "Paste from Kill Menu")) yank-menu
494 :enable (and (cdr yank-menu) (not buffer-read-only))
495 :help ,(purecopy "Choose a string from the kill ring and paste it")))
496 (define-key menu-bar-edit-menu [paste]
497 `(menu-item ,(purecopy "Paste") yank
498 :enable (and (or
499 ;; Emacs compiled --without-x (or --with-ns)
500 ;; doesn't have x-selection-exists-p.
501 (and (fboundp 'x-selection-exists-p)
502 (x-selection-exists-p 'CLIPBOARD))
503 (if (featurep 'ns) ; like paste-from-menu
504 (cdr yank-menu)
505 kill-ring))
506 (not buffer-read-only))
507 :help ,(purecopy "Paste (yank) text most recently cut/copied")))
508 (define-key menu-bar-edit-menu [copy]
509 ;; ns-win.el said: Substitute a Copy function that works better
510 ;; under X (for GNUstep).
511 `(menu-item ,(purecopy "Copy") ,(if (featurep 'ns)
512 'ns-copy-including-secondary
513 'menu-bar-kill-ring-save)
514 :enable mark-active
515 :help ,(purecopy "Copy text in region between mark and current position")
516 :keys ,(purecopy (if (featurep 'ns)
517 "\\[ns-copy-including-secondary]"
518 "\\[kill-ring-save]"))))
519 (define-key menu-bar-edit-menu [cut]
520 `(menu-item ,(purecopy "Cut") kill-region
521 :enable (and mark-active (not buffer-read-only))
522 :help
523 ,(purecopy "Cut (kill) text in region between mark and current position")))
524 ;; ns-win.el said: Separate undo from cut/paste section.
525 (if (featurep 'ns)
526 (define-key menu-bar-edit-menu [separator-undo] `(,(purecopy "--"))))
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")))
536 (defun menu-bar-kill-ring-save (beg end)
537 (interactive "r")
538 (if (mouse-region-match)
539 (message "Selecting a region with the mouse does `copy' automatically")
540 (kill-ring-save beg end)))
542 ;; These are alternative definitions for the cut, paste and copy
543 ;; menu items. Use them if your system expects these to use the clipboard.
545 (put 'clipboard-kill-region 'menu-enable
546 '(and mark-active (not buffer-read-only)))
547 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
548 (put 'clipboard-yank 'menu-enable
549 '(and (or (not (fboundp 'x-selection-exists-p))
550 (x-selection-exists-p)
551 (x-selection-exists-p 'CLIPBOARD))
552 (not buffer-read-only)))
554 (defun clipboard-yank ()
555 "Insert the clipboard contents, or the last stretch of killed text."
556 (interactive "*")
557 (let ((x-select-enable-clipboard t))
558 (yank)))
560 (defun clipboard-kill-ring-save (beg end)
561 "Copy region to kill ring, and save in the X clipboard."
562 (interactive "r")
563 (let ((x-select-enable-clipboard t))
564 (kill-ring-save beg end)))
566 (defun clipboard-kill-region (beg end)
567 "Kill the region, and save it in the X clipboard."
568 (interactive "r")
569 (let ((x-select-enable-clipboard t))
570 (kill-region beg end)))
572 (defun menu-bar-enable-clipboard ()
573 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
574 Do the same for the keys of the same name."
575 (interactive)
576 ;; These are Sun server keysyms for the Cut, Copy and Paste keys
577 ;; (also for XFree86 on Sun keyboard):
578 (define-key global-map [f20] 'clipboard-kill-region)
579 (define-key global-map [f16] 'clipboard-kill-ring-save)
580 (define-key global-map [f18] 'clipboard-yank)
581 ;; X11R6 versions:
582 (define-key global-map [cut] 'clipboard-kill-region)
583 (define-key global-map [copy] 'clipboard-kill-ring-save)
584 (define-key global-map [paste] 'clipboard-yank))
586 ;; The "Options" menu items
588 (defvar menu-bar-custom-menu (make-sparse-keymap "Customize"))
590 (define-key menu-bar-custom-menu [customize-apropos-groups]
591 `(menu-item ,(purecopy "Groups Matching Regexp...") customize-apropos-groups
592 :help ,(purecopy "Browse groups whose names match regexp")))
593 (define-key menu-bar-custom-menu [customize-apropos-faces]
594 `(menu-item ,(purecopy "Faces Matching Regexp...") customize-apropos-faces
595 :help ,(purecopy "Browse faces whose names match regexp")))
596 (define-key menu-bar-custom-menu [customize-apropos-options]
597 `(menu-item ,(purecopy "Options Matching Regexp...") customize-apropos-options
598 :help ,(purecopy "Browse options whose names match regexp")))
599 (define-key menu-bar-custom-menu [customize-apropos]
600 `(menu-item ,(purecopy "Settings Matching Regexp...") customize-apropos
601 :help ,(purecopy "Browse customizable settings whose names match regexp")))
602 (define-key menu-bar-custom-menu [separator-1]
603 menu-bar-separator)
604 (define-key menu-bar-custom-menu [customize-group]
605 `(menu-item ,(purecopy "Specific Group...") customize-group
606 :help ,(purecopy "Customize settings of specific group")))
607 (define-key menu-bar-custom-menu [customize-face]
608 `(menu-item ,(purecopy "Specific Face...") customize-face
609 :help ,(purecopy "Customize attributes of specific face")))
610 (define-key menu-bar-custom-menu [customize-option]
611 `(menu-item ,(purecopy "Specific Option...") customize-option
612 :help ,(purecopy "Customize value of specific option")))
613 (define-key menu-bar-custom-menu [separator-2]
614 menu-bar-separator)
615 (define-key menu-bar-custom-menu [customize-changed-options]
616 `(menu-item ,(purecopy "New Options...") customize-changed-options
617 :help ,(purecopy "Options added or changed in recent Emacs versions")))
618 (define-key menu-bar-custom-menu [customize-saved]
619 `(menu-item ,(purecopy "Saved Options") customize-saved
620 :help ,(purecopy "Customize previously saved options")))
621 (define-key menu-bar-custom-menu [separator-3]
622 menu-bar-separator)
623 (define-key menu-bar-custom-menu [customize-browse]
624 `(menu-item ,(purecopy "Browse Customization Groups") customize-browse
625 :help ,(purecopy "Browse all customization groups")))
626 (define-key menu-bar-custom-menu [customize]
627 `(menu-item ,(purecopy "Top-level Customization Group") customize
628 :help ,(purecopy "The master group called `Emacs'")))
630 ;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
632 (defmacro menu-bar-make-mm-toggle (fname doc help &optional props)
633 "Make a menu-item for a global minor mode toggle.
634 FNAME is the minor mode's name (variable and function).
635 DOC is the text to use for the menu entry.
636 HELP is the text to use for the tooltip.
637 PROPS are additional properties."
638 `(list 'menu-item (purecopy ,doc) ',fname
639 ,@(mapcar (lambda (p) (list 'quote p)) props)
640 :help (purecopy ,help)
641 :button '(:toggle . (and (default-boundp ',fname)
642 (default-value ',fname)))))
644 (defmacro menu-bar-make-toggle (name variable doc message help &rest body)
645 `(progn
646 (defun ,name (&optional interactively)
647 ,(concat "Toggle whether to " (downcase (substring help 0 1))
648 (substring help 1) ".
649 In an interactive call, record this option as a candidate for saving
650 by \"Save Options\" in Custom buffers.")
651 (interactive "p")
652 (if ,(if body `(progn . ,body)
653 `(progn
654 (custom-load-symbol ',variable)
655 (let ((set (or (get ',variable 'custom-set) 'set-default))
656 (get (or (get ',variable 'custom-get) 'default-value)))
657 (funcall set ',variable (not (funcall get ',variable))))))
658 (message ,message "enabled globally")
659 (message ,message "disabled globally"))
660 ;; The function `customize-mark-as-set' must only be called when
661 ;; a variable is set interactively, as the purpose is to mark it as
662 ;; a candidate for "Save Options", and we do not want to save options
663 ;; the user have already set explicitly in his init file.
664 (if interactively (customize-mark-as-set ',variable)))
665 (list 'menu-item (purecopy ,doc) ',name
666 :help (purecopy ,help)
667 :button '(:toggle . (and (default-boundp ',variable)
668 (default-value ',variable))))))
670 ;; Function for setting/saving default font.
672 (defun menu-set-font ()
673 "Interactively select a font and make it the default."
674 (interactive)
675 (let ((font (if (fboundp 'x-select-font)
676 (x-select-font)
677 (mouse-select-font)))
678 spec)
679 (when font
680 ;; Be careful here: when set-face-attribute is called for the
681 ;; :font attribute, Emacs tries to guess the best matching font
682 ;; by examining the other face attributes (Bug#2476).
683 (set-face-attribute 'default (selected-frame)
684 :width 'normal
685 :weight 'normal
686 :slant 'normal
687 :font font)
688 (let ((font-object (face-attribute 'default :font)))
689 (dolist (f (frame-list))
690 (and (not (eq f (selected-frame)))
691 (display-graphic-p f)
692 (set-face-attribute 'default f :font font-object)))
693 (set-face-attribute 'default t :font font-object))
694 (setq spec (list (list t (face-attr-construct 'default))))
695 (put 'default 'customized-face spec)
696 (custom-push-theme 'theme-face 'default 'user 'set spec)
697 (put 'default 'face-modified nil))))
701 ;;; Assemble all the top-level items of the "Options" menu
702 (define-key menu-bar-options-menu [customize]
703 `(menu-item ,(purecopy "Customize Emacs") ,menu-bar-custom-menu))
705 (defun menu-bar-options-save ()
706 "Save current values of Options menu items using Custom."
707 (interactive)
708 (let ((need-save nil))
709 ;; These are set with menu-bar-make-mm-toggle, which does not
710 ;; put on a customized-value property.
711 (dolist (elt '(line-number-mode column-number-mode size-indication-mode
712 cua-mode show-paren-mode transient-mark-mode
713 blink-cursor-mode display-time-mode display-battery-mode
714 ;; These are set by other functions that don't set
715 ;; the customized state. Having them here has the
716 ;; side-effect that turning them off via X
717 ;; resources acts like having customized them, but
718 ;; that seems harmless.
719 menu-bar-mode tool-bar-mode))
720 ;; FIXME ? It's a little annoying that running this command
721 ;; always loads cua-base, paren, time, and battery, even if they
722 ;; have not been customized in any way. (Due to custom-load-symbol.)
723 (and (customize-mark-to-save elt)
724 (setq need-save t)))
725 ;; These are set with `customize-set-variable'.
726 (dolist (elt '(scroll-bar-mode
727 debug-on-quit debug-on-error
728 ;; Somehow this works, when tool-bar and menu-bar don't.
729 tooltip-mode
730 save-place uniquify-buffer-name-style fringe-mode
731 indicate-empty-lines indicate-buffer-boundaries
732 case-fold-search font-use-system-font
733 current-language-environment default-input-method
734 ;; Saving `text-mode-hook' is somewhat questionable,
735 ;; as we might get more than we bargain for, if
736 ;; other code may has added hooks as well.
737 ;; Nonetheless, not saving it would like be confuse
738 ;; more often.
739 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
740 text-mode-hook tool-bar-position))
741 (and (get elt 'customized-value)
742 (customize-mark-to-save elt)
743 (setq need-save t)))
744 (when (get 'default 'customized-face)
745 (put 'default 'saved-face (get 'default 'customized-face))
746 (put 'default 'customized-face nil)
747 (setq need-save t))
748 ;; Save if we changed anything.
749 (when need-save
750 (custom-save-all))))
752 (define-key menu-bar-options-menu [package]
753 '(menu-item "Manage Emacs Packages" package-list-packages
754 :help "Install or uninstall additional Emacs packages"))
756 (define-key menu-bar-options-menu [save]
757 `(menu-item ,(purecopy "Save Options") menu-bar-options-save
758 :help ,(purecopy "Save options set from the menu above")))
760 (define-key menu-bar-options-menu [custom-separator]
761 menu-bar-separator)
763 (define-key menu-bar-options-menu [menu-set-font]
764 `(menu-item ,(purecopy "Set Default Font...") menu-set-font
765 :visible (display-multi-font-p)
766 :help ,(purecopy "Select a default font")))
768 (if (featurep 'system-font-setting)
769 (define-key menu-bar-options-menu [menu-system-font]
770 (menu-bar-make-toggle toggle-use-system-font font-use-system-font
771 "Use system font"
772 "Use system font: %s"
773 "Use the monospaced font defined by the system")))
776 ;; The "Show/Hide" submenu of menu "Options"
778 (defvar menu-bar-showhide-menu (make-sparse-keymap "Show/Hide"))
780 (define-key menu-bar-showhide-menu [column-number-mode]
781 (menu-bar-make-mm-toggle column-number-mode
782 "Column Numbers"
783 "Show the current column number in the mode line"))
785 (define-key menu-bar-showhide-menu [line-number-mode]
786 (menu-bar-make-mm-toggle line-number-mode
787 "Line Numbers"
788 "Show the current line number in the mode line"))
790 (define-key menu-bar-showhide-menu [size-indication-mode]
791 (menu-bar-make-mm-toggle size-indication-mode
792 "Size Indication"
793 "Show the size of the buffer in the mode line"))
795 (define-key menu-bar-showhide-menu [linecolumn-separator]
796 menu-bar-separator)
798 (define-key menu-bar-showhide-menu [showhide-battery]
799 (menu-bar-make-mm-toggle display-battery-mode
800 "Battery Status"
801 "Display battery status information in mode line"))
803 (define-key menu-bar-showhide-menu [showhide-date-time]
804 (menu-bar-make-mm-toggle display-time-mode
805 "Time, Load and Mail"
806 "Display time, system load averages and \
807 mail status in mode line"))
809 (define-key menu-bar-showhide-menu [datetime-separator]
810 menu-bar-separator)
812 (define-key menu-bar-showhide-menu [showhide-speedbar]
813 `(menu-item ,(purecopy "Speedbar") speedbar-frame-mode
814 :help ,(purecopy "Display a Speedbar quick-navigation frame")
815 :button (:toggle
816 . (and (boundp 'speedbar-frame)
817 (frame-live-p (symbol-value 'speedbar-frame))
818 (frame-visible-p
819 (symbol-value 'speedbar-frame))))))
821 (defvar menu-bar-showhide-fringe-menu (make-sparse-keymap "Fringe"))
823 (defvar menu-bar-showhide-fringe-ind-menu
824 (make-sparse-keymap "Buffer boundaries"))
826 (defun menu-bar-showhide-fringe-ind-customize ()
827 "Show customization buffer for `indicate-buffer-boundaries'."
828 (interactive)
829 (customize-variable 'indicate-buffer-boundaries))
831 (define-key menu-bar-showhide-fringe-ind-menu [customize]
832 `(menu-item ,(purecopy "Other (Customize)")
833 menu-bar-showhide-fringe-ind-customize
834 :help ,(purecopy "Additional choices available through Custom buffer")
835 :visible (display-graphic-p)
836 :button (:radio . (not (member indicate-buffer-boundaries
837 '(nil left right
838 ((top . left) (bottom . right))
839 ((t . right) (top . left))))))))
841 (defun menu-bar-showhide-fringe-ind-mixed ()
842 "Display top and bottom indicators in opposite fringes, arrows in right."
843 (interactive)
844 (customize-set-variable 'indicate-buffer-boundaries
845 '((t . right) (top . left))))
847 (define-key menu-bar-showhide-fringe-ind-menu [mixed]
848 `(menu-item ,(purecopy "Opposite, Arrows Right") menu-bar-showhide-fringe-ind-mixed
849 :help
850 ,(purecopy "Show top/bottom indicators in opposite fringes, arrows in right")
851 :visible (display-graphic-p)
852 :button (:radio . (equal indicate-buffer-boundaries
853 '((t . right) (top . left))))))
855 (defun menu-bar-showhide-fringe-ind-box ()
856 "Display top and bottom indicators in opposite fringes."
857 (interactive)
858 (customize-set-variable 'indicate-buffer-boundaries
859 '((top . left) (bottom . right))))
861 (define-key menu-bar-showhide-fringe-ind-menu [box]
862 `(menu-item ,(purecopy "Opposite, No Arrows") menu-bar-showhide-fringe-ind-box
863 :help ,(purecopy "Show top/bottom indicators in opposite fringes, no arrows")
864 :visible (display-graphic-p)
865 :button (:radio . (equal indicate-buffer-boundaries
866 '((top . left) (bottom . right))))))
868 (defun menu-bar-showhide-fringe-ind-right ()
869 "Display buffer boundaries and arrows in the right fringe."
870 (interactive)
871 (customize-set-variable 'indicate-buffer-boundaries 'right))
873 (define-key menu-bar-showhide-fringe-ind-menu [right]
874 `(menu-item ,(purecopy "In Right Fringe") menu-bar-showhide-fringe-ind-right
875 :help ,(purecopy "Show buffer boundaries and arrows in right fringe")
876 :visible (display-graphic-p)
877 :button (:radio . (eq indicate-buffer-boundaries 'right))))
879 (defun menu-bar-showhide-fringe-ind-left ()
880 "Display buffer boundaries and arrows in the left fringe."
881 (interactive)
882 (customize-set-variable 'indicate-buffer-boundaries 'left))
884 (define-key menu-bar-showhide-fringe-ind-menu [left]
885 `(menu-item ,(purecopy "In Left Fringe") menu-bar-showhide-fringe-ind-left
886 :help ,(purecopy "Show buffer boundaries and arrows in left fringe")
887 :visible (display-graphic-p)
888 :button (:radio . (eq indicate-buffer-boundaries 'left))))
890 (defun menu-bar-showhide-fringe-ind-none ()
891 "Do not display any buffer boundary indicators."
892 (interactive)
893 (customize-set-variable 'indicate-buffer-boundaries nil))
895 (define-key menu-bar-showhide-fringe-ind-menu [none]
896 `(menu-item ,(purecopy "No Indicators") menu-bar-showhide-fringe-ind-none
897 :help ,(purecopy "Hide all buffer boundary indicators and arrows")
898 :visible (display-graphic-p)
899 :button (:radio . (eq indicate-buffer-boundaries nil))))
901 (define-key menu-bar-showhide-fringe-menu [showhide-fringe-ind]
902 `(menu-item ,(purecopy "Buffer Boundaries") ,menu-bar-showhide-fringe-ind-menu
903 :visible (display-graphic-p)
904 :help ,(purecopy "Indicate buffer boundaries in fringe")))
906 (define-key menu-bar-showhide-fringe-menu [indicate-empty-lines]
907 (menu-bar-make-toggle toggle-indicate-empty-lines indicate-empty-lines
908 "Empty Line Indicators"
909 "Indicating of empty lines %s"
910 "Indicate trailing empty lines in fringe, globally"))
912 (defun menu-bar-showhide-fringe-menu-customize ()
913 "Show customization buffer for `fringe-mode'."
914 (interactive)
915 (customize-variable 'fringe-mode))
917 (define-key menu-bar-showhide-fringe-menu [customize]
918 `(menu-item ,(purecopy "Customize Fringe") menu-bar-showhide-fringe-menu-customize
919 :help ,(purecopy "Detailed customization of fringe")
920 :visible (display-graphic-p)))
922 (defun menu-bar-showhide-fringe-menu-customize-reset ()
923 "Reset the fringe mode: display fringes on both sides of a window."
924 (interactive)
925 (customize-set-variable 'fringe-mode nil))
927 (define-key menu-bar-showhide-fringe-menu [default]
928 `(menu-item ,(purecopy "Default") menu-bar-showhide-fringe-menu-customize-reset
929 :help ,(purecopy "Default width fringe on both left and right side")
930 :visible (display-graphic-p)
931 :button (:radio . (eq fringe-mode nil))))
933 (defun menu-bar-showhide-fringe-menu-customize-right ()
934 "Display fringes only on the right of each window."
935 (interactive)
936 (require 'fringe)
937 (customize-set-variable 'fringe-mode '(0 . nil)))
939 (define-key menu-bar-showhide-fringe-menu [right]
940 `(menu-item ,(purecopy "On the Right") menu-bar-showhide-fringe-menu-customize-right
941 :help ,(purecopy "Fringe only on the right side")
942 :visible (display-graphic-p)
943 :button (:radio . (equal fringe-mode '(0 . nil)))))
945 (defun menu-bar-showhide-fringe-menu-customize-left ()
946 "Display fringes only on the left of each window."
947 (interactive)
948 (require 'fringe)
949 (customize-set-variable 'fringe-mode '(nil . 0)))
951 (define-key menu-bar-showhide-fringe-menu [left]
952 `(menu-item ,(purecopy "On the Left") menu-bar-showhide-fringe-menu-customize-left
953 :help ,(purecopy "Fringe only on the left side")
954 :visible (display-graphic-p)
955 :button (:radio . (equal fringe-mode '(nil . 0)))))
957 (defun menu-bar-showhide-fringe-menu-customize-disable ()
958 "Do not display window fringes."
959 (interactive)
960 (require 'fringe)
961 (customize-set-variable 'fringe-mode 0))
963 (define-key menu-bar-showhide-fringe-menu [none]
964 `(menu-item ,(purecopy "None") menu-bar-showhide-fringe-menu-customize-disable
965 :help ,(purecopy "Turn off fringe")
966 :visible (display-graphic-p)
967 :button (:radio . (eq fringe-mode 0))))
969 (define-key menu-bar-showhide-menu [showhide-fringe]
970 `(menu-item ,(purecopy "Fringe") ,menu-bar-showhide-fringe-menu
971 :visible (display-graphic-p)))
973 (defvar menu-bar-showhide-scroll-bar-menu (make-sparse-keymap "Scroll-bar"))
975 (define-key menu-bar-showhide-scroll-bar-menu [right]
976 `(menu-item ,(purecopy "On the Right")
977 menu-bar-right-scroll-bar
978 :help ,(purecopy "Scroll-bar on the right side")
979 :visible (display-graphic-p)
980 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
981 (frame-parameters))) 'right))))
982 (defun menu-bar-right-scroll-bar ()
983 "Display scroll bars on the right of each window."
984 (interactive)
985 (customize-set-variable 'scroll-bar-mode 'right))
987 (define-key menu-bar-showhide-scroll-bar-menu [left]
988 `(menu-item ,(purecopy "On the Left")
989 menu-bar-left-scroll-bar
990 :help ,(purecopy "Scroll-bar on the left side")
991 :visible (display-graphic-p)
992 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
993 (frame-parameters))) 'left))))
995 (defun menu-bar-left-scroll-bar ()
996 "Display scroll bars on the left of each window."
997 (interactive)
998 (customize-set-variable 'scroll-bar-mode 'left))
1000 (define-key menu-bar-showhide-scroll-bar-menu [none]
1001 `(menu-item ,(purecopy "None")
1002 menu-bar-no-scroll-bar
1003 :help ,(purecopy "Turn off scroll-bar")
1004 :visible (display-graphic-p)
1005 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
1006 (frame-parameters))) nil))))
1008 (defun menu-bar-no-scroll-bar ()
1009 "Turn off scroll bars."
1010 (interactive)
1011 (customize-set-variable 'scroll-bar-mode nil))
1013 (define-key menu-bar-showhide-menu [showhide-scroll-bar]
1014 `(menu-item ,(purecopy "Scroll-bar") ,menu-bar-showhide-scroll-bar-menu
1015 :visible (display-graphic-p)))
1017 (define-key menu-bar-showhide-menu [showhide-tooltip-mode]
1018 `(menu-item ,(purecopy "Tooltips") tooltip-mode
1019 :help ,(purecopy "Turn tooltips on/off")
1020 :visible (and (display-graphic-p) (fboundp 'x-show-tip))
1021 :button (:toggle . tooltip-mode)))
1023 (defun menu-bar-frame-for-menubar ()
1024 "Return the frame suitable for updating the menu bar."
1025 (or (and (framep menu-updating-frame)
1026 menu-updating-frame)
1027 (selected-frame)))
1029 (defun menu-bar-positive-p (val)
1030 "Return non-nil iff VAL is a positive number."
1031 (and (numberp val)
1032 (> val 0)))
1034 (define-key menu-bar-showhide-menu [menu-bar-mode]
1035 `(menu-item ,(purecopy "Menu-bar") toggle-menu-bar-mode-from-frame
1036 :help ,(purecopy "Turn menu-bar on/off")
1037 :button
1038 (:toggle . (menu-bar-positive-p
1039 (frame-parameter (menu-bar-frame-for-menubar)
1040 'menu-bar-lines)))))
1042 (defun menu-bar-set-tool-bar-position (position)
1043 (customize-set-variable 'tool-bar-mode t)
1044 (customize-set-variable 'tool-bar-position position))
1045 (defun menu-bar-showhide-tool-bar-menu-customize-disable ()
1046 "Do not display tool bars."
1047 (interactive)
1048 (customize-set-variable 'tool-bar-mode nil))
1049 (defun menu-bar-showhide-tool-bar-menu-customize-enable-left ()
1050 "Display tool bars on the left side."
1051 (interactive)
1052 (menu-bar-set-tool-bar-position 'left))
1053 (defun menu-bar-showhide-tool-bar-menu-customize-enable-right ()
1054 "Display tool bars on the right side."
1055 (interactive)
1056 (menu-bar-set-tool-bar-position 'right))
1057 (defun menu-bar-showhide-tool-bar-menu-customize-enable-top ()
1058 "Display tool bars on the top side."
1059 (interactive)
1060 (menu-bar-set-tool-bar-position 'top))
1061 (defun menu-bar-showhide-tool-bar-menu-customize-enable-bottom ()
1062 "Display tool bars on the bottom side."
1063 (interactive)
1064 (menu-bar-set-tool-bar-position 'bottom))
1066 (if (featurep 'move-toolbar)
1067 (progn
1068 (defvar menu-bar-showhide-tool-bar-menu (make-sparse-keymap "Tool-bar"))
1070 (define-key menu-bar-showhide-tool-bar-menu [showhide-tool-bar-left]
1071 `(menu-item ,(purecopy "On the left")
1072 menu-bar-showhide-tool-bar-menu-customize-enable-left
1073 :help ,(purecopy "Tool-bar at the left side")
1074 :visible (display-graphic-p)
1075 :button
1076 (:radio . (and tool-bar-mode
1077 (eq (frame-parameter
1078 (menu-bar-frame-for-menubar)
1079 'tool-bar-position)
1080 'left)))))
1082 (define-key menu-bar-showhide-tool-bar-menu [showhide-tool-bar-right]
1083 `(menu-item ,(purecopy "On the right")
1084 menu-bar-showhide-tool-bar-menu-customize-enable-right
1085 :help ,(purecopy "Tool-bar at the right side")
1086 :visible (display-graphic-p)
1087 :button
1088 (:radio . (and tool-bar-mode
1089 (eq (frame-parameter
1090 (menu-bar-frame-for-menubar)
1091 'tool-bar-position)
1092 'right)))))
1094 (define-key menu-bar-showhide-tool-bar-menu [showhide-tool-bar-bottom]
1095 `(menu-item ,(purecopy "On the bottom")
1096 menu-bar-showhide-tool-bar-menu-customize-enable-bottom
1097 :help ,(purecopy "Tool-bar at the bottom")
1098 :visible (display-graphic-p)
1099 :button
1100 (:radio . (and tool-bar-mode
1101 (eq (frame-parameter
1102 (menu-bar-frame-for-menubar)
1103 'tool-bar-position)
1104 'bottom)))))
1106 (define-key menu-bar-showhide-tool-bar-menu [showhide-tool-bar-top]
1107 `(menu-item ,(purecopy "On the top")
1108 menu-bar-showhide-tool-bar-menu-customize-enable-top
1109 :help ,(purecopy "Tool-bar at the top")
1110 :visible (display-graphic-p)
1111 :button
1112 (:radio . (and tool-bar-mode
1113 (eq (frame-parameter
1114 (menu-bar-frame-for-menubar)
1115 'tool-bar-position)
1116 'top)))))
1118 (define-key menu-bar-showhide-tool-bar-menu [showhide-tool-bar-none]
1119 `(menu-item ,(purecopy "None")
1120 menu-bar-showhide-tool-bar-menu-customize-disable
1121 :help ,(purecopy "Turn tool-bar off")
1122 :visible (display-graphic-p)
1123 :button (:radio . (eq tool-bar-mode nil))))
1125 (define-key menu-bar-showhide-menu [showhide-tool-bar]
1126 `(menu-item ,(purecopy "Tool-bar") ,menu-bar-showhide-tool-bar-menu
1127 :visible (display-graphic-p)))
1130 ;; else not tool bar that can move.
1131 (define-key menu-bar-showhide-menu [showhide-tool-bar]
1132 `(menu-item ,(purecopy "Tool-bar") toggle-tool-bar-mode-from-frame
1133 :help ,(purecopy "Turn tool-bar on/off")
1134 :visible (display-graphic-p)
1135 :button
1136 (:toggle . (menu-bar-positive-p
1137 (frame-parameter (menu-bar-frame-for-menubar)
1138 'tool-bar-lines))))))
1140 (define-key menu-bar-options-menu [showhide]
1141 `(menu-item ,(purecopy "Show/Hide") ,menu-bar-showhide-menu))
1143 (define-key menu-bar-options-menu [showhide-separator]
1144 menu-bar-separator)
1146 (define-key menu-bar-options-menu [mule]
1147 ;; It is better not to use backquote here,
1148 ;; because that makes a bootstrapping problem
1149 ;; if you need to recompile all the Lisp files using interpreted code.
1150 `(menu-item ,(purecopy "Mule (Multilingual Environment)") ,mule-menu-keymap
1151 ;; Most of the MULE menu actually does make sense in unibyte mode,
1152 ;; e.g. language selection.
1153 ;;; :visible '(default-value 'enable-multibyte-characters)
1155 ;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
1156 ;(define-key menu-bar-options-menu [preferences]
1157 ; `(menu-item ,(purecopy "Preferences") ,menu-bar-preferences-menu
1158 ; :help ,(purecopy "Toggle important global options")))
1160 (define-key menu-bar-options-menu [mule-separator]
1161 menu-bar-separator)
1163 (define-key menu-bar-options-menu [debug-on-quit]
1164 (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
1165 "Enter Debugger on Quit/C-g" "Debug on Quit %s"
1166 "Enter Lisp debugger when C-g is pressed"))
1167 (define-key menu-bar-options-menu [debug-on-error]
1168 (menu-bar-make-toggle toggle-debug-on-error debug-on-error
1169 "Enter Debugger on Error" "Debug on Error %s"
1170 "Enter Lisp debugger when an error is signaled"))
1171 (define-key menu-bar-options-menu [debugger-separator]
1172 menu-bar-separator)
1174 (define-key menu-bar-options-menu [blink-cursor-mode]
1175 (menu-bar-make-mm-toggle blink-cursor-mode
1176 "Blinking Cursor"
1177 "Whether the cursor blinks (Blink Cursor mode)"))
1178 (define-key menu-bar-options-menu [cursor-separator]
1179 menu-bar-separator)
1181 (define-key menu-bar-options-menu [save-place]
1182 (menu-bar-make-toggle toggle-save-place-globally save-place
1183 "Save Place in Files between Sessions"
1184 "Saving place in files %s"
1185 "Visit files of previous session when restarting Emacs"
1186 (require 'saveplace)
1187 ;; Do it by name, to avoid a free-variable
1188 ;; warning during byte compilation.
1189 (set-default
1190 'save-place (not (symbol-value 'save-place)))))
1192 (define-key menu-bar-options-menu [uniquify]
1193 (menu-bar-make-toggle toggle-uniquify-buffer-names uniquify-buffer-name-style
1194 "Use Directory Names in Buffer Names"
1195 "Directory name in buffer names (uniquify) %s"
1196 "Uniquify buffer names by adding parent directory names"
1197 (require 'uniquify)
1198 (setq uniquify-buffer-name-style
1199 (if (not uniquify-buffer-name-style)
1200 'forward))))
1202 (define-key menu-bar-options-menu [edit-options-separator]
1203 menu-bar-separator)
1204 (define-key menu-bar-options-menu [cua-mode]
1205 (menu-bar-make-mm-toggle cua-mode
1206 "C-x/C-c/C-v Cut and Paste (CUA)"
1207 "Use C-z/C-x/C-c/C-v keys for undo/cut/copy/paste"
1208 (:visible (or (not (boundp 'cua-enable-cua-keys))
1209 cua-enable-cua-keys))))
1211 (define-key menu-bar-options-menu [cua-emulation-mode]
1212 (menu-bar-make-mm-toggle cua-mode
1213 "Shift movement mark region (CUA)"
1214 "Use shifted movement keys to set and extend the region"
1215 (:visible (and (boundp 'cua-enable-cua-keys)
1216 (not cua-enable-cua-keys)))))
1218 (define-key menu-bar-options-menu [case-fold-search]
1219 (menu-bar-make-toggle toggle-case-fold-search case-fold-search
1220 "Case-Insensitive Search"
1221 "Case-Insensitive Search %s"
1222 "Ignore letter-case in search commands"))
1224 (defun menu-bar-text-mode-auto-fill ()
1225 (interactive)
1226 (toggle-text-mode-auto-fill)
1227 ;; This is somewhat questionable, as `text-mode-hook'
1228 ;; might have changed outside customize.
1229 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
1230 (customize-mark-as-set 'text-mode-hook))
1232 (define-key menu-bar-options-menu [auto-fill-mode]
1233 `(menu-item ,(purecopy "Auto Fill in Text Modes")
1234 menu-bar-text-mode-auto-fill
1235 :help ,(purecopy "Automatically fill text while typing (Auto Fill mode)")
1236 :button (:toggle . (if (listp text-mode-hook)
1237 (member 'turn-on-auto-fill text-mode-hook)
1238 (eq 'turn-on-auto-fill text-mode-hook)))))
1241 (defvar menu-bar-line-wrapping-menu (make-sparse-keymap "Line Wrapping"))
1243 (define-key menu-bar-line-wrapping-menu [word-wrap]
1244 `(menu-item ,(purecopy "Word Wrap (Visual Line mode)")
1245 (lambda ()
1246 (interactive)
1247 (unless visual-line-mode
1248 (visual-line-mode 1))
1249 (message ,(purecopy "Visual-Line mode enabled")))
1250 :help ,(purecopy "Wrap long lines at word boundaries")
1251 :button (:radio . (and (null truncate-lines)
1252 (not (truncated-partial-width-window-p))
1253 word-wrap))
1254 :visible (menu-bar-menu-frame-live-and-visible-p)))
1256 (define-key menu-bar-line-wrapping-menu [truncate]
1257 `(menu-item ,(purecopy "Truncate Long Lines")
1258 (lambda ()
1259 (interactive)
1260 (if visual-line-mode (visual-line-mode 0))
1261 (setq word-wrap nil)
1262 (toggle-truncate-lines 1))
1263 :help ,(purecopy "Truncate long lines at window edge")
1264 :button (:radio . (or truncate-lines
1265 (truncated-partial-width-window-p)))
1266 :visible (menu-bar-menu-frame-live-and-visible-p)
1267 :enable (not (truncated-partial-width-window-p))))
1269 (define-key menu-bar-line-wrapping-menu [window-wrap]
1270 `(menu-item ,(purecopy "Wrap at Window Edge")
1271 (lambda () (interactive)
1272 (if visual-line-mode (visual-line-mode 0))
1273 (setq word-wrap nil)
1274 (if truncate-lines (toggle-truncate-lines -1)))
1275 :help ,(purecopy "Wrap long lines at window edge")
1276 :button (:radio . (and (null truncate-lines)
1277 (not (truncated-partial-width-window-p))
1278 (not word-wrap)))
1279 :visible (menu-bar-menu-frame-live-and-visible-p)
1280 :enable (not (truncated-partial-width-window-p))))
1282 (define-key menu-bar-options-menu [line-wrapping]
1283 `(menu-item ,(purecopy "Line Wrapping in this Buffer") ,menu-bar-line-wrapping-menu))
1286 (define-key menu-bar-options-menu [highlight-separator]
1287 menu-bar-separator)
1288 (define-key menu-bar-options-menu [highlight-paren-mode]
1289 (menu-bar-make-mm-toggle show-paren-mode
1290 "Paren Match Highlighting"
1291 "Highlight matching/mismatched parentheses at cursor (Show Paren mode)"))
1292 (define-key menu-bar-options-menu [transient-mark-mode]
1293 (menu-bar-make-mm-toggle transient-mark-mode
1294 "Active Region Highlighting"
1295 "Make text in active region stand out in color (Transient Mark mode)"
1296 (:enable (not cua-mode))))
1299 ;; The "Tools" menu items
1301 (defun send-mail-item-name ()
1302 (let* ((known-send-mail-commands '((sendmail-user-agent . "sendmail")
1303 (mh-e-user-agent . "MH")
1304 (message-user-agent . "Gnus Message")
1305 (gnus-user-agent . "Gnus")))
1306 (name (assq mail-user-agent known-send-mail-commands)))
1307 (if name
1308 (setq name (cdr name))
1309 (setq name (symbol-name mail-user-agent))
1310 (if (string-match "\\(.+\\)-user-agent" name)
1311 (setq name (match-string 1 name))))
1312 name))
1314 (defun read-mail-item-name ()
1315 (let* ((known-rmail-commands '((rmail . "RMAIL")
1316 (mh-rmail . "MH")
1317 (gnus . "Gnus")))
1318 (known (assq read-mail-command known-rmail-commands)))
1319 (if known (cdr known) (symbol-name read-mail-command))))
1321 (defvar menu-bar-games-menu (make-sparse-keymap "Games"))
1323 (define-key menu-bar-tools-menu [games]
1324 `(menu-item ,(purecopy "Games") ,menu-bar-games-menu))
1326 (define-key menu-bar-tools-menu [separator-games]
1327 menu-bar-separator)
1329 (define-key menu-bar-games-menu [zone]
1330 `(menu-item ,(purecopy "Zone Out") zone
1331 :help ,(purecopy "Play tricks with Emacs display when Emacs is idle")))
1332 (define-key menu-bar-games-menu [tetris]
1333 `(menu-item ,(purecopy "Tetris") tetris
1334 :help ,(purecopy "Falling blocks game")))
1335 (define-key menu-bar-games-menu [solitaire]
1336 `(menu-item ,(purecopy "Solitaire") solitaire
1337 :help ,(purecopy "Get rid of all the stones")))
1338 (define-key menu-bar-games-menu [snake]
1339 `(menu-item ,(purecopy "Snake") snake
1340 :help ,(purecopy "Move snake around avoiding collisions")))
1341 (define-key menu-bar-games-menu [pong]
1342 `(menu-item ,(purecopy "Pong") pong
1343 :help ,(purecopy "Bounce the ball to your opponent")))
1344 (define-key menu-bar-games-menu [mult]
1345 `(menu-item ,(purecopy "Multiplication Puzzle") mpuz
1346 :help ,(purecopy "Exercise brain with multiplication")))
1347 (define-key menu-bar-games-menu [life]
1348 `(menu-item ,(purecopy "Life") life
1349 :help ,(purecopy "Watch how John Conway's cellular automaton evolves")))
1350 (define-key menu-bar-games-menu [land]
1351 `(menu-item ,(purecopy "Landmark") landmark
1352 :help ,(purecopy "Watch a neural-network robot learn landmarks")))
1353 (define-key menu-bar-games-menu [hanoi]
1354 `(menu-item ,(purecopy "Towers of Hanoi") hanoi
1355 :help ,(purecopy "Watch Towers-of-Hanoi puzzle solved by Emacs")))
1356 (define-key menu-bar-games-menu [gomoku]
1357 `(menu-item ,(purecopy "Gomoku") gomoku
1358 :help ,(purecopy "Mark 5 contiguous squares (like tic-tac-toe)")))
1359 (define-key menu-bar-games-menu [bubbles]
1360 `(menu-item ,(purecopy "Bubbles") bubbles
1361 :help ,(purecopy "Remove all bubbles using the fewest moves")))
1362 (define-key menu-bar-games-menu [black-box]
1363 `(menu-item ,(purecopy "Blackbox") blackbox
1364 :help ,(purecopy "Find balls in a black box by shooting rays")))
1365 (define-key menu-bar-games-menu [adventure]
1366 `(menu-item ,(purecopy "Adventure") dunnet
1367 :help ,(purecopy "Dunnet, a text Adventure game for Emacs")))
1368 (define-key menu-bar-games-menu [5x5]
1369 `(menu-item ,(purecopy "5x5") 5x5
1370 :help ,(purecopy "Fill in all the squares on a 5x5 board")))
1372 (defvar menu-bar-encryption-decryption-menu
1373 (make-sparse-keymap "Encryption/Decryption"))
1375 (define-key menu-bar-tools-menu [encryption-decryption]
1376 `(menu-item ,(purecopy "Encryption/Decryption") ,menu-bar-encryption-decryption-menu))
1378 (define-key menu-bar-tools-menu [separator-encryption-decryption]
1379 menu-bar-separator)
1381 (define-key menu-bar-encryption-decryption-menu [insert-keys]
1382 `(menu-item ,(purecopy "Insert Keys") epa-insert-keys
1383 :help ,(purecopy "Insert public keys after the current point")))
1385 (define-key menu-bar-encryption-decryption-menu [export-keys]
1386 `(menu-item ,(purecopy "Export Keys") epa-export-keys
1387 :help ,(purecopy "Export public keys to a file")))
1389 (define-key menu-bar-encryption-decryption-menu [import-keys-region]
1390 `(menu-item ,(purecopy "Import Keys from Region") epa-import-keys-region
1391 :help ,(purecopy "Import public keys from the current region")))
1393 (define-key menu-bar-encryption-decryption-menu [import-keys]
1394 `(menu-item ,(purecopy "Import Keys from File...") epa-import-keys
1395 :help ,(purecopy "Import public keys from a file")))
1397 (define-key menu-bar-encryption-decryption-menu [list-keys]
1398 `(menu-item ,(purecopy "List Keys") epa-list-keys
1399 :help ,(purecopy "Browse your public keyring")))
1401 (define-key menu-bar-encryption-decryption-menu [separator-keys]
1402 menu-bar-separator)
1404 (define-key menu-bar-encryption-decryption-menu [sign-region]
1405 `(menu-item ,(purecopy "Sign Region") epa-sign-region
1406 :help ,(purecopy "Create digital signature of the current region")))
1408 (define-key menu-bar-encryption-decryption-menu [verify-region]
1409 `(menu-item ,(purecopy "Verify Region") epa-verify-region
1410 :help ,(purecopy "Verify digital signature of the current region")))
1412 (define-key menu-bar-encryption-decryption-menu [encrypt-region]
1413 `(menu-item ,(purecopy "Encrypt Region") epa-encrypt-region
1414 :help ,(purecopy "Encrypt the current region")))
1416 (define-key menu-bar-encryption-decryption-menu [decrypt-region]
1417 `(menu-item ,(purecopy "Decrypt Region") epa-decrypt-region
1418 :help ,(purecopy "Decrypt the current region")))
1420 (define-key menu-bar-encryption-decryption-menu [separator-file]
1421 menu-bar-separator)
1423 (define-key menu-bar-encryption-decryption-menu [sign-file]
1424 `(menu-item ,(purecopy "Sign File...") epa-sign-file
1425 :help ,(purecopy "Create digital signature of a file")))
1427 (define-key menu-bar-encryption-decryption-menu [verify-file]
1428 `(menu-item ,(purecopy "Verify File...") epa-verify-file
1429 :help ,(purecopy "Verify digital signature of a file")))
1431 (define-key menu-bar-encryption-decryption-menu [encrypt-file]
1432 `(menu-item ,(purecopy "Encrypt File...") epa-encrypt-file
1433 :help ,(purecopy "Encrypt a file")))
1435 (define-key menu-bar-encryption-decryption-menu [decrypt-file]
1436 `(menu-item ,(purecopy "Decrypt File...") epa-decrypt-file
1437 :help ,(purecopy "Decrypt a file")))
1439 (define-key menu-bar-tools-menu [simple-calculator]
1440 `(menu-item ,(purecopy "Simple Calculator") calculator
1441 :help ,(purecopy "Invoke the Emacs built-in quick calculator")))
1442 (define-key menu-bar-tools-menu [calc]
1443 `(menu-item ,(purecopy "Programmable Calculator") calc
1444 :help ,(purecopy "Invoke the Emacs built-in full scientific calculator")))
1445 (define-key menu-bar-tools-menu [calendar]
1446 `(menu-item ,(purecopy "Calendar") calendar
1447 :help ,(purecopy "Invoke the Emacs built-in calendar")))
1449 (define-key menu-bar-tools-menu [separator-net]
1450 menu-bar-separator)
1452 (define-key menu-bar-tools-menu [directory-search]
1453 `(menu-item ,(purecopy "Directory Search") eudc-tools-menu))
1454 (define-key menu-bar-tools-menu [compose-mail]
1455 `(menu-item (format "Send Mail (with %s)" (send-mail-item-name)) compose-mail
1456 :visible (and mail-user-agent (not (eq mail-user-agent 'ignore)))
1457 :help ,(purecopy "Send a mail message")))
1458 (define-key menu-bar-tools-menu [rmail]
1459 `(menu-item (format "Read Mail (with %s)" (read-mail-item-name))
1460 menu-bar-read-mail
1461 :visible (and read-mail-command
1462 (not (eq read-mail-command 'ignore)))
1463 :help ,(purecopy "Read your mail and reply to it")))
1465 (defun menu-bar-read-mail ()
1466 "Read mail using `read-mail-command'."
1467 (interactive)
1468 (call-interactively read-mail-command))
1470 (define-key menu-bar-tools-menu [gnus]
1471 `(menu-item ,(purecopy "Read Net News (Gnus)") gnus
1472 :help ,(purecopy "Read network news groups")))
1474 (define-key menu-bar-tools-menu [separator-vc]
1475 menu-bar-separator)
1477 (define-key menu-bar-tools-menu [pcl-cvs]
1478 `(menu-item ,(purecopy "PCL-CVS") cvs-global-menu))
1479 (define-key menu-bar-tools-menu [vc] nil) ;Create the place for the VC menu.
1481 (define-key menu-bar-tools-menu [separator-compare]
1482 menu-bar-separator)
1484 (define-key menu-bar-tools-menu [epatch]
1485 `(menu-item ,(purecopy "Apply Patch") menu-bar-epatch-menu))
1486 (define-key menu-bar-tools-menu [ediff-merge]
1487 `(menu-item ,(purecopy "Merge") menu-bar-ediff-merge-menu))
1488 (define-key menu-bar-tools-menu [compare]
1489 `(menu-item ,(purecopy "Compare (Ediff)") menu-bar-ediff-menu))
1491 (define-key menu-bar-tools-menu [separator-spell]
1492 menu-bar-separator)
1494 (define-key menu-bar-tools-menu [spell]
1495 `(menu-item ,(purecopy "Spell Checking") ispell-menu-map))
1497 (define-key menu-bar-tools-menu [separator-prog]
1498 menu-bar-separator)
1500 (define-key menu-bar-tools-menu [semantic]
1501 `(menu-item ,(purecopy "Source Code Parsers (Semantic)")
1502 semantic-mode
1503 :help ,(purecopy "Toggle automatic parsing in source code buffers (Semantic mode)")
1504 :button (:toggle . (bound-and-true-p semantic-mode))))
1506 (define-key menu-bar-tools-menu [ede]
1507 `(menu-item ,(purecopy "Project support (EDE)")
1508 global-ede-mode
1509 :help ,(purecopy "Toggle the Emacs Development Environment (Global EDE mode)")
1510 :button (:toggle . (bound-and-true-p global-ede-mode))))
1512 (define-key menu-bar-tools-menu [gdb]
1513 `(menu-item ,(purecopy "Debugger (GDB)...") gdb
1514 :help ,(purecopy "Debug a program from within Emacs with GDB")))
1515 (define-key menu-bar-tools-menu [shell-on-region]
1516 `(menu-item ,(purecopy "Shell Command on Region...") shell-command-on-region
1517 :enable mark-active
1518 :help ,(purecopy "Pass marked region to a shell command")))
1519 (define-key menu-bar-tools-menu [shell]
1520 `(menu-item ,(purecopy "Shell Command...") shell-command
1521 :help ,(purecopy "Invoke a shell command and catch its output")))
1522 (define-key menu-bar-tools-menu [compile]
1523 `(menu-item ,(purecopy "Compile...") compile
1524 :help ,(purecopy "Invoke compiler or Make, view compilation errors")))
1525 (define-key menu-bar-tools-menu [grep]
1526 `(menu-item ,(purecopy "Search Files (Grep)...") grep
1527 :help ,(purecopy "Search files for strings or regexps (with Grep)")))
1530 ;; The "Help" menu items
1532 (defvar menu-bar-describe-menu (make-sparse-keymap "Describe"))
1534 (define-key menu-bar-describe-menu [mule-diag]
1535 `(menu-item ,(purecopy "Show All of Mule Status") mule-diag
1536 :visible (default-value 'enable-multibyte-characters)
1537 :help ,(purecopy "Display multilingual environment settings")))
1538 (define-key menu-bar-describe-menu [describe-coding-system-briefly]
1539 `(menu-item ,(purecopy "Describe Coding System (Briefly)")
1540 describe-current-coding-system-briefly
1541 :visible (default-value 'enable-multibyte-characters)))
1542 (define-key menu-bar-describe-menu [describe-coding-system]
1543 `(menu-item ,(purecopy "Describe Coding System...") describe-coding-system
1544 :visible (default-value 'enable-multibyte-characters)))
1545 (define-key menu-bar-describe-menu [describe-input-method]
1546 `(menu-item ,(purecopy "Describe Input Method...") describe-input-method
1547 :visible (default-value 'enable-multibyte-characters)
1548 :help ,(purecopy "Keyboard layout for specific input method")))
1549 (define-key menu-bar-describe-menu [describe-language-environment]
1550 `(menu-item ,(purecopy "Describe Language Environment")
1551 ,describe-language-environment-map))
1553 (define-key menu-bar-describe-menu [separator-desc-mule]
1554 menu-bar-separator)
1556 (define-key menu-bar-describe-menu [list-keybindings]
1557 `(menu-item ,(purecopy "List Key Bindings") describe-bindings
1558 :help ,(purecopy "Display all current key bindings (keyboard shortcuts)")))
1559 (define-key menu-bar-describe-menu [describe-current-display-table]
1560 `(menu-item ,(purecopy "Describe Display Table") describe-current-display-table
1561 :help ,(purecopy "Describe the current display table")))
1562 (define-key menu-bar-describe-menu [describe-package]
1563 `(menu-item ,(purecopy "Describe Package...") describe-package
1564 :help ,(purecopy "Display documentation of a Lisp package")))
1565 (define-key menu-bar-describe-menu [describe-face]
1566 `(menu-item ,(purecopy "Describe Face...") describe-face
1567 :help ,(purecopy "Display the properties of a face")))
1568 (define-key menu-bar-describe-menu [describe-variable]
1569 `(menu-item ,(purecopy "Describe Variable...") describe-variable
1570 :help ,(purecopy "Display documentation of variable/option")))
1571 (define-key menu-bar-describe-menu [describe-function]
1572 `(menu-item ,(purecopy "Describe Function...") describe-function
1573 :help ,(purecopy "Display documentation of function/command")))
1574 (define-key menu-bar-describe-menu [describe-key-1]
1575 `(menu-item ,(purecopy "Describe Key or Mouse Operation...") describe-key
1576 ;; Users typically don't identify keys and menu items...
1577 :help ,(purecopy "Display documentation of command bound to a \
1578 key, a click, or a menu-item")))
1579 (define-key menu-bar-describe-menu [describe-mode]
1580 `(menu-item ,(purecopy "Describe Buffer Modes") describe-mode
1581 :help ,(purecopy "Describe this buffer's major and minor mode")))
1583 (defvar menu-bar-search-documentation-menu
1584 (make-sparse-keymap "Search Documentation"))
1585 (defun menu-bar-read-lispref ()
1586 "Display the Emacs Lisp Reference manual in Info mode."
1587 (interactive)
1588 (info "elisp"))
1590 (defun menu-bar-read-lispintro ()
1591 "Display the Introduction to Emacs Lisp Programming in Info mode."
1592 (interactive)
1593 (info "eintr"))
1595 (defun search-emacs-glossary ()
1596 "Display the Glossary node of the Emacs manual in Info mode."
1597 (interactive)
1598 (info "(emacs)Glossary"))
1600 (defun emacs-index-search (topic)
1601 "Look up TOPIC in the indices of the Emacs User Manual."
1602 (interactive "sSubject to look up: ")
1603 (info "emacs")
1604 (Info-index topic))
1606 (defun elisp-index-search (topic)
1607 "Look up TOPIC in the indices of the Emacs Lisp Reference Manual."
1608 (interactive "sSubject to look up: ")
1609 (info "elisp")
1610 (Info-index topic))
1612 (define-key menu-bar-search-documentation-menu [search-documentation-strings]
1613 `(menu-item ,(purecopy "Search Documentation Strings...") apropos-documentation
1614 :help
1615 ,(purecopy "Find functions and variables whose doc strings match a regexp")))
1616 (define-key menu-bar-search-documentation-menu [find-any-object-by-name]
1617 `(menu-item ,(purecopy "Find Any Object by Name...") apropos
1618 :help ,(purecopy "Find symbols of any kind whose names match a regexp")))
1619 (define-key menu-bar-search-documentation-menu [find-option-by-value]
1620 `(menu-item ,(purecopy "Find Options by Value...") apropos-value
1621 :help ,(purecopy "Find variables whose values match a regexp")))
1622 (define-key menu-bar-search-documentation-menu [find-options-by-name]
1623 `(menu-item ,(purecopy "Find Options by Name...") apropos-variable
1624 :help ,(purecopy "Find variables whose names match a regexp")))
1625 (define-key menu-bar-search-documentation-menu [find-commands-by-name]
1626 `(menu-item ,(purecopy "Find Commands by Name...") apropos-command
1627 :help ,(purecopy "Find commands whose names match a regexp")))
1628 (define-key menu-bar-search-documentation-menu [sep1]
1629 menu-bar-separator)
1630 (define-key menu-bar-search-documentation-menu [lookup-command-in-manual]
1631 `(menu-item ,(purecopy "Look Up Command in User Manual...") Info-goto-emacs-command-node
1632 :help ,(purecopy "Display manual section that describes a command")))
1633 (define-key menu-bar-search-documentation-menu [lookup-key-in-manual]
1634 `(menu-item ,(purecopy "Look Up Key in User Manual...") Info-goto-emacs-key-command-node
1635 :help ,(purecopy "Display manual section that describes a key")))
1636 (define-key menu-bar-search-documentation-menu [lookup-subject-in-elisp-manual]
1637 `(menu-item ,(purecopy "Look Up Subject in ELisp Manual...") elisp-index-search
1638 :help ,(purecopy "Find description of a subject in Emacs Lisp manual")))
1639 (define-key menu-bar-search-documentation-menu [lookup-subject-in-emacs-manual]
1640 `(menu-item ,(purecopy "Look Up Subject in User Manual...") emacs-index-search
1641 :help ,(purecopy "Find description of a subject in Emacs User manual")))
1642 (define-key menu-bar-search-documentation-menu [emacs-terminology]
1643 `(menu-item ,(purecopy "Emacs Terminology") search-emacs-glossary
1644 :help ,(purecopy "Display the Glossary section of the Emacs manual")))
1646 (defvar menu-bar-manuals-menu (make-sparse-keymap "More Manuals"))
1648 (define-key menu-bar-manuals-menu [man]
1649 `(menu-item ,(purecopy "Read Man Page...") manual-entry
1650 :help ,(purecopy "Man-page docs for external commands and libraries")))
1651 (define-key menu-bar-manuals-menu [sep2]
1652 menu-bar-separator)
1653 (define-key menu-bar-manuals-menu [order-emacs-manuals]
1654 `(menu-item ,(purecopy "Ordering Manuals") view-order-manuals
1655 :help ,(purecopy "How to order manuals from the Free Software Foundation")))
1656 (define-key menu-bar-manuals-menu [lookup-subject-in-all-manuals]
1657 `(menu-item ,(purecopy "Lookup Subject in all Manuals...") info-apropos
1658 :help ,(purecopy "Find description of a subject in all installed manuals")))
1659 (define-key menu-bar-manuals-menu [other-manuals]
1660 `(menu-item ,(purecopy "All Other Manuals (Info)") Info-directory
1661 :help ,(purecopy "Read any of the installed manuals")))
1662 (define-key menu-bar-manuals-menu [emacs-lisp-reference]
1663 `(menu-item ,(purecopy "Emacs Lisp Reference") menu-bar-read-lispref
1664 :help ,(purecopy "Read the Emacs Lisp Reference manual")))
1665 (define-key menu-bar-manuals-menu [emacs-lisp-intro]
1666 `(menu-item ,(purecopy "Introduction to Emacs Lisp") menu-bar-read-lispintro
1667 :help ,(purecopy "Read the Introduction to Emacs Lisp Programming")))
1669 (define-key menu-bar-help-menu [about-gnu-project]
1670 `(menu-item ,(purecopy "About GNU") describe-gnu-project
1671 :help ,(purecopy "About the GNU System, GNU Project, and GNU/Linux")))
1672 (define-key menu-bar-help-menu [about-emacs]
1673 `(menu-item ,(purecopy "About Emacs") about-emacs
1674 :help ,(purecopy "Display version number, copyright info, and basic help")))
1675 (define-key menu-bar-help-menu [sep4]
1676 menu-bar-separator)
1677 (define-key menu-bar-help-menu [describe-no-warranty]
1678 `(menu-item ,(purecopy "(Non)Warranty") describe-no-warranty
1679 :help ,(purecopy "Explain that Emacs has NO WARRANTY")))
1680 (define-key menu-bar-help-menu [describe-copying]
1681 `(menu-item ,(purecopy "Copying Conditions") describe-copying
1682 :help ,(purecopy "Show the Emacs license (GPL)")))
1683 (define-key menu-bar-help-menu [getting-new-versions]
1684 `(menu-item ,(purecopy "Getting New Versions") describe-distribution
1685 :help ,(purecopy "How to get the latest version of Emacs")))
1686 (defun menu-bar-help-extra-packages ()
1687 "Display help about some additional packages available for Emacs."
1688 (interactive)
1689 (let (enable-local-variables)
1690 (view-file (expand-file-name "MORE.STUFF"
1691 data-directory))
1692 (goto-address-mode 1)))
1693 (define-key menu-bar-help-menu [sep2]
1694 menu-bar-separator)
1695 (define-key menu-bar-help-menu [external-packages]
1696 `(menu-item ,(purecopy "Finding Extra Packages") menu-bar-help-extra-packages
1697 :help ,(purecopy "Lisp packages distributed separately for use in Emacs")))
1698 (define-key menu-bar-help-menu [find-emacs-packages]
1699 `(menu-item ,(purecopy "Search Built-in Packages") finder-by-keyword
1700 :help ,(purecopy "Find built-in packages and features by keyword")))
1701 (define-key menu-bar-help-menu [more-manuals]
1702 `(menu-item ,(purecopy "More Manuals") ,menu-bar-manuals-menu))
1703 (define-key menu-bar-help-menu [emacs-manual]
1704 `(menu-item ,(purecopy "Read the Emacs Manual") info-emacs-manual
1705 :help ,(purecopy "Full documentation of Emacs features")))
1706 (define-key menu-bar-help-menu [describe]
1707 `(menu-item ,(purecopy "Describe") ,menu-bar-describe-menu))
1708 (define-key menu-bar-help-menu [search-documentation]
1709 `(menu-item ,(purecopy "Search Documentation") ,menu-bar-search-documentation-menu))
1710 (define-key menu-bar-help-menu [sep1]
1711 menu-bar-separator)
1712 (define-key menu-bar-help-menu [emacs-psychotherapist]
1713 `(menu-item ,(purecopy "Emacs Psychotherapist") doctor
1714 :help ,(purecopy "Our doctor will help you feel better")))
1715 (define-key menu-bar-help-menu [send-emacs-bug-report]
1716 `(menu-item ,(purecopy "Send Bug Report...") report-emacs-bug
1717 :help ,(purecopy "Send e-mail to Emacs maintainers")))
1718 (define-key menu-bar-help-menu [emacs-known-problems]
1719 `(menu-item ,(purecopy "Emacs Known Problems") view-emacs-problems
1720 :help ,(purecopy "Read about known problems with Emacs")))
1721 (define-key menu-bar-help-menu [emacs-news]
1722 `(menu-item ,(purecopy "Emacs News") view-emacs-news
1723 :help ,(purecopy "New features of this version")))
1724 (define-key menu-bar-help-menu [emacs-faq]
1725 `(menu-item ,(purecopy "Emacs FAQ") view-emacs-FAQ
1726 :help ,(purecopy "Frequently asked (and answered) questions about Emacs")))
1728 (defun help-with-tutorial-spec-language ()
1729 "Use the Emacs tutorial, specifying which language you want."
1730 (interactive)
1731 (help-with-tutorial t))
1733 (define-key menu-bar-help-menu [emacs-tutorial-language-specific]
1734 `(menu-item ,(purecopy "Emacs Tutorial (choose language)...")
1735 help-with-tutorial-spec-language
1736 :help ,(purecopy "Learn how to use Emacs (choose a language)")))
1737 (define-key menu-bar-help-menu [emacs-tutorial]
1738 `(menu-item ,(purecopy "Emacs Tutorial") help-with-tutorial
1739 :help ,(purecopy "Learn how to use Emacs")))
1741 ;; In OS X it's in the app menu already.
1742 ;; FIXME? There already is an "About Emacs" (sans ...) entry in the Help menu.
1743 (and (featurep 'ns)
1744 (not (eq system-type 'darwin))
1745 (define-key menu-bar-help-menu [info-panel]
1746 `(menu-item ,(purecopy "About Emacs...") ns-do-emacs-info-panel)))
1748 (defun menu-bar-menu-frame-live-and-visible-p ()
1749 "Return non-nil if the menu frame is alive and visible.
1750 The menu frame is the frame for which we are updating the menu."
1751 (let ((menu-frame (or menu-updating-frame (selected-frame))))
1752 (and (frame-live-p menu-frame)
1753 (frame-visible-p menu-frame))))
1755 (defun menu-bar-non-minibuffer-window-p ()
1756 "Return non-nil if selected window of the menu frame is not a minibuf window.
1758 See the documentation of `menu-bar-menu-frame-live-and-visible-p'
1759 for the definition of the menu frame."
1760 (let ((menu-frame (or menu-updating-frame (selected-frame))))
1761 (not (window-minibuffer-p (frame-selected-window menu-frame)))))
1763 (defun kill-this-buffer () ; for the menu bar
1764 "Kill the current buffer.
1765 When called in the minibuffer, get out of the minibuffer
1766 using `abort-recursive-edit'."
1767 (interactive)
1768 (if (menu-bar-non-minibuffer-window-p)
1769 (kill-buffer (current-buffer))
1770 (abort-recursive-edit)))
1772 (defun kill-this-buffer-enabled-p ()
1773 (let ((count 0)
1774 (buffers (buffer-list)))
1775 (while buffers
1776 (or (string-match "^ " (buffer-name (car buffers)))
1777 (setq count (1+ count)))
1778 (setq buffers (cdr buffers)))
1779 (or (not (menu-bar-non-minibuffer-window-p))
1780 (> count 1))))
1782 (put 'dired 'menu-enable '(menu-bar-non-minibuffer-window-p))
1784 ;; Permit deleting frame if it would leave a visible or iconified frame.
1785 (defun delete-frame-enabled-p ()
1786 "Return non-nil if `delete-frame' should be enabled in the menu bar."
1787 (let ((frames (frame-list))
1788 (count 0))
1789 (while frames
1790 (if (frame-visible-p (car frames))
1791 (setq count (1+ count)))
1792 (setq frames (cdr frames)))
1793 (> count 1)))
1795 (defcustom yank-menu-length 20
1796 "Maximum length to display in the yank-menu."
1797 :type 'integer
1798 :group 'menu)
1800 (defun menu-bar-update-yank-menu (string old)
1801 (let ((front (car (cdr yank-menu)))
1802 (menu-string (if (<= (length string) yank-menu-length)
1803 string
1804 (concat
1805 (substring string 0 (/ yank-menu-length 2))
1806 "..."
1807 (substring string (- (/ yank-menu-length 2)))))))
1808 ;; Don't let the menu string be all dashes
1809 ;; because that has a special meaning in a menu.
1810 (if (string-match "\\`-+\\'" menu-string)
1811 (setq menu-string (concat menu-string " ")))
1812 ;; If we're supposed to be extending an existing string, and that
1813 ;; string really is at the front of the menu, then update it in place.
1814 (if (and old (or (eq old (car front))
1815 (string= old (car front))))
1816 (progn
1817 (setcar front string)
1818 (setcar (cdr front) menu-string))
1819 (setcdr yank-menu
1820 (cons
1821 (cons string (cons menu-string 'menu-bar-select-yank))
1822 (cdr yank-menu)))))
1823 (if (> (length (cdr yank-menu)) kill-ring-max)
1824 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
1826 (put 'menu-bar-select-yank 'apropos-inhibit t)
1827 (defun menu-bar-select-yank ()
1828 "Insert the stretch of previously-killed text selected from menu.
1829 The menu shows all the killed text sequences stored in `kill-ring'."
1830 (interactive "*")
1831 (push-mark (point))
1832 (insert last-command-event))
1835 ;;; Buffers Menu
1837 (defcustom buffers-menu-max-size 10
1838 "Maximum number of entries which may appear on the Buffers menu.
1839 If this is 10, then only the ten most-recently-selected buffers are shown.
1840 If this is nil, then all buffers are shown.
1841 A large number or nil slows down menu responsiveness."
1842 :type '(choice integer
1843 (const :tag "All" nil))
1844 :group 'menu)
1846 (defcustom buffers-menu-buffer-name-length 30
1847 "Maximum length of the buffer name on the Buffers menu.
1848 If this is a number, then buffer names are truncated to this length.
1849 If this is nil, then buffer names are shown in full.
1850 A large number or nil makes the menu too wide."
1851 :type '(choice integer
1852 (const :tag "Full length" nil))
1853 :group 'menu)
1855 (defcustom buffers-menu-show-directories 'unless-uniquify
1856 "If non-nil, show directories in the Buffers menu for buffers that have them.
1857 The special value `unless-uniquify' means that directories will be shown
1858 unless `uniquify-buffer-name-style' is non-nil (in which case, buffer
1859 names should include enough of a buffer's directory to distinguish it
1860 from other buffers).
1862 Setting this variable directly does not take effect until next time the
1863 Buffers menu is regenerated."
1864 :set (lambda (symbol value)
1865 (set symbol value)
1866 (menu-bar-update-buffers t))
1867 :initialize 'custom-initialize-default
1868 :type '(choice (const :tag "Never" nil)
1869 (const :tag "Unless uniquify is enabled" unless-uniquify)
1870 (const :tag "Always" t))
1871 :group 'menu)
1873 (defcustom buffers-menu-show-status t
1874 "If non-nil, show modified/read-only status of buffers in the Buffers menu.
1875 Setting this variable directly does not take effect until next time the
1876 Buffers menu is regenerated."
1877 :set (lambda (symbol value)
1878 (set symbol value)
1879 (menu-bar-update-buffers t))
1880 :initialize 'custom-initialize-default
1881 :type 'boolean
1882 :group 'menu)
1884 (defvar list-buffers-directory nil
1885 "String to display in buffer listings for buffers not visiting a file.")
1886 (make-variable-buffer-local 'list-buffers-directory)
1888 (defun menu-bar-select-buffer ()
1889 (interactive)
1890 (switch-to-buffer last-command-event))
1892 (defun menu-bar-select-frame (frame)
1893 (make-frame-visible frame)
1894 (raise-frame frame)
1895 (select-frame frame))
1897 (defun menu-bar-update-buffers-1 (elt)
1898 (let* ((buf (car elt))
1899 (file
1900 (and (if (eq buffers-menu-show-directories 'unless-uniquify)
1901 (or (not (boundp 'uniquify-buffer-name-style))
1902 (null uniquify-buffer-name-style))
1903 buffers-menu-show-directories)
1904 (or (buffer-file-name buf)
1905 (buffer-local-value 'list-buffers-directory buf)))))
1906 (when file
1907 (setq file (file-name-directory file)))
1908 (when (and file (> (length file) 20))
1909 (setq file (concat "..." (substring file -17))))
1910 (cons (if buffers-menu-show-status
1911 (let ((mod (if (buffer-modified-p buf) "*" ""))
1912 (ro (if (buffer-local-value 'buffer-read-only buf) "%" "")))
1913 (if file
1914 (format "%s %s%s -- %s" (cdr elt) mod ro file)
1915 (format "%s %s%s" (cdr elt) mod ro)))
1916 (if file
1917 (format "%s -- %s" (cdr elt) file)
1918 (cdr elt)))
1919 buf)))
1921 ;; Used to cache the menu entries for commands in the Buffers menu
1922 (defvar menu-bar-buffers-menu-command-entries nil)
1924 (defun menu-bar-update-buffers (&optional force)
1925 ;; If user discards the Buffers item, play along.
1926 (and (lookup-key (current-global-map) [menu-bar buffer])
1927 (or force (frame-or-buffer-changed-p))
1928 (let ((buffers (buffer-list))
1929 (frames (frame-list))
1930 buffers-menu)
1931 ;; If requested, list only the N most recently selected buffers.
1932 (if (and (integerp buffers-menu-max-size)
1933 (> buffers-menu-max-size 1))
1934 (if (> (length buffers) buffers-menu-max-size)
1935 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
1937 ;; Make the menu of buffers proper.
1938 (setq buffers-menu
1939 (let (alist)
1940 ;; Put into each element of buffer-list
1941 ;; the name for actual display,
1942 ;; perhaps truncated in the middle.
1943 (dolist (buf buffers)
1944 (let ((name (buffer-name buf)))
1945 (unless (eq ?\s (aref name 0))
1946 (push (menu-bar-update-buffers-1
1947 (cons buf
1948 (if (and (integerp buffers-menu-buffer-name-length)
1949 (> (length name) buffers-menu-buffer-name-length))
1950 (concat
1951 (substring
1952 name 0 (/ buffers-menu-buffer-name-length 2))
1953 "..."
1954 (substring
1955 name (- (/ buffers-menu-buffer-name-length 2))))
1956 name)
1958 alist))))
1959 ;; Now make the actual list of items.
1960 (let ((buffers-vec (make-vector (length alist) nil))
1961 (i (length alist)))
1962 (dolist (pair alist)
1963 (setq i (1- i))
1964 (aset buffers-vec i
1965 (nconc (list (car pair)
1966 (cons nil nil))
1967 `(lambda ()
1968 (interactive)
1969 (switch-to-buffer ,(cdr pair))))))
1970 (list buffers-vec))))
1972 ;; Make a Frames menu if we have more than one frame.
1973 (when (cdr frames)
1974 (let* ((frames-vec (make-vector (length frames) nil))
1975 (frames-menu
1976 (cons 'keymap
1977 (list "Select Frame" frames-vec)))
1978 (i 0))
1979 (dolist (frame frames)
1980 (aset frames-vec i
1981 (nconc
1982 (list
1983 (frame-parameter frame 'name)
1984 (cons nil nil))
1985 `(lambda ()
1986 (interactive) (menu-bar-select-frame ,frame))))
1987 (setq i (1+ i)))
1988 ;; Put it after the normal buffers
1989 (setq buffers-menu
1990 (nconc buffers-menu
1991 `((frames-separator "--")
1992 (frames menu-item "Frames" ,frames-menu))))))
1994 ;; Add in some normal commands at the end of the menu. We use
1995 ;; the copy cached in `menu-bar-buffers-menu-command-entries'
1996 ;; if it's been set already. Note that we can't use constant
1997 ;; lists for the menu-entries, because the low-level menu-code
1998 ;; modifies them.
1999 (unless menu-bar-buffers-menu-command-entries
2000 (setq menu-bar-buffers-menu-command-entries
2001 (list '(command-separator "--")
2002 (list 'next-buffer
2003 'menu-item
2004 "Next Buffer"
2005 'next-buffer
2006 :help "Switch to the \"next\" buffer in a cyclic order")
2007 (list 'previous-buffer
2008 'menu-item
2009 "Previous Buffer"
2010 'previous-buffer
2011 :help "Switch to the \"previous\" buffer in a cyclic order")
2012 (list 'select-named-buffer
2013 'menu-item
2014 "Select Named Buffer..."
2015 'switch-to-buffer
2016 :help "Prompt for a buffer name, and select that buffer in the current window")
2017 (list 'list-all-buffers
2018 'menu-item
2019 "List All Buffers"
2020 'list-buffers
2021 :help "Pop up a window listing all Emacs buffers"
2022 ))))
2023 (setq buffers-menu
2024 (nconc buffers-menu menu-bar-buffers-menu-command-entries))
2026 ;; We used to "(define-key (current-global-map) [menu-bar buffer]"
2027 ;; but that did not do the right thing when the [menu-bar buffer]
2028 ;; entry above had been moved (e.g. to a parent keymap).
2029 (setcdr global-buffers-menu-map (cons "Select Buffer" buffers-menu)))))
2031 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
2033 (menu-bar-update-buffers)
2035 ;; this version is too slow
2036 ;;(defun format-buffers-menu-line (buffer)
2037 ;; "Returns a string to represent the given buffer in the Buffer menu.
2038 ;;nil means the buffer shouldn't be listed. You can redefine this."
2039 ;; (if (string-match "\\` " (buffer-name buffer))
2040 ;; nil
2041 ;; (with-current-buffer buffer
2042 ;; (let ((size (buffer-size)))
2043 ;; (format "%s%s %-19s %6s %-15s %s"
2044 ;; (if (buffer-modified-p) "*" " ")
2045 ;; (if buffer-read-only "%" " ")
2046 ;; (buffer-name)
2047 ;; size
2048 ;; mode-name
2049 ;; (or (buffer-file-name) ""))))))
2051 ;;; Set up a menu bar menu for the minibuffer.
2053 (dolist (map (list minibuffer-local-map
2054 ;; This shouldn't be necessary, but there's a funny
2055 ;; bug in keymap.c that I don't understand yet. -stef
2056 minibuffer-local-completion-map))
2057 (define-key map [menu-bar minibuf]
2058 (cons (purecopy "Minibuf") (make-sparse-keymap "Minibuf"))))
2060 (let ((map minibuffer-local-completion-map))
2061 (define-key map [menu-bar minibuf ?\?]
2062 `(menu-item ,(purecopy "List Completions") minibuffer-completion-help
2063 :help ,(purecopy "Display all possible completions")))
2064 (define-key map [menu-bar minibuf space]
2065 `(menu-item ,(purecopy "Complete Word") minibuffer-complete-word
2066 :help ,(purecopy "Complete at most one word")))
2067 (define-key map [menu-bar minibuf tab]
2068 `(menu-item ,(purecopy "Complete") minibuffer-complete
2069 :help ,(purecopy "Complete as far as possible"))))
2071 (let ((map minibuffer-local-map))
2072 (define-key map [menu-bar minibuf quit]
2073 `(menu-item ,(purecopy "Quit") abort-recursive-edit
2074 :help ,(purecopy "Abort input and exit minibuffer")))
2075 (define-key map [menu-bar minibuf return]
2076 `(menu-item ,(purecopy "Enter") exit-minibuffer
2077 :key-sequence ,(purecopy "\r")
2078 :help ,(purecopy "Terminate input and exit minibuffer")))
2079 (define-key map [menu-bar minibuf isearch-forward]
2080 `(menu-item ,(purecopy "Isearch History Forward") isearch-forward
2081 :help ,(purecopy "Incrementally search minibuffer history forward")))
2082 (define-key map [menu-bar minibuf isearch-backward]
2083 `(menu-item ,(purecopy "Isearch History Backward") isearch-backward
2084 :help ,(purecopy "Incrementally search minibuffer history backward")))
2085 (define-key map [menu-bar minibuf next]
2086 `(menu-item ,(purecopy "Next History Item") next-history-element
2087 :help ,(purecopy "Put next minibuffer history element in the minibuffer")))
2088 (define-key map [menu-bar minibuf previous]
2089 `(menu-item ,(purecopy "Previous History Item") previous-history-element
2090 :help ,(purecopy "Put previous minibuffer history element in the minibuffer"))))
2092 (define-minor-mode menu-bar-mode
2093 "Toggle display of a menu bar on each frame.
2094 This command applies to all frames that exist and frames to be
2095 created in the future.
2096 With a numeric argument, if the argument is positive,
2097 turn on menu bars; otherwise, turn off menu bars."
2098 :init-value t
2099 :global t
2100 ;; It's defined in C/cus-start, this stops the d-m-m macro defining it again.
2101 :variable menu-bar-mode
2103 ;; Turn the menu-bars on all frames on or off.
2104 (let ((val (if menu-bar-mode 1 0)))
2105 (dolist (frame (frame-list))
2106 (set-frame-parameter frame 'menu-bar-lines val))
2107 ;; If the user has given `default-frame-alist' a `menu-bar-lines'
2108 ;; parameter, replace it.
2109 (if (assq 'menu-bar-lines default-frame-alist)
2110 (setq default-frame-alist
2111 (cons (cons 'menu-bar-lines val)
2112 (assq-delete-all 'menu-bar-lines
2113 default-frame-alist)))))
2114 ;; Make the message appear when Emacs is idle. We can not call message
2115 ;; directly. The minor-mode message "Menu-bar mode disabled" comes
2116 ;; after this function returns, overwriting any message we do here.
2117 (when (and (called-interactively-p 'interactive) (not menu-bar-mode))
2118 (run-with-idle-timer 0 nil 'message
2119 "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear.")))
2121 ;;;###autoload
2122 ;; (This does not work right unless it comes after the above definition.)
2123 ;; This comment is taken from tool-bar.el near
2124 ;; (put 'tool-bar-mode ...)
2125 ;; We want to pretend the menu bar by standard is on, as this will make
2126 ;; customize consider disabling the menu bar a customization, and save
2127 ;; that. We could do this for real by setting :init-value above, but
2128 ;; that would overwrite disabling the menu bar from X resources.
2129 (put 'menu-bar-mode 'standard-value '(t))
2131 (defun toggle-menu-bar-mode-from-frame (&optional arg)
2132 "Toggle menu bar on or off, based on the status of the current frame.
2133 See `menu-bar-mode' for more information."
2134 (interactive (list (or current-prefix-arg 'toggle)))
2135 (if (eq arg 'toggle)
2136 (menu-bar-mode
2137 (if (menu-bar-positive-p
2138 (frame-parameter (menu-bar-frame-for-menubar) 'menu-bar-lines))
2139 0 1))
2140 (menu-bar-mode arg)))
2142 (declare-function x-menu-bar-open "term/x-win" (&optional frame))
2143 (declare-function w32-menu-bar-open "term/w32-win" (&optional frame))
2145 (defun menu-bar-open (&optional frame)
2146 "Start key navigation of the menu bar in FRAME.
2148 This function decides which method to use to access the menu
2149 depending on FRAME's terminal device. On X displays, it calls
2150 `x-menu-bar-open'; on Windows, `w32-menu-bar-open' otherwise it
2151 calls `tmm-menubar'.
2153 If FRAME is nil or not given, use the selected frame."
2154 (interactive)
2155 (let ((type (framep (or frame (selected-frame)))))
2156 (cond
2157 ((eq type 'x) (x-menu-bar-open frame))
2158 ((eq type 'w32) (w32-menu-bar-open frame))
2159 (t (with-selected-frame (or frame (selected-frame))
2160 (tmm-menubar))))))
2162 (global-set-key [f10] 'menu-bar-open)
2164 (provide 'menu-bar)
2166 ;;; menu-bar.el ends here