(describe_syntax_1): Pass new args to describe_vector.
[emacs.git] / lisp / menu-bar.el
blob41bc628c895ef8c0927cb1017e6fccf3f5ccd59f
1 ;;; menu-bar.el --- define a default menu bar.
3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
5 ;; Author: RMS
6 ;; Keywords: internal
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;; Avishai Yacobi suggested some menu rearrangements.
27 ;;; Code:
29 ;;; User options:
31 (defcustom buffers-menu-max-size 10
32 "*Maximum number of entries which may appear on the Buffers menu.
33 If this is 10, then only the ten most-recently-selected buffers are shown.
34 If this is nil, then all buffers are shown.
35 A large number or nil slows down menu responsiveness."
36 :type '(choice integer
37 (const :tag "All" nil))
38 :group 'mouse)
40 ;; Don't clobber an existing menu-bar keymap, to preserve any menu-bar key
41 ;; definitions made in loaddefs.el.
42 (or (lookup-key global-map [menu-bar])
43 (define-key global-map [menu-bar] (make-sparse-keymap "menu-bar")))
44 (defvar menu-bar-help-menu (make-sparse-keymap "Help"))
46 ;; Force Help item to come last, after the major mode's own items.
47 ;; The symbol used to be called `help', but that gets confused with the
48 ;; help key.
49 (setq menu-bar-final-items '(help-menu))
51 (define-key global-map [menu-bar help-menu] (cons "Help" menu-bar-help-menu))
52 (defvar menu-bar-search-menu (make-sparse-keymap "Search"))
53 (define-key global-map [menu-bar search] (cons "Search" menu-bar-search-menu))
54 (defvar menu-bar-edit-menu (make-sparse-keymap "Edit"))
55 (define-key global-map [menu-bar edit] (cons "Edit" menu-bar-edit-menu))
56 (defvar menu-bar-tools-menu (make-sparse-keymap "Tools"))
57 (define-key global-map [menu-bar tools] (cons "Tools" menu-bar-tools-menu))
58 (defvar menu-bar-files-menu (make-sparse-keymap "Files"))
59 (define-key global-map [menu-bar files] (cons "Files" menu-bar-files-menu))
61 ;; This alias is for compatibility with 19.28 and before.
62 (defvar menu-bar-file-menu menu-bar-files-menu)
64 (defvar vc-menu-map (make-sparse-keymap "Version Control"))
66 (define-key menu-bar-tools-menu [gdb] '("Debugger..." . gdb))
67 (define-key menu-bar-tools-menu [compile] '("Compile..." . compile))
68 (define-key menu-bar-tools-menu [grep] '("Search Files..." . grep))
70 (define-key menu-bar-tools-menu [separator-1]
71 '("--"))
73 (define-key menu-bar-tools-menu [calendar] '("Display Calendar" . calendar))
74 (define-key menu-bar-tools-menu [compose-mail] '("Send Mail" . compose-mail))
75 (define-key menu-bar-tools-menu [rmail] '("Read Mail" . rmail))
76 (define-key menu-bar-tools-menu [gnus] '("Read Net News" . gnus))
78 (define-key menu-bar-tools-menu [separator-vc]
79 '("--"))
81 (define-key menu-bar-tools-menu [vc]
82 (cons "Version Control" vc-menu-map))
84 (define-key menu-bar-tools-menu [separator-compare]
85 '("--"))
87 (define-key menu-bar-tools-menu [epatch]
88 '("Apply Patch" . menu-bar-epatch-menu))
89 (define-key menu-bar-tools-menu [ediff-merge]
90 '("Merge" . menu-bar-ediff-merge-menu))
91 (define-key menu-bar-tools-menu [compare]
92 '("Compare" . menu-bar-ediff-menu))
94 (define-key menu-bar-tools-menu [separator-print]
95 '("--"))
97 (put 'print-region 'menu-enable 'mark-active)
98 (put 'ps-print-region-with-faces 'menu-enable 'mark-active)
100 (define-key menu-bar-tools-menu [ps-print-region]
101 '("Postscript Print Region" . ps-print-region-with-faces))
102 (define-key menu-bar-tools-menu [ps-print-buffer]
103 '("Postscript Print Buffer" . ps-print-buffer-with-faces))
104 (define-key menu-bar-tools-menu [print-region]
105 '("Print Region" . print-region))
106 (define-key menu-bar-tools-menu [print-buffer]
107 '("Print Buffer" . print-buffer))
109 (define-key menu-bar-files-menu [exit-emacs]
110 '("Exit Emacs" . save-buffers-kill-emacs))
112 (define-key menu-bar-files-menu [separator-exit]
113 '("--"))
115 (define-key menu-bar-files-menu [one-window]
116 '("One Window" . delete-other-windows))
118 (define-key menu-bar-files-menu [split-window]
119 '("Split Window" . split-window-vertically))
121 (if (fboundp 'delete-frame)
122 (progn
123 ;; Don't use delete-frame as event name
124 ;; because that is a special event.
125 (define-key menu-bar-files-menu [delete-this-frame]
126 '("Delete Frame" . delete-frame))
127 (define-key menu-bar-files-menu [make-frame-on-display]
128 '("Open New Display..." . make-frame-on-display))
129 (define-key menu-bar-files-menu [make-frame]
130 '("Make New Frame" . make-frame))))
132 (define-key menu-bar-files-menu [separator-buffers]
133 '("--"))
135 (define-key menu-bar-files-menu [kill-buffer]
136 '("Kill Current Buffer" . kill-this-buffer))
137 (define-key menu-bar-files-menu [insert-file]
138 '("Insert File..." . insert-file))
139 (define-key menu-bar-files-menu [revert-buffer]
140 '("Revert Buffer" . revert-buffer))
141 (define-key menu-bar-files-menu [write-file]
142 '("Save Buffer As..." . write-file))
143 (define-key menu-bar-files-menu [save-buffer] '("Save Buffer" . save-buffer))
144 (define-key menu-bar-files-menu [dired] '("Open Directory..." . dired))
145 (define-key menu-bar-files-menu [open-file] '("Open File..." . find-file))
148 (defun nonincremental-search-forward (string)
149 "Read a string and search for it nonincrementally."
150 (interactive "sSearch for string: ")
151 (if (equal string "")
152 (search-forward (car search-ring))
153 (isearch-update-ring string nil)
154 (search-forward string)))
156 (defun nonincremental-search-backward (string)
157 "Read a string and search backward for it nonincrementally."
158 (interactive "sSearch for string: ")
159 (if (equal string "")
160 (search-backward (car search-ring))
161 (isearch-update-ring string nil)
162 (search-backward string)))
164 (defun nonincremental-re-search-forward (string)
165 "Read a regular expression and search for it nonincrementally."
166 (interactive "sSearch for regexp: ")
167 (if (equal string "")
168 (re-search-forward (car regexp-search-ring))
169 (isearch-update-ring string t)
170 (re-search-forward string)))
172 (defun nonincremental-re-search-backward (string)
173 "Read a regular expression and search backward for it nonincrementally."
174 (interactive "sSearch for regexp: ")
175 (if (equal string "")
176 (re-search-backward (car regexp-search-ring))
177 (isearch-update-ring string t)
178 (re-search-backward string)))
180 (defun nonincremental-repeat-search-forward ()
181 "Search forward for the previous search string."
182 (interactive)
183 (search-forward (car search-ring)))
185 (defun nonincremental-repeat-search-backward ()
186 "Search backward for the previous search string."
187 (interactive)
188 (search-backward (car search-ring)))
190 (defun nonincremental-repeat-re-search-forward ()
191 "Search forward for the previous regular expression."
192 (interactive)
193 (re-search-forward (car regexp-search-ring)))
195 (defun nonincremental-repeat-re-search-backward ()
196 "Search backward for the previous regular expression."
197 (interactive)
198 (re-search-backward (car regexp-search-ring)))
200 (define-key menu-bar-search-menu [query-replace-regexp]
201 '("Query Replace Regexp..." . query-replace-regexp))
202 (define-key menu-bar-search-menu [query-replace]
203 '("Query Replace..." . query-replace))
204 (define-key menu-bar-search-menu [find-tag]
205 '("Find Tag..." . find-tag))
206 (define-key menu-bar-search-menu [bookmark]
207 '("Bookmarks" . menu-bar-bookmark-map))
209 (define-key menu-bar-search-menu [separator-search]
210 '("--"))
212 (define-key menu-bar-search-menu [repeat-regexp-back]
213 '("Repeat Regexp Backwards" . nonincremental-repeat-re-search-backward))
214 (define-key menu-bar-search-menu [repeat-search-back]
215 '("Repeat Backwards" . nonincremental-repeat-search-backward))
216 (define-key menu-bar-search-menu [repeat-regexp-fwd]
217 '("Repeat Regexp" . nonincremental-repeat-re-search-forward))
218 (define-key menu-bar-search-menu [repeat-search-fwd]
219 '("Repeat Search" . nonincremental-repeat-search-forward))
221 (define-key menu-bar-search-menu [separator-repeat]
222 '("--"))
224 (define-key menu-bar-search-menu [re-search-backward]
225 '("Regexp Search Backwards..." . nonincremental-re-search-backward))
226 (define-key menu-bar-search-menu [search-backward]
227 '("Search Backwards..." . nonincremental-search-backward))
228 (define-key menu-bar-search-menu [re-search-forward]
229 '("Regexp Search..." . nonincremental-re-search-forward))
230 (define-key menu-bar-search-menu [search-forward]
231 '("Search..." . nonincremental-search-forward))
233 (if (fboundp 'start-process)
234 (define-key menu-bar-edit-menu [spell] '("Spell" . ispell-menu-map)))
235 (define-key menu-bar-edit-menu [fill] '("Fill" . fill-region))
236 (define-key menu-bar-edit-menu [props] '("Text Properties" . facemenu-menu))
238 (define-key menu-bar-edit-menu [separator-edit]
239 '("--"))
241 (define-key menu-bar-edit-menu [clear] '("Clear" . delete-region))
243 (define-key menu-bar-edit-menu [paste] '("Paste Most Recent" . yank))
245 (defvar yank-menu (cons "Select Yank" nil))
246 (fset 'yank-menu (cons 'keymap yank-menu))
247 (define-key menu-bar-edit-menu [select-paste] '("Select and Paste" . yank-menu))
248 (define-key menu-bar-edit-menu [copy] '("Copy" . menu-bar-kill-ring-save))
249 (define-key menu-bar-edit-menu [cut] '("Cut" . kill-region))
250 (define-key menu-bar-edit-menu [undo] '("Undo" . undo))
252 (defun menu-bar-kill-ring-save (beg end)
253 (interactive "r")
254 (if (mouse-region-match)
255 (message "Select a region with the mouse does `copy' automatically")
256 (kill-ring-save beg end)))
258 (put 'fill-region 'menu-enable '(and mark-active (not buffer-read-only)))
259 (put 'kill-region 'menu-enable '(and mark-active (not buffer-read-only)))
260 (put 'menu-bar-kill-ring-save 'menu-enable 'mark-active)
261 (put 'yank 'menu-enable '(and (x-selection-exists-p) (not buffer-read-only)))
262 (put 'yank-menu 'menu-enable '(and (cdr yank-menu) (not buffer-read-only)))
263 (put 'delete-region 'menu-enable '(and mark-active
264 (not buffer-read-only)
265 (not (mouse-region-match))))
266 (put 'undo 'menu-enable '(and (not buffer-read-only)
267 (if (eq last-command 'undo)
268 pending-undo-list
269 (consp buffer-undo-list))))
270 (put 'query-replace 'menu-enable '(not buffer-read-only))
271 (put 'query-replace-regexp 'menu-enable '(not buffer-read-only))
273 (autoload 'ispell-menu-map "ispell" nil t 'keymap)
275 ;; These are alternative definitions for the cut, paste and copy
276 ;; menu items. Use them if your system expects these to use the clipboard.
278 (put 'clipboard-kill-region 'menu-enable 'mark-active)
279 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
280 (put 'clipboard-yank 'menu-enable
281 '(or (x-selection-exists-p) (x-selection-exists-p 'CLIPBOARD)))
283 (defun clipboard-yank ()
284 "Reinsert the last stretch of killed text, or the clipboard contents."
285 (interactive)
286 (let ((x-select-enable-clipboard t))
287 (yank)))
289 (defun clipboard-kill-ring-save (beg end)
290 "Copy region to kill ring, and save in the X clipboard."
291 (interactive "r")
292 (let ((x-select-enable-clipboard t))
293 (kill-ring-save beg end)))
295 (defun clipboard-kill-region (beg end)
296 "Kill the region, and save it in the X clipboard."
297 (interactive "r")
298 (let ((x-select-enable-clipboard t))
299 (kill-region beg end)))
301 (defun menu-bar-enable-clipboard ()
302 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
303 Do the same for the keys of the same name."
304 (interactive)
305 ;; We can't use constant list structure here because it becomes pure,
306 ;; and because it gets modified with cache data.
307 (define-key menu-bar-edit-menu [paste]
308 (cons "Paste" 'clipboard-yank))
309 (define-key menu-bar-edit-menu [copy]
310 (cons "Copy" 'clipboard-kill-ring-save))
311 (define-key menu-bar-edit-menu [cut]
312 (cons "Cut" 'clipboard-kill-region))
314 (define-key global-map [f20] 'clipboard-kill-region)
315 (define-key global-map [f16] 'clipboard-kill-ring-save)
316 (define-key global-map [f18] 'clipboard-yank)
317 ;; X11R6 versions
318 (define-key global-map [cut] 'clipboard-kill-region)
319 (define-key global-map [copy] 'clipboard-kill-ring-save)
320 (define-key global-map [paste] 'clipboard-yank))
323 ;;; Menu support
325 (defvar menu-bar-custom-menu (make-sparse-keymap "Customize"))
327 (define-key menu-bar-custom-menu [custom-menu-update]
328 '("Update This Menu" . custom-menu-update))
329 (define-key menu-bar-custom-menu [customize-apropos]
330 '("Apropos..." . customize-apropos))
331 (define-key menu-bar-custom-menu [customize-group]
332 '("Specific Group..." . customize-group))
333 (define-key menu-bar-custom-menu [customize-face]
334 '("Specific Face..." . customize-face))
335 (define-key menu-bar-custom-menu [customize-variable]
336 '("Specific Variable..." . customize-variable))
337 (define-key menu-bar-custom-menu [customize]
338 '("Browse Hierarchy of User Options" . customize))
340 (define-key menu-bar-help-menu [emacs-version]
341 '("Show Version" . emacs-version))
342 (define-key menu-bar-help-menu [report-emacs-bug]
343 '("Send Bug Report..." . report-emacs-bug))
344 (define-key menu-bar-help-menu [finder-by-keyword]
345 '("Find Lisp Packages..." . finder-by-keyword))
346 (define-key menu-bar-help-menu [emacs-tutorial]
347 '("Emacs Tutorial" . help-with-tutorial))
348 (define-key menu-bar-help-menu [man]
349 '("Man..." . manual-entry))
350 (define-key menu-bar-help-menu [describe-variable]
351 '("Describe Variable..." . describe-variable))
352 (define-key menu-bar-help-menu [describe-function]
353 '("Describe Function..." . describe-function))
354 (define-key menu-bar-help-menu [describe-key]
355 '("Describe Key..." . describe-key))
356 (define-key menu-bar-help-menu [list-keybindings]
357 '("List Keybindings" . describe-bindings))
358 (define-key menu-bar-help-menu [command-apropos]
359 '("Command Apropos..." . command-apropos))
360 (define-key menu-bar-help-menu [describe-mode]
361 '("Describe Mode" . describe-mode))
362 (define-key menu-bar-help-menu [info] '("Browse Manuals" . info))
363 (define-key menu-bar-help-menu [emacs-faq] '("Emacs FAQ" . view-emacs-FAQ))
364 (define-key menu-bar-help-menu [emacs-news] '("Emacs News" . view-emacs-news))
365 (define-key menu-bar-help-menu [customize-menu]
366 (cons "Customize" menu-bar-custom-menu))
368 (defun kill-this-buffer () ; for the menubar
369 "Kills the current buffer."
370 (interactive)
371 (kill-buffer (current-buffer)))
373 (defun kill-this-buffer-enabled-p ()
374 (let ((count 0)
375 (buffers (buffer-list)))
376 (while buffers
377 (or (string-match "^ " (buffer-name (car buffers)))
378 (setq count (1+ count)))
379 (setq buffers (cdr buffers)))
380 (and (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
381 (> count 1))))
383 (put 'kill-this-buffer 'menu-enable '(kill-this-buffer-enabled-p))
385 (put 'save-buffer 'menu-enable
386 '(and (buffer-modified-p)
387 (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))))
389 (put 'write-file 'menu-enable
390 '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
392 (put 'find-file 'menu-enable
393 '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
395 (put 'dired 'menu-enable
396 '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
398 (put 'insert-file 'menu-enable
399 '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
401 (put 'revert-buffer 'menu-enable
402 '(or revert-buffer-function revert-buffer-insert-file-contents-function
403 (and (buffer-file-name)
404 (or (buffer-modified-p)
405 (not (verify-visited-file-modtime (current-buffer)))))))
407 ;; Permit deleting frame if it would leave a visible or iconified frame.
408 (put 'delete-frame 'menu-enable
409 '(delete-frame-enabled-p))
411 (defun delete-frame-enabled-p ()
412 "Return non-nil if `delete-frame' should be enabled in the menu bar."
413 (let ((frames (frame-list))
414 (count 0))
415 (while frames
416 (if (frame-visible-p (car frames))
417 (setq count (1+ count)))
418 (setq frames (cdr frames)))
419 (> count 1)))
421 (put 'advertised-undo 'menu-enable
422 '(and (not (eq t buffer-undo-list))
423 (if (eq last-command 'undo)
424 (and (boundp 'pending-undo-list)
425 pending-undo-list)
426 buffer-undo-list)))
428 (defcustom yank-menu-length 20
429 "*Maximum length to display in the yank-menu."
430 :type 'integer
431 :group 'mouse)
433 (defun menu-bar-update-yank-menu (string old)
434 (let ((front (car (cdr yank-menu)))
435 (menu-string (if (<= (length string) yank-menu-length)
436 string
437 (concat
438 (substring string 0 (/ yank-menu-length 2))
439 "..."
440 (substring string (- (/ yank-menu-length 2)))))))
441 ;; Don't let the menu string be all dashes
442 ;; because that has a special meaning in a menu.
443 (if (string-match "\\`-+\\'" menu-string)
444 (setq menu-string (concat menu-string " ")))
445 ;; If we're supposed to be extending an existing string, and that
446 ;; string really is at the front of the menu, then update it in place.
447 (if (and old (or (eq old (car front))
448 (string= old (car front))))
449 (progn
450 (setcar front string)
451 (setcar (cdr front) menu-string))
452 (setcdr yank-menu
453 (cons
454 (cons string (cons menu-string 'menu-bar-select-yank))
455 (cdr yank-menu)))))
456 (if (> (length (cdr yank-menu)) kill-ring-max)
457 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
459 (defun menu-bar-select-yank ()
460 (interactive "*")
461 (push-mark (point))
462 (insert last-command-event))
464 ;; This definition is just to show what this looks like.
465 ;; It gets overridden below when menu-bar-update-buffers is called.
466 (define-key global-map [menu-bar buffer]
467 (cons "Buffers" (make-sparse-keymap "Buffers")))
469 (defvar list-buffers-directory nil)
471 (defvar menu-bar-update-buffers-maxbuf)
473 (defun menu-bar-select-buffer ()
474 (interactive)
475 (switch-to-buffer last-command-event))
477 (defun menu-bar-select-frame ()
478 (interactive)
479 (make-frame-visible last-command-event)
480 (raise-frame last-command-event)
481 (select-frame last-command-event))
483 (defun menu-bar-update-buffers-1 (elt)
484 (cons (format
485 (format "%%%ds %%s%%s %%s" menu-bar-update-buffers-maxbuf)
486 (cdr elt)
487 (if (buffer-modified-p (car elt))
488 "*" " ")
489 (save-excursion
490 (set-buffer (car elt))
491 (if buffer-read-only "%" " "))
492 (let ((file
493 (or (buffer-file-name (car elt))
494 (save-excursion
495 (set-buffer (car elt))
496 list-buffers-directory)
497 "")))
498 (setq file (or (file-name-directory file)
499 ""))
500 (if (> (length file) 20)
501 (setq file (concat "..." (substring file -17))))
502 file))
503 (car elt)))
505 (defvar menu-bar-buffers-menu-list-buffers-entry nil)
507 (defun menu-bar-update-buffers ()
508 ;; If user discards the Buffers item, play along.
509 (and (lookup-key (current-global-map) [menu-bar buffer])
510 (frame-or-buffer-changed-p)
511 (let ((buffers (buffer-list))
512 (frames (frame-list))
513 (maxlen 0)
514 buffers-menu frames-menu)
515 ;; If requested, list only the N most recently selected buffers.
516 (if (and (integerp buffers-menu-max-size)
517 (> buffers-menu-max-size 1))
518 (if (> (length buffers) buffers-menu-max-size)
519 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
521 ;; Make the menu of buffers proper.
522 (setq buffers-menu
523 (cons "Select Buffer"
524 (let* ((buffer-list
525 (mapcar 'list buffers))
526 tail
527 (menu-bar-update-buffers-maxbuf 0)
528 alist
529 head)
530 ;; Put into each element of buffer-list
531 ;; the name for actual display,
532 ;; perhaps truncated in the middle.
533 (setq tail buffer-list)
534 (while tail
535 (let ((name (buffer-name (car (car tail)))))
536 (setcdr (car tail)
537 (if (> (length name) 27)
538 (concat (substring name 0 12)
539 "..."
540 (substring name -12))
541 name)))
542 (setq tail (cdr tail)))
543 ;; Compute the maximum length of any name.
544 (setq tail buffer-list)
545 (while tail
546 (or (eq ?\ (aref (cdr (car tail)) 0))
547 (setq menu-bar-update-buffers-maxbuf
548 (max menu-bar-update-buffers-maxbuf
549 (length (cdr (car tail))))))
550 (setq tail (cdr tail)))
551 ;; Set ALIST to an alist of the form
552 ;; ITEM-STRING . BUFFER
553 (setq tail buffer-list)
554 (while tail
555 (let ((elt (car tail)))
556 (or (eq ?\ (aref (cdr elt) 0))
557 (setq alist (cons
558 (menu-bar-update-buffers-1 elt)
559 alist)))
560 (and alist (> (length (car (car alist))) maxlen)
561 (setq maxlen (length (car (car alist))))))
562 (setq tail (cdr tail)))
563 (setq alist (nreverse alist))
564 ;; Make the menu item for list-buffers
565 ;; or reuse the one we already have.
566 ;; The advantage in reusing one
567 ;; is that it already has the keyboard equivalent
568 ;; cached, so we save the time to look that up again.
569 (or menu-bar-buffers-menu-list-buffers-entry
570 (setq menu-bar-buffers-menu-list-buffers-entry
571 (cons
572 'list-buffers
573 (cons
575 'list-buffers))))
576 ;; Update the item string for menu's new width.
577 (setcar (cdr menu-bar-buffers-menu-list-buffers-entry)
578 (concat (make-string (max (- (/ maxlen 2) 8) 0)
579 ?\ )
580 "List All Buffers"))
581 ;; Now make the actual list of items,
582 ;; ending with the list-buffers item.
583 (nconc (mapcar '(lambda (pair)
584 ;; This is somewhat risque, to use
585 ;; the buffer name itself as the event
586 ;; type to define, but it works.
587 ;; It would not work to use the buffer
588 ;; since a buffer as an event has its
589 ;; own meaning.
590 (nconc (list (buffer-name (cdr pair))
591 (car pair)
592 (cons nil nil))
593 'menu-bar-select-buffer))
594 alist)
595 (list menu-bar-buffers-menu-list-buffers-entry)))))
598 ;; Make a Frames menu if we have more than one frame.
599 (if (cdr frames)
600 (let ((name (concat (make-string (max (- (/ maxlen 2) 3) 0)
601 ?\ )
602 "Frames"))
603 (frames-menu
604 (cons 'keymap
605 (cons "Select Frame"
606 (mapcar '(lambda (frame)
607 (nconc (list frame
608 (cdr (assq 'name
609 (frame-parameters frame)))
610 (cons nil nil))
611 'menu-bar-select-frame))
612 frames)))))
613 ;; Put it underneath the Buffers menu.
614 (setq buffers-menu (cons (cons 'frames (cons name frames-menu))
615 buffers-menu))))
616 (if buffers-menu
617 (setq buffers-menu (cons 'keymap buffers-menu)))
618 (define-key (current-global-map) [menu-bar buffer]
619 (cons "Buffers" buffers-menu)))))
621 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
623 (menu-bar-update-buffers)
625 ;; this version is too slow
626 ;;;(defun format-buffers-menu-line (buffer)
627 ;;; "Returns a string to represent the given buffer in the Buffer menu.
628 ;;;nil means the buffer shouldn't be listed. You can redefine this."
629 ;;; (if (string-match "\\` " (buffer-name buffer))
630 ;;; nil
631 ;;; (save-excursion
632 ;;; (set-buffer buffer)
633 ;;; (let ((size (buffer-size)))
634 ;;; (format "%s%s %-19s %6s %-15s %s"
635 ;;; (if (buffer-modified-p) "*" " ")
636 ;;; (if buffer-read-only "%" " ")
637 ;;; (buffer-name)
638 ;;; size
639 ;;; mode-name
640 ;;; (or (buffer-file-name) ""))))))
642 ;;; Set up a menu bar menu for the minibuffer.
644 (mapcar
645 (function
646 (lambda (map)
647 (define-key map [menu-bar minibuf]
648 (cons "Minibuf" (make-sparse-keymap "Minibuf")))))
649 (list minibuffer-local-ns-map
650 minibuffer-local-must-match-map
651 minibuffer-local-isearch-map
652 minibuffer-local-map
653 minibuffer-local-completion-map))
655 (mapcar
656 (function
657 (lambda (map)
658 (define-key map [menu-bar minibuf ?\?]
659 '("List Completions" . minibuffer-completion-help))
660 (define-key map [menu-bar minibuf space]
661 '("Complete Word" . minibuffer-complete-word))
662 (define-key map [menu-bar minibuf tab]
663 '("Complete" . minibuffer-complete))
665 (list minibuffer-local-must-match-map
666 minibuffer-local-completion-map))
668 (mapcar
669 (function
670 (lambda (map)
671 (define-key map [menu-bar minibuf quit]
672 '("Quit" . keyboard-escape-quit))
673 (define-key map [menu-bar minibuf return]
674 '("Enter" . exit-minibuffer))
676 (list minibuffer-local-ns-map
677 minibuffer-local-must-match-map
678 minibuffer-local-isearch-map
679 minibuffer-local-map
680 minibuffer-local-completion-map))
682 (defvar menu-bar-mode nil)
684 (defun menu-bar-mode (flag)
685 "Toggle display of a menu bar on each frame.
686 This command applies to all frames that exist and frames to be
687 created in the future.
688 With a numeric argument, if the argument is negative,
689 turn off menu bars; otherwise, turn on menu bars."
690 (interactive "P")
692 ;; Make menu-bar-mode and default-frame-alist consistent.
693 (let ((default (assq 'menu-bar-lines default-frame-alist)))
694 (if default
695 (setq menu-bar-mode (not (eq (cdr default) 0)))
696 (setq default-frame-alist
697 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
698 default-frame-alist))))
700 ;; Toggle or set the mode, according to FLAG.
701 (setq menu-bar-mode (if (null flag) (not menu-bar-mode)
702 (> (prefix-numeric-value flag) 0)))
704 ;; Apply it to default-frame-alist.
705 (let ((parameter (assq 'menu-bar-lines default-frame-alist)))
706 (if (consp parameter)
707 (setcdr parameter (if menu-bar-mode 1 0))
708 (setq default-frame-alist
709 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
710 default-frame-alist))))
712 ;; Apply it to existing frames.
713 (let ((frames (frame-list)))
714 (while frames
715 (let ((height (cdr (assq 'height (frame-parameters (car frames))))))
716 (modify-frame-parameters (car frames)
717 (list (cons 'menu-bar-lines
718 (if menu-bar-mode 1 0))))
719 (modify-frame-parameters (car frames)
720 (list (cons 'height height))))
721 (setq frames (cdr frames)))))
723 (provide 'menu-bar)
725 ;;; menu-bar.el ends here