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