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