(send_process): Make buf and temp_buf `unsigned char *'.
[emacs.git] / lisp / menu-bar.el
blob47cdd61851759fce42c6fdf4905bcf9f6887d7b5
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 (if (null search-ring)
187 (error "No previous search"))
188 (search-forward (car search-ring)))
190 (defun nonincremental-repeat-search-backward ()
191 "Search backward for the previous search string."
192 (interactive)
193 (if (null search-ring)
194 (error "No previous search"))
195 (search-backward (car search-ring)))
197 (defun nonincremental-repeat-re-search-forward ()
198 "Search forward for the previous regular expression."
199 (interactive)
200 (if (null regexp-search-ring)
201 (error "No previous search"))
202 (re-search-forward (car regexp-search-ring)))
204 (defun nonincremental-repeat-re-search-backward ()
205 "Search backward for the previous regular expression."
206 (interactive)
207 (if (null regexp-search-ring)
208 (error "No previous search"))
209 (re-search-backward (car regexp-search-ring)))
211 (define-key menu-bar-search-menu [query-replace-regexp]
212 '("Query Replace Regexp..." . query-replace-regexp))
213 (define-key menu-bar-search-menu [query-replace]
214 '("Query Replace..." . query-replace))
215 (define-key menu-bar-search-menu [find-tag]
216 '("Find Tag..." . find-tag))
217 (define-key menu-bar-search-menu [bookmark]
218 '("Bookmarks" . menu-bar-bookmark-map))
220 (define-key menu-bar-search-menu [separator-search]
221 '("--"))
223 (define-key menu-bar-search-menu [repeat-regexp-back]
224 '("Repeat Regexp Backwards" . nonincremental-repeat-re-search-backward))
225 (define-key menu-bar-search-menu [repeat-search-back]
226 '("Repeat Backwards" . nonincremental-repeat-search-backward))
227 (define-key menu-bar-search-menu [repeat-regexp-fwd]
228 '("Repeat Regexp" . nonincremental-repeat-re-search-forward))
229 (define-key menu-bar-search-menu [repeat-search-fwd]
230 '("Repeat Search" . nonincremental-repeat-search-forward))
232 (define-key menu-bar-search-menu [separator-repeat]
233 '("--"))
235 (define-key menu-bar-search-menu [re-search-backward]
236 '("Regexp Search Backwards..." . nonincremental-re-search-backward))
237 (define-key menu-bar-search-menu [search-backward]
238 '("Search Backwards..." . nonincremental-search-backward))
239 (define-key menu-bar-search-menu [re-search-forward]
240 '("Regexp Search..." . nonincremental-re-search-forward))
241 (define-key menu-bar-search-menu [search-forward]
242 '("Search..." . nonincremental-search-forward))
244 (if (fboundp 'start-process)
245 (define-key menu-bar-edit-menu [spell] '("Spell" . ispell-menu-map)))
246 (define-key menu-bar-edit-menu [fill] '("Fill" . fill-region))
247 (define-key menu-bar-edit-menu [props] '("Text Properties" . facemenu-menu))
249 (define-key menu-bar-edit-menu [separator-edit]
250 '("--"))
252 (define-key menu-bar-edit-menu [clear] '("Clear" . delete-region))
254 (define-key menu-bar-edit-menu [paste] '("Paste Most Recent" . yank))
256 (defvar yank-menu (cons "Select Yank" nil))
257 (fset 'yank-menu (cons 'keymap yank-menu))
258 (define-key menu-bar-edit-menu [select-paste] '("Select and Paste" . yank-menu))
259 (define-key menu-bar-edit-menu [copy] '("Copy" . menu-bar-kill-ring-save))
260 (define-key menu-bar-edit-menu [cut] '("Cut" . kill-region))
261 (define-key menu-bar-edit-menu [undo] '("Undo" . undo))
263 (defun menu-bar-kill-ring-save (beg end)
264 (interactive "r")
265 (if (mouse-region-match)
266 (message "Select a region with the mouse does `copy' automatically")
267 (kill-ring-save beg end)))
269 (put 'fill-region 'menu-enable '(and mark-active (not buffer-read-only)))
270 (put 'kill-region 'menu-enable '(and mark-active (not buffer-read-only)))
271 (put 'menu-bar-kill-ring-save 'menu-enable 'mark-active)
272 (put 'yank 'menu-enable '(and (x-selection-exists-p) (not buffer-read-only)))
273 (put 'yank-menu 'menu-enable '(and (cdr yank-menu) (not buffer-read-only)))
274 (put 'delete-region 'menu-enable '(and mark-active
275 (not buffer-read-only)
276 (not (mouse-region-match))))
277 (put 'undo 'menu-enable '(and (not buffer-read-only)
278 (if (eq last-command 'undo)
279 pending-undo-list
280 (consp buffer-undo-list))))
281 (put 'query-replace 'menu-enable '(not buffer-read-only))
282 (put 'query-replace-regexp 'menu-enable '(not buffer-read-only))
284 (autoload 'ispell-menu-map "ispell" nil t 'keymap)
286 ;; These are alternative definitions for the cut, paste and copy
287 ;; menu items. Use them if your system expects these to use the clipboard.
289 (put 'clipboard-kill-region 'menu-enable 'mark-active)
290 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
291 (put 'clipboard-yank 'menu-enable
292 '(or (x-selection-exists-p) (x-selection-exists-p 'CLIPBOARD)))
294 (defun clipboard-yank ()
295 "Reinsert the last stretch of killed text, or the clipboard contents."
296 (interactive)
297 (let ((x-select-enable-clipboard t))
298 (yank)))
300 (defun clipboard-kill-ring-save (beg end)
301 "Copy region to kill ring, and save in the X clipboard."
302 (interactive "r")
303 (let ((x-select-enable-clipboard t))
304 (kill-ring-save beg end)))
306 (defun clipboard-kill-region (beg end)
307 "Kill the region, and save it in the X clipboard."
308 (interactive "r")
309 (let ((x-select-enable-clipboard t))
310 (kill-region beg end)))
312 (defun menu-bar-enable-clipboard ()
313 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
314 Do the same for the keys of the same name."
315 (interactive)
316 ;; We can't use constant list structure here because it becomes pure,
317 ;; and because it gets modified with cache data.
318 (define-key menu-bar-edit-menu [paste]
319 (cons "Paste" 'clipboard-yank))
320 (define-key menu-bar-edit-menu [copy]
321 (cons "Copy" 'clipboard-kill-ring-save))
322 (define-key menu-bar-edit-menu [cut]
323 (cons "Cut" 'clipboard-kill-region))
325 (define-key global-map [f20] 'clipboard-kill-region)
326 (define-key global-map [f16] 'clipboard-kill-ring-save)
327 (define-key global-map [f18] 'clipboard-yank)
328 ;; X11R6 versions
329 (define-key global-map [cut] 'clipboard-kill-region)
330 (define-key global-map [copy] 'clipboard-kill-ring-save)
331 (define-key global-map [paste] 'clipboard-yank))
334 ;;; Menu support
336 (defvar menu-bar-custom-menu (make-sparse-keymap "Customize"))
338 (define-key menu-bar-custom-menu [custom-menu-update]
339 '("Update This Menu" . custom-menu-update))
340 (define-key menu-bar-custom-menu [customize-apropos]
341 '("Apropos..." . customize-apropos))
342 (define-key menu-bar-custom-menu [customize-group]
343 '("Specific Group..." . customize-group))
344 (define-key menu-bar-custom-menu [customize-face]
345 '("Specific Face..." . customize-face))
346 (define-key menu-bar-custom-menu [customize-variable]
347 '("Specific Variable..." . customize-variable))
348 (define-key menu-bar-custom-menu [customize]
349 '("Browse Hierarchy of User Options" . customize))
351 (define-key menu-bar-help-menu [emacs-version]
352 '("Show Version" . emacs-version))
353 (define-key menu-bar-help-menu [report-emacs-bug]
354 '("Send Bug Report..." . report-emacs-bug))
355 (define-key menu-bar-help-menu [finder-by-keyword]
356 '("Find Lisp Packages..." . finder-by-keyword))
357 (define-key menu-bar-help-menu [emacs-tutorial]
358 '("Emacs Tutorial" . help-with-tutorial))
359 (define-key menu-bar-help-menu [man]
360 '("Man..." . manual-entry))
361 (define-key menu-bar-help-menu [describe-variable]
362 '("Describe Variable..." . describe-variable))
363 (define-key menu-bar-help-menu [describe-function]
364 '("Describe Function..." . describe-function))
365 (define-key menu-bar-help-menu [describe-key]
366 '("Describe Key..." . describe-key))
367 (define-key menu-bar-help-menu [list-keybindings]
368 '("List Keybindings" . describe-bindings))
369 (define-key menu-bar-help-menu [command-apropos]
370 '("Command Apropos..." . command-apropos))
371 (define-key menu-bar-help-menu [describe-mode]
372 '("Describe Mode" . describe-mode))
373 (define-key menu-bar-help-menu [info] '("Browse Manuals" . info))
374 (define-key menu-bar-help-menu [emacs-faq] '("Emacs FAQ" . view-emacs-FAQ))
375 (define-key menu-bar-help-menu [emacs-news] '("Emacs News" . view-emacs-news))
376 (define-key menu-bar-help-menu [customize-menu]
377 (cons "Customize" menu-bar-custom-menu))
379 (defun kill-this-buffer () ; for the menubar
380 "Kills the current buffer."
381 (interactive)
382 (kill-buffer (current-buffer)))
384 (defun kill-this-buffer-enabled-p ()
385 (let ((count 0)
386 (buffers (buffer-list)))
387 (while buffers
388 (or (string-match "^ " (buffer-name (car buffers)))
389 (setq count (1+ count)))
390 (setq buffers (cdr buffers)))
391 (and (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
392 (> count 1))))
394 (put 'kill-this-buffer 'menu-enable '(kill-this-buffer-enabled-p))
396 (put 'save-buffer 'menu-enable
397 '(and (buffer-modified-p)
398 (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))))
400 (put 'write-file 'menu-enable
401 '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
403 (put 'find-file 'menu-enable
404 '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
406 (put 'dired 'menu-enable
407 '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
409 (put 'insert-file 'menu-enable
410 '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
412 (put 'revert-buffer 'menu-enable
413 '(or revert-buffer-function revert-buffer-insert-file-contents-function
414 (and (buffer-file-name)
415 (or (buffer-modified-p)
416 (not (verify-visited-file-modtime (current-buffer)))))))
418 ;; Permit deleting frame if it would leave a visible or iconified frame.
419 (put 'delete-frame 'menu-enable
420 '(delete-frame-enabled-p))
422 (defun delete-frame-enabled-p ()
423 "Return non-nil if `delete-frame' should be enabled in the menu bar."
424 (let ((frames (frame-list))
425 (count 0))
426 (while frames
427 (if (frame-visible-p (car frames))
428 (setq count (1+ count)))
429 (setq frames (cdr frames)))
430 (> count 1)))
432 (put 'advertised-undo 'menu-enable
433 '(and (not (eq t buffer-undo-list))
434 (if (eq last-command 'undo)
435 (and (boundp 'pending-undo-list)
436 pending-undo-list)
437 buffer-undo-list)))
439 (defcustom yank-menu-length 20
440 "*Maximum length to display in the yank-menu."
441 :type 'integer
442 :group 'mouse)
444 (defun menu-bar-update-yank-menu (string old)
445 (let ((front (car (cdr yank-menu)))
446 (menu-string (if (<= (length string) yank-menu-length)
447 string
448 (concat
449 (substring string 0 (/ yank-menu-length 2))
450 "..."
451 (substring string (- (/ yank-menu-length 2)))))))
452 ;; Don't let the menu string be all dashes
453 ;; because that has a special meaning in a menu.
454 (if (string-match "\\`-+\\'" menu-string)
455 (setq menu-string (concat menu-string " ")))
456 ;; If we're supposed to be extending an existing string, and that
457 ;; string really is at the front of the menu, then update it in place.
458 (if (and old (or (eq old (car front))
459 (string= old (car front))))
460 (progn
461 (setcar front string)
462 (setcar (cdr front) menu-string))
463 (setcdr yank-menu
464 (cons
465 (cons string (cons menu-string 'menu-bar-select-yank))
466 (cdr yank-menu)))))
467 (if (> (length (cdr yank-menu)) kill-ring-max)
468 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
470 (defun menu-bar-select-yank ()
471 (interactive "*")
472 (push-mark (point))
473 (insert last-command-event))
475 ;; This definition is just to show what this looks like.
476 ;; It gets overridden below when menu-bar-update-buffers is called.
477 (define-key global-map [menu-bar buffer]
478 (cons "Buffers" (make-sparse-keymap "Buffers")))
480 (defvar list-buffers-directory nil)
482 (defvar menu-bar-update-buffers-maxbuf)
484 (defun menu-bar-select-buffer ()
485 (interactive)
486 (switch-to-buffer last-command-event))
488 (defun menu-bar-select-frame ()
489 (interactive)
490 (make-frame-visible last-command-event)
491 (raise-frame last-command-event)
492 (select-frame last-command-event))
494 (defun menu-bar-update-buffers-1 (elt)
495 (cons (format
496 (format "%%%ds %%s%%s %%s" menu-bar-update-buffers-maxbuf)
497 (cdr elt)
498 (if (buffer-modified-p (car elt))
499 "*" " ")
500 (save-excursion
501 (set-buffer (car elt))
502 (if buffer-read-only "%" " "))
503 (let ((file
504 (or (buffer-file-name (car elt))
505 (save-excursion
506 (set-buffer (car elt))
507 list-buffers-directory)
508 "")))
509 (setq file (or (file-name-directory file)
510 ""))
511 (if (> (length file) 20)
512 (setq file (concat "..." (substring file -17))))
513 file))
514 (car elt)))
516 (defvar menu-bar-buffers-menu-list-buffers-entry nil)
518 (defun menu-bar-update-buffers ()
519 ;; If user discards the Buffers item, play along.
520 (and (lookup-key (current-global-map) [menu-bar buffer])
521 (frame-or-buffer-changed-p)
522 (let ((buffers (buffer-list))
523 (frames (frame-list))
524 (maxlen 0)
525 buffers-menu frames-menu)
526 ;; If requested, list only the N most recently selected buffers.
527 (if (and (integerp buffers-menu-max-size)
528 (> buffers-menu-max-size 1))
529 (if (> (length buffers) buffers-menu-max-size)
530 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
532 ;; Make the menu of buffers proper.
533 (setq buffers-menu
534 (cons "Select Buffer"
535 (let* ((buffer-list
536 (mapcar 'list buffers))
537 tail
538 (menu-bar-update-buffers-maxbuf 0)
539 alist
540 head)
541 ;; Put into each element of buffer-list
542 ;; the name for actual display,
543 ;; perhaps truncated in the middle.
544 (setq tail buffer-list)
545 (while tail
546 (let ((name (buffer-name (car (car tail)))))
547 (setcdr (car tail)
548 (if (> (length name) 27)
549 (concat (substring name 0 12)
550 "..."
551 (substring name -12))
552 name)))
553 (setq tail (cdr tail)))
554 ;; Compute the maximum length of any name.
555 (setq tail buffer-list)
556 (while tail
557 (or (eq ?\ (aref (cdr (car tail)) 0))
558 (setq menu-bar-update-buffers-maxbuf
559 (max menu-bar-update-buffers-maxbuf
560 (length (cdr (car tail))))))
561 (setq tail (cdr tail)))
562 ;; Set ALIST to an alist of the form
563 ;; ITEM-STRING . BUFFER
564 (setq tail buffer-list)
565 (while tail
566 (let ((elt (car tail)))
567 (or (eq ?\ (aref (cdr elt) 0))
568 (setq alist (cons
569 (menu-bar-update-buffers-1 elt)
570 alist)))
571 (and alist (> (length (car (car alist))) maxlen)
572 (setq maxlen (length (car (car alist))))))
573 (setq tail (cdr tail)))
574 (setq alist (nreverse alist))
575 ;; Make the menu item for list-buffers
576 ;; or reuse the one we already have.
577 ;; The advantage in reusing one
578 ;; is that it already has the keyboard equivalent
579 ;; cached, so we save the time to look that up again.
580 (or menu-bar-buffers-menu-list-buffers-entry
581 (setq menu-bar-buffers-menu-list-buffers-entry
582 (cons
583 'list-buffers
584 (cons
586 'list-buffers))))
587 ;; Update the item string for menu's new width.
588 (setcar (cdr menu-bar-buffers-menu-list-buffers-entry)
589 (concat (make-string (max (- (/ maxlen 2) 8) 0)
590 ?\ )
591 "List All Buffers"))
592 ;; Now make the actual list of items,
593 ;; ending with the list-buffers item.
594 (nconc (mapcar '(lambda (pair)
595 ;; This is somewhat risque, to use
596 ;; the buffer name itself as the event
597 ;; type to define, but it works.
598 ;; It would not work to use the buffer
599 ;; since a buffer as an event has its
600 ;; own meaning.
601 (nconc (list (buffer-name (cdr pair))
602 (car pair)
603 (cons nil nil))
604 'menu-bar-select-buffer))
605 alist)
606 (list menu-bar-buffers-menu-list-buffers-entry)))))
609 ;; Make a Frames menu if we have more than one frame.
610 (if (cdr frames)
611 (let ((name (concat (make-string (max (- (/ maxlen 2) 3) 0)
612 ?\ )
613 "Frames"))
614 (frames-menu
615 (cons 'keymap
616 (cons "Select Frame"
617 (mapcar '(lambda (frame)
618 (nconc (list frame
619 (cdr (assq 'name
620 (frame-parameters frame)))
621 (cons nil nil))
622 'menu-bar-select-frame))
623 frames)))))
624 ;; Put it underneath the Buffers menu.
625 (setq buffers-menu (cons (cons 'frames (cons name frames-menu))
626 buffers-menu))))
627 (if buffers-menu
628 (setq buffers-menu (cons 'keymap buffers-menu)))
629 (define-key (current-global-map) [menu-bar buffer]
630 (cons "Buffers" buffers-menu)))))
632 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
634 (menu-bar-update-buffers)
636 ;; this version is too slow
637 ;;;(defun format-buffers-menu-line (buffer)
638 ;;; "Returns a string to represent the given buffer in the Buffer menu.
639 ;;;nil means the buffer shouldn't be listed. You can redefine this."
640 ;;; (if (string-match "\\` " (buffer-name buffer))
641 ;;; nil
642 ;;; (save-excursion
643 ;;; (set-buffer buffer)
644 ;;; (let ((size (buffer-size)))
645 ;;; (format "%s%s %-19s %6s %-15s %s"
646 ;;; (if (buffer-modified-p) "*" " ")
647 ;;; (if buffer-read-only "%" " ")
648 ;;; (buffer-name)
649 ;;; size
650 ;;; mode-name
651 ;;; (or (buffer-file-name) ""))))))
653 ;;; Set up a menu bar menu for the minibuffer.
655 (mapcar
656 (function
657 (lambda (map)
658 (define-key map [menu-bar minibuf]
659 (cons "Minibuf" (make-sparse-keymap "Minibuf")))))
660 (list minibuffer-local-ns-map
661 minibuffer-local-must-match-map
662 minibuffer-local-isearch-map
663 minibuffer-local-map
664 minibuffer-local-completion-map))
666 (mapcar
667 (function
668 (lambda (map)
669 (define-key map [menu-bar minibuf ?\?]
670 '("List Completions" . minibuffer-completion-help))
671 (define-key map [menu-bar minibuf space]
672 '("Complete Word" . minibuffer-complete-word))
673 (define-key map [menu-bar minibuf tab]
674 '("Complete" . minibuffer-complete))
676 (list minibuffer-local-must-match-map
677 minibuffer-local-completion-map))
679 (mapcar
680 (function
681 (lambda (map)
682 (define-key map [menu-bar minibuf quit]
683 '("Quit" . keyboard-escape-quit))
684 (define-key map [menu-bar minibuf return]
685 '("Enter" . exit-minibuffer))
687 (list minibuffer-local-ns-map
688 minibuffer-local-must-match-map
689 minibuffer-local-isearch-map
690 minibuffer-local-map
691 minibuffer-local-completion-map))
693 (defvar menu-bar-mode nil)
695 (defun menu-bar-mode (flag)
696 "Toggle display of a menu bar on each frame.
697 This command applies to all frames that exist and frames to be
698 created in the future.
699 With a numeric argument, if the argument is negative,
700 turn off menu bars; otherwise, turn on menu bars."
701 (interactive "P")
703 ;; Make menu-bar-mode and default-frame-alist consistent.
704 (let ((default (assq 'menu-bar-lines default-frame-alist)))
705 (if default
706 (setq menu-bar-mode (not (eq (cdr default) 0)))
707 (setq default-frame-alist
708 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
709 default-frame-alist))))
711 ;; Toggle or set the mode, according to FLAG.
712 (setq menu-bar-mode (if (null flag) (not menu-bar-mode)
713 (> (prefix-numeric-value flag) 0)))
715 ;; Apply it to default-frame-alist.
716 (let ((parameter (assq 'menu-bar-lines default-frame-alist)))
717 (if (consp parameter)
718 (setcdr parameter (if menu-bar-mode 1 0))
719 (setq default-frame-alist
720 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
721 default-frame-alist))))
723 ;; Apply it to existing frames.
724 (let ((frames (frame-list)))
725 (while frames
726 (let ((height (cdr (assq 'height (frame-parameters (car frames))))))
727 (modify-frame-parameters (car frames)
728 (list (cons 'menu-bar-lines
729 (if menu-bar-mode 1 0))))
730 (modify-frame-parameters (car frames)
731 (list (cons 'height height))))
732 (setq frames (cdr frames)))))
734 (provide 'menu-bar)
736 ;;; menu-bar.el ends here