mapc
[bpt/emacs.git] / lisp / menu-bar.el
CommitLineData
235aa29b
ER
1;;; menu-bar.el --- define a default menu bar.
2
b578f267
EN
3;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
4
235aa29b 5;; Author: RMS
e4874521 6;; Maintainer: FSF
b7f66977 7;; Keywords: internal
235aa29b 8
1db87953
RS
9;; This file is part of GNU Emacs.
10
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.
15
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.
20
21;; You should have received a copy of the GNU General Public License
b578f267
EN
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.
1db87953 25
260130bb
KH
26;; Avishai Yacobi suggested some menu rearrangements.
27
b578f267
EN
28;;; Code:
29
d537086b
RS
30;;; User options:
31
30e19aee 32(defcustom buffers-menu-max-size 10
d537086b
RS
33 "*Maximum number of entries which may appear on the Buffers menu.
34If this is 10, then only the ten most-recently-selected buffers are shown.
35If this is nil, then all buffers are shown.
30e19aee
RS
36A large number or nil slows down menu responsiveness."
37 :type '(choice integer
38 (const :tag "All" nil))
39 :group 'mouse)
d537086b 40
b132f2b1
RM
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")))
22390f50 45(defvar menu-bar-help-menu (make-sparse-keymap "Help"))
ffbdd83d
RS
46
47;; Force Help item to come last, after the major mode's own items.
0d31efcd
KH
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))
ffbdd83d 51
0d31efcd 52(define-key global-map [menu-bar help-menu] (cons "Help" menu-bar-help-menu))
ffbdd83d
RS
53(defvar menu-bar-tools-menu (make-sparse-keymap "Tools"))
54(define-key global-map [menu-bar tools] (cons "Tools" menu-bar-tools-menu))
7f315c7c
EZ
55;; This definition is just to show what this looks like.
56;; It gets overridden below when menu-bar-update-buffers is called.
57(define-key global-map [menu-bar buffer]
58 (cons "Buffers" (make-sparse-keymap "Buffers")))
59(defvar menu-bar-options-menu (make-sparse-keymap "Options"))
60(define-key global-map [menu-bar options]
61 (cons "Options" menu-bar-options-menu))
62(defvar menu-bar-edit-menu (make-sparse-keymap "Edit"))
63(define-key global-map [menu-bar edit] (cons "Edit" menu-bar-edit-menu))
64(defvar menu-bar-files-menu (make-sparse-keymap "File"))
65(define-key global-map [menu-bar files] (cons "File" menu-bar-files-menu))
1b009b97
RS
66
67;; This alias is for compatibility with 19.28 and before.
68(defvar menu-bar-file-menu menu-bar-files-menu)
9bb8e471 69\f
7f315c7c 70;; The "File" menu items
ffbdd83d 71(define-key menu-bar-files-menu [exit-emacs]
7f315c7c
EZ
72 '(menu-item "Exit Emacs" save-buffers-kill-emacs
73 :help "Save unsaved buffers, then exit"))
ffbdd83d
RS
74
75(define-key menu-bar-files-menu [separator-exit]
76 '("--"))
77
7f315c7c
EZ
78;; Don't use delete-frame as event name because that is a special
79;; event.
80(define-key menu-bar-files-menu [delete-this-frame]
81 '(menu-item "Delete Frame" delete-frame
82 :visible (fboundp 'delete-frame)
83 :enable (delete-frame-enabled-p)
84 :help "Delete currently selected frame"))
85(define-key menu-bar-files-menu [make-frame-on-display]
86 '(menu-item "New Frame on Display..." make-frame-on-display
87 :visible (fboundp 'make-frame-on-display)
88 :help "Open a new frame on another display"))
89(define-key menu-bar-files-menu [make-frame]
90 '(menu-item "New Frame" make-frame-command
91 :visible (fboundp 'make-frame-command)
92 :help "Open a new frame"))
93
ffbdd83d 94(define-key menu-bar-files-menu [one-window]
7f315c7c
EZ
95 '(menu-item "Unsplit Windows" delete-other-windows
96 :enable (not (one-window-p t nil))
97 :help "Make selected window fill its frame"))
ffbdd83d
RS
98
99(define-key menu-bar-files-menu [split-window]
7f315c7c
EZ
100 '(menu-item "Split Window" split-window-vertically
101 :help "Split selected window in two"))
102
103(define-key menu-bar-files-menu [separator-window]
104 '(menu-item "--"))
105
106(define-key menu-bar-files-menu [ps-print-region]
107 '(menu-item "Postscript Print Region" ps-print-region-with-faces
108 :enable mark-active
109 :help "Pretty-print marked region to PostScript printer"))
110(define-key menu-bar-files-menu [ps-print-buffer]
111 '(menu-item "Postscript Print Buffer" ps-print-buffer-with-faces
112 :help "Pretty-print current buffer to PostScript printer"))
113(define-key menu-bar-files-menu [print-region]
114 '(menu-item "Print Region" print-region
115 :enable mark-active
116 :help "Print region between mark and current position"))
117(define-key menu-bar-files-menu [print-buffer]
118 '(menu-item "Print Buffer" print-buffer
119 :help "Print current buffer with page headings"))
120
121(define-key menu-bar-files-menu [separator-print]
122 '(menu-item "--"))
9bb8e471 123
f3e1e0dd 124(define-key menu-bar-files-menu [recover-session]
7f315c7c
EZ
125 '(menu-item "Recover Crashed Session..." recover-session
126 :enable (and auto-save-list-file-prefix
127 (directory-files
128 (file-name-directory auto-save-list-file-prefix)
129 nil
130 (concat "\\`"
131 (regexp-quote
132 (file-name-nondirectory
133 auto-save-list-file-prefix)))
134 t))
135 :help "Recover edits from a crashed session"))
ffbdd83d 136(define-key menu-bar-files-menu [revert-buffer]
7f315c7c
EZ
137 '(menu-item "Revert Buffer" revert-buffer
138 :enable (or revert-buffer-function
139 revert-buffer-insert-file-contents-function
140 (and (buffer-file-name)
141 (or (buffer-modified-p)
142 (not (verify-visited-file-modtime
143 (current-buffer))))))
144 :help "Re-read current buffer from its file"))
ffbdd83d 145(define-key menu-bar-files-menu [write-file]
7f315c7c
EZ
146 '(menu-item "Save Buffer As..." write-file
147 :enable (not (window-minibuffer-p
148 (frame-selected-window menu-updating-frame)))
149 :help "Write current buffer to another file"))
150(define-key menu-bar-files-menu [save-buffer]
151 '(menu-item "Save (current buffer)" save-buffer
152 :enable (and (buffer-modified-p)
153 (not (window-minibuffer-p
154 (frame-selected-window menu-updating-frame))))
155 :help "Save current buffer to its file"))
156
157(define-key menu-bar-files-menu [separator-save]
158 '(menu-item "--"))
159
160(define-key menu-bar-files-menu [kill-buffer]
161 '(menu-item "Close (current buffer)" kill-this-buffer
162 :enable (kill-this-buffer-enabled-p)
163 :help "Discard contents of current buffer"))
164(define-key menu-bar-files-menu [insert-file]
165 '(menu-item "Insert File..." insert-file
166 :enable (not (window-minibuffer-p
167 (frame-selected-window menu-updating-frame)))
168 :help "Insert another file into current buffer"))
169(define-key menu-bar-files-menu [dired]
170 '(menu-item "Open Directory..." dired
171 :help "Read a directory, operate on its files"))
172(define-key menu-bar-files-menu [open-file]
173 '(menu-item "Open File..." find-file
174 :enable (not (window-minibuffer-p
175 (frame-selected-window menu-updating-frame)))
176 :help "Read a file into an Emacs buffer"))
177
9bb8e471 178\f
7f315c7c 179;; The "Edit" menu items
ffbdd83d
RS
180(defun nonincremental-search-forward (string)
181 "Read a string and search for it nonincrementally."
182 (interactive "sSearch for string: ")
183 (if (equal string "")
184 (search-forward (car search-ring))
185 (isearch-update-ring string nil)
186 (search-forward string)))
187
188(defun nonincremental-search-backward (string)
189 "Read a string and search backward for it nonincrementally."
190 (interactive "sSearch for string: ")
191 (if (equal string "")
192 (search-backward (car search-ring))
193 (isearch-update-ring string nil)
194 (search-backward string)))
195
196(defun nonincremental-re-search-forward (string)
197 "Read a regular expression and search for it nonincrementally."
198 (interactive "sSearch for regexp: ")
199 (if (equal string "")
200 (re-search-forward (car regexp-search-ring))
201 (isearch-update-ring string t)
202 (re-search-forward string)))
203
204(defun nonincremental-re-search-backward (string)
205 "Read a regular expression and search backward for it nonincrementally."
206 (interactive "sSearch for regexp: ")
207 (if (equal string "")
208 (re-search-backward (car regexp-search-ring))
209 (isearch-update-ring string t)
210 (re-search-backward string)))
211
1f50590a 212(defun nonincremental-repeat-search-forward ()
ffbdd83d
RS
213 "Search forward for the previous search string."
214 (interactive)
008c8493
RS
215 (if (null search-ring)
216 (error "No previous search"))
ffbdd83d
RS
217 (search-forward (car search-ring)))
218
1f50590a 219(defun nonincremental-repeat-search-backward ()
ffbdd83d
RS
220 "Search backward for the previous search string."
221 (interactive)
008c8493
RS
222 (if (null search-ring)
223 (error "No previous search"))
ffbdd83d
RS
224 (search-backward (car search-ring)))
225
1f50590a 226(defun nonincremental-repeat-re-search-forward ()
ffbdd83d
RS
227 "Search forward for the previous regular expression."
228 (interactive)
97565dd9 229 (if (null regexp-search-ring)
008c8493 230 (error "No previous search"))
ffbdd83d
RS
231 (re-search-forward (car regexp-search-ring)))
232
1f50590a 233(defun nonincremental-repeat-re-search-backward ()
ffbdd83d
RS
234 "Search backward for the previous regular expression."
235 (interactive)
97565dd9 236 (if (null regexp-search-ring)
008c8493 237 (error "No previous search"))
ffbdd83d
RS
238 (re-search-backward (car regexp-search-ring)))
239
7f315c7c
EZ
240(defvar menu-bar-search-menu (make-sparse-keymap "Search"))
241(defvar menu-bar-adv-search-menu
242 (make-sparse-keymap "Advanced Search/Replace"))
243
244(define-key menu-bar-adv-search-menu [tags-continue]
245 '(menu-item "Continue Tags Search/Replace" tags-loop-continue
246 :help "Continue last tags search/replace operation"))
247(define-key menu-bar-adv-search-menu [tags-repl]
248 '(menu-item "Replace in all tagged files" tags-query-replace
249 :help "Interactively replace a regexp in all tagged files"))
250(define-key menu-bar-adv-search-menu [tags-srch]
251 '(menu-item "Search in all tagged files" tags-search
252 :help "Search for a regexp in all tagged files"))
253
254(define-key menu-bar-adv-search-menu [separator-tag-search]
255 '(menu-item "--"))
256
257(define-key menu-bar-adv-search-menu [query-replace-regexp]
258 '(menu-item "Replace Regexp..." query-replace-regexp
259 :enable (not buffer-read-only)
260 :help "Replace regular expression, ask about each occurrence"))
261(define-key menu-bar-adv-search-menu [repeat-regexp-back]
262 '(menu-item "Repeat Regexp Backwards"
263 nonincremental-repeat-re-search-backward
264 :enable regexp-search-ring
265 :help "Repeat last regular expression search backwards"))
266(define-key menu-bar-adv-search-menu [repeat-regexp-fwd]
267 '(menu-item "Repeat Regexp" nonincremental-repeat-re-search-forward
268 :enable regexp-search-ring
269 :help "Repeat last regular expression search forward"))
270(define-key menu-bar-adv-search-menu [re-search-backward]
271 '(menu-item "Search Regexp Backwards..." nonincremental-re-search-backward
272 :help "Search backwards for a regular expression"))
273(define-key menu-bar-adv-search-menu [re-search-forward]
274 '(menu-item "Search Regexp..." nonincremental-re-search-forward
275 :help "Search forward for a regular expression"))
276(define-key menu-bar-search-menu [re-search]
277 (list 'menu-item "Advanced Search/Replace" menu-bar-adv-search-menu
278 :help "Regexp and Tags search and replace"))
ffbdd83d 279
7f315c7c
EZ
280(define-key menu-bar-search-menu [query-replace]
281 '(menu-item "Replace..." query-replace
282 :enable (not buffer-read-only)
283 :help "Replace string interactively, ask about each occurrence"))
fe74180c 284(define-key menu-bar-search-menu [repeat-search-back]
7f315c7c
EZ
285 '(menu-item "Repeat Backwards" nonincremental-repeat-search-backward
286 :enable search-ring
287 :help "Repeat last search backwards"))
fe74180c 288(define-key menu-bar-search-menu [repeat-search-fwd]
7f315c7c
EZ
289 '(menu-item "Repeat Search" nonincremental-repeat-search-forward
290 :enable search-ring
291 :help "Repeat last search forward"))
fe74180c 292(define-key menu-bar-search-menu [search-backward]
7f315c7c
EZ
293 '(menu-item "Search Backwards..." nonincremental-search-backward
294 :help "Search backwards for a string"))
fe74180c 295(define-key menu-bar-search-menu [search-forward]
7f315c7c
EZ
296 '(menu-item "Search..." nonincremental-search-forward
297 :help "Search forward for a string"))
9bb8e471 298
7f315c7c
EZ
299;;; Assemble the top-level Edit menu items.
300(define-key menu-bar-edit-menu [props]
301 '(menu-item "Text Properties" facemenu-menu
302 :help "Change properties of text in region"))
3dd92899 303
7f315c7c
EZ
304(define-key menu-bar-search-menu [separator-search]
305 '(menu-item "--"))
306
307(define-key menu-bar-edit-menu [bookmark]
308 '(menu-item "Bookmarks" menu-bar-bookmark-map
309 :help "Record positions and jump between them"))
310
311(define-key menu-bar-edit-menu [separator-bookmark]
312 '(menu-item "--"))
313
314(defvar menu-bar-goto-menu (make-sparse-keymap "Go To"))
315
316(define-key menu-bar-goto-menu [set-tags-name]
317 '(menu-item "Set Tags File Name" visit-tags-table
318 :help "Tell Tags commands which tag table file to use"))
319
320(define-key menu-bar-goto-menu [separator-tag-file]
321 '(menu-item "--"))
322
323(define-key menu-bar-goto-menu [apropos-tags]
324 '(menu-item "Tags Apropos" tags-apropos
325 :help "Find function/variables whose names match regexp"))
326(define-key menu-bar-goto-menu [next-tag-otherw]
327 '(menu-item "Next Tag in Other Window"
328 (function (lambda () (find-tag-other-window nil t)))
0ae27881
EZ
329 :enable (and (boundp 'tags-location-ring)
330 (not (ring-empty-p tags-location-ring)))
7f315c7c
EZ
331 :help "Find next function/variable matching last tag name in another window"))
332(define-key menu-bar-goto-menu [next-tag]
333 '(menu-item "Find Next Tag"
334 (function (lambda () (find-tag nil t)))
0ae27881
EZ
335 :enable (and (boundp 'tags-location-ring)
336 (not (ring-empty-p tags-location-ring)))
7f315c7c
EZ
337 :help "Find next function/variable matching last tag name"))
338(define-key menu-bar-goto-menu [find-tag-otherw]
339 '(menu-item "Find Tag in Other Window..." find-tag-other-window
340 :help "Find function/variable definition in another window"))
341(define-key menu-bar-goto-menu [find-tag]
342 '(menu-item "Find Tag..." find-tag
343 :help "Find definition of function or variable"))
344
345(define-key menu-bar-goto-menu [separator-tags]
346 '(menu-item "--"))
347
348(define-key menu-bar-goto-menu [end-of-buf]
349 '(menu-item "Goto End of Buffer" end-of-buffer))
350(define-key menu-bar-goto-menu [beg-of-buf]
351 '(menu-item "Goto Beginning of Buffer" beginning-of-buffer))
352(define-key menu-bar-goto-menu [go-to-pos]
353 '(menu-item "Goto Buffer Position..." goto-char
354 :help "Read a number N and go to buffer position N"))
355(define-key menu-bar-goto-menu [go-to-line]
356 '(menu-item "Goto Line..." goto-line
357 :help "Read a line number and go to that line"))
358
359(define-key menu-bar-edit-menu [goto]
360 (list 'menu-item "Go To" menu-bar-goto-menu))
361
362(define-key menu-bar-edit-menu [search]
363 (list 'menu-item "Search" menu-bar-search-menu))
364
365(define-key menu-bar-edit-menu [fill]
366 '(menu-item "Fill" fill-region
367 :enable (and mark-active (not buffer-read-only))
368 :help
369 "Fill text in region to fit between left and right margin"))
370(define-key menu-bar-edit-menu [clear]
371 '(menu-item "Clear" delete-region
372 :enable (and mark-active
373 (not buffer-read-only)
374 (not (mouse-region-match)))
375 :help
376 "Delete the text in region between mark and current pos"))
3dd92899
KH
377(defvar yank-menu (cons "Select Yank" nil))
378(fset 'yank-menu (cons 'keymap yank-menu))
7f315c7c
EZ
379(define-key menu-bar-edit-menu [select-paste]
380 '(menu-item "Select and Paste" yank-menu
381 :enable (and (cdr yank-menu) (not buffer-read-only))
382 :help "Paste text cut/copied earlier"))
383(define-key menu-bar-edit-menu [paste]
384 '(menu-item "Paste" yank
385 :enable (and (x-selection-exists-p) (not buffer-read-only))
386 :help "Paste text most recently cut/copied"))
387(define-key menu-bar-edit-menu [copy]
388 '(menu-item "Copy" menu-bar-kill-ring-save
389 :enable mark-active
390 :help "Copy text in region between mark and current pos"))
391(define-key menu-bar-edit-menu [cut]
392 '(menu-item "Cut" kill-region
393 :enable (and mark-active (not buffer-read-only))
394 :help "Cut (kill) text in region between mark and current pos"))
395(define-key menu-bar-edit-menu [undo]
396 '(menu-item "Undo" undo
397 :enable (and (not buffer-read-only)
398 (not (eq t buffer-undo-list))
399 (if (eq last-command 'undo)
400 pending-undo-list
401 (consp buffer-undo-list)))
402 :help "Undo last operation"))
403
057d49d1 404
4c0317b1
RS
405(defun menu-bar-kill-ring-save (beg end)
406 (interactive "r")
407 (if (mouse-region-match)
b1a4cc61 408 (message "Selecting a region with the mouse does `copy' automatically")
4c0317b1
RS
409 (kill-ring-save beg end)))
410
9e18f0a0
RS
411(autoload 'ispell-menu-map "ispell" nil t 'keymap)
412
f9cf0be2 413;; These are alternative definitions for the cut, paste and copy
4c0317b1 414;; menu items. Use them if your system expects these to use the clipboard.
f9cf0be2 415
f9cf0be2
RS
416(put 'clipboard-kill-region 'menu-enable 'mark-active)
417(put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
418(put 'clipboard-yank 'menu-enable
419 '(or (x-selection-exists-p) (x-selection-exists-p 'CLIPBOARD)))
420
421(defun clipboard-yank ()
ee497664 422 "Insert the clipboard contents, or the last stretch of killed text."
f9cf0be2
RS
423 (interactive)
424 (let ((x-select-enable-clipboard t))
425 (yank)))
426
427(defun clipboard-kill-ring-save (beg end)
428 "Copy region to kill ring, and save in the X clipboard."
429 (interactive "r")
430 (let ((x-select-enable-clipboard t))
431 (kill-ring-save beg end)))
432
433(defun clipboard-kill-region (beg end)
434 "Kill the region, and save it in the X clipboard."
435 (interactive "r")
436 (let ((x-select-enable-clipboard t))
437 (kill-region beg end)))
438
439(defun menu-bar-enable-clipboard ()
5cbdeb30
RS
440 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
441Do the same for the keys of the same name."
f9cf0be2 442 (interactive)
5754d7f2
RS
443 ;; We can't use constant list structure here because it becomes pure,
444 ;; and because it gets modified with cache data.
445 (define-key menu-bar-edit-menu [paste]
7f315c7c 446 (cons "Paste" (cons "Paste text from clipboard" 'clipboard-yank)))
5754d7f2 447 (define-key menu-bar-edit-menu [copy]
7f315c7c
EZ
448 (cons "Copy" (cons "Copy text in region to the clipboard"
449 'clipboard-kill-ring-save)))
5754d7f2 450 (define-key menu-bar-edit-menu [cut]
7f315c7c
EZ
451 (cons "Cut" (cons "Delete text in region and copy it to the clipboard"
452 'clipboard-kill-region)))
5cbdeb30
RS
453
454 (define-key global-map [f20] 'clipboard-kill-region)
455 (define-key global-map [f16] 'clipboard-kill-ring-save)
456 (define-key global-map [f18] 'clipboard-yank)
457 ;; X11R6 versions
458 (define-key global-map [cut] 'clipboard-kill-region)
459 (define-key global-map [copy] 'clipboard-kill-ring-save)
460 (define-key global-map [paste] 'clipboard-yank))
f9cf0be2 461\f
7f315c7c 462;; The "Options" menu items
a9f53ffb
RS
463
464(defvar menu-bar-custom-menu (make-sparse-keymap "Customize"))
465
b0f661de 466(define-key menu-bar-custom-menu [customize-apropos-groups]
7f315c7c
EZ
467 '(menu-item "Groups Matching Regexp..." customize-apropos-groups
468 :help "Browse groups whose names match regexp"))
b0f661de 469(define-key menu-bar-custom-menu [customize-apropos-faces]
7f315c7c
EZ
470 '(menu-item "Faces Matching Regexp..." customize-apropos-faces
471 :help "Browse faces whose names match regexp"))
b0f661de 472(define-key menu-bar-custom-menu [customize-apropos-options]
7f315c7c
EZ
473 '(menu-item "Options Matching Regexp..." customize-apropos-options
474 :help "Browse options whose names match regexp"))
a9f53ffb 475(define-key menu-bar-custom-menu [customize-apropos]
7f315c7c
EZ
476 '(menu-item "Settings Matching Regexp..." customize-apropos
477 :help "Browse customizable settings whose names match regexp"))
b0f661de
RS
478(define-key menu-bar-custom-menu [separator-2]
479 '("--"))
c9a86e71 480(define-key menu-bar-custom-menu [customize-group]
7f315c7c
EZ
481 '(menu-item "Specific Group..." customize-group
482 :help "Customize settings of specific group"))
a9f53ffb 483(define-key menu-bar-custom-menu [customize-face]
7f315c7c
EZ
484 '(menu-item "Specific Face..." customize-face
485 :help "Customize attributes of specific face"))
b0f661de 486(define-key menu-bar-custom-menu [customize-option]
7f315c7c
EZ
487 '(menu-item "Specific Option..." customize-option
488 :help "Change value of specific option"))
6fe9c658 489(define-key menu-bar-custom-menu [customize-changed-options]
7f315c7c
EZ
490 '(menu-item "Recently Changed Options..." customize-changed-options
491 :help "Customize options changed in recent versions"))
b0f661de
RS
492(define-key menu-bar-custom-menu [separator-3]
493 '("--"))
e6354b3e 494(define-key menu-bar-custom-menu [customize-browse]
7f315c7c
EZ
495 '(menu-item "Browse Customization Groups" customize-browse
496 :help "Browse all customization groups"))
b0f661de 497(define-key menu-bar-custom-menu [customize]
7f315c7c
EZ
498 '(menu-item "Top-level Customization Group" customize
499 :help "The master group called `Emacs'"))
a9f53ffb 500
7f315c7c 501;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
bacb2d12 502
7f315c7c 503(defmacro menu-bar-make-toggle (name variable doc message help &rest body)
bacb2d12
RS
504 `(progn
505 (defun ,name ()
506 ,(concat doc ".")
507 (interactive)
508 (if ,(if body `(progn . ,body)
509 `(setq ,variable (not ,variable)))
510 (message ,message "enabled")
511 (message ,message "disabled")))
7f315c7c
EZ
512 '(menu-item ,doc ,name
513 :help ,help
514 :button (:toggle . (and (boundp ',variable) ,variable)))))
515
516;;; Assemble all the top-level items of the "Options" menu
517(define-key menu-bar-options-menu [customize]
518 (list 'menu-item "Customize Emacs" menu-bar-custom-menu
519 :help "Full customization of every Emacs feature"))
520(define-key menu-bar-options-menu [mule]
521 ;; It is better not to use backquote here,
522 ;; because that makes a bootstrapping problem
523 ;; if you need to recompile all the Lisp files using interpreted code.
524 (list 'menu-item "Mule (Multilingual Environment)" mule-menu-keymap
525 ':visible 'default-enable-multibyte-characters
526 ':help "Default language, encodings, input method"))
527;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
528;(define-key menu-bar-options-menu [preferences]
529; (list 'menu-item "Preferences" menu-bar-preferences-menu
530; :help "Toggle important global options"))
531
532(define-key menu-bar-options-menu [mule-separator]
533 '("------"))
bacb2d12
RS
534
535(define-key menu-bar-options-menu [debug-on-quit]
536 (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
7f315c7c
EZ
537 "Enter Debugger on Quit/C-g" "Debug on Quit %s"
538 "Enter Lisp debugger when C-g is pressed"))
bacb2d12
RS
539(define-key menu-bar-options-menu [debug-on-error]
540 (menu-bar-make-toggle toggle-debug-on-error debug-on-error
7f315c7c
EZ
541 "Enter Debugger on Error" "Debug on Error %s"
542 "Enter Lisp debugger when error is signaled"))
543(define-key menu-bar-options-menu [debugger-separator]
bacb2d12 544 '("--"))
7f315c7c
EZ
545(define-key menu-bar-options-menu [toggle-auto-compression]
546 '(menu-item "Automatic File De/compression"
547 auto-compression-mode
548 :help "Transparently decompress compressed files"
549 :button (:toggle . (rassq 'jka-compr-handler
550 file-name-handler-alist))))
bacb2d12
RS
551(define-key menu-bar-options-menu [save-place]
552 (menu-bar-make-toggle toggle-save-place-globally save-place
89f1709f 553 "Save Place in Files between Sessions"
bacb2d12 554 "Saving place in files %s"
7f315c7c 555 "Save Emacs state for next session"
89f1709f 556 (require 'saveplace)
bacb2d12
RS
557 (setq-default save-place (not (default-value save-place)))))
558(define-key menu-bar-options-menu [uniquify]
559 (menu-bar-make-toggle toggle-uniquify-buffer-names uniquify-buffer-name-style
89f1709f 560 "Use Directory Names in Buffer Names"
bacb2d12 561 "Directory name in buffer names (uniquify) %s"
7f315c7c 562 nil
bacb2d12
RS
563 (require 'uniquify)
564 (setq uniquify-buffer-name-style
565 (if (not uniquify-buffer-name-style)
566 'forward))))
7f315c7c
EZ
567(define-key menu-bar-options-menu [edit-options-separator]
568 '("--"))
3f51f129
RS
569(define-key menu-bar-options-menu [case-fold-search]
570 (menu-bar-make-toggle toggle-case-fold-search case-fold-search
7f315c7c
EZ
571 "Case-Insensitive Search"
572 "Case-Insensitive Search %s"
573 "If checked, search ignores letter-case"))
574(define-key menu-bar-options-menu [auto-fill-mode]
575 '(menu-item "Word Wrap in Text Modes (Auto Fill)"
576 toggle-text-mode-auto-fill
577 :help "Automatically fill text between left and right margins"
578 :button (:toggle . (member 'turn-on-auto-fill text-mode-hook))))
43c35fd7
RS
579(define-key menu-bar-options-menu [truncate-lines]
580 (menu-bar-make-toggle
581 toggle-truncate-lines truncate-lines
7f315c7c
EZ
582 "Truncate Long Lines" "Long Line Truncation %s"
583 "If checked, long lines are truncated on the screen"
43c35fd7
RS
584 (prog1 (setq truncate-lines (not truncate-lines))
585 (set-buffer-modified-p (buffer-modified-p)))))
7f315c7c
EZ
586(define-key menu-bar-options-menu [highlight-separator]
587 '("--"))
588(define-key menu-bar-options-menu [highlight-paren-mode]
589 (menu-bar-make-toggle toggle-highlight-paren-mode show-paren-mode
590 "Highlight Matching Parentheses"
591 "Show Paren mode %s"
592 "Highlight matching and mismatched parentheses"))
bacb2d12
RS
593(define-key menu-bar-options-menu [transient-mark-mode]
594 (menu-bar-make-toggle toggle-transient-mark-mode transient-mark-mode
89f1709f 595 "Transient Mark Mode (highlights region)"
7f315c7c
EZ
596 "Transient Mark mode %s"
597 "Highlight the marked region when it's active"))
8ad97b87 598(define-key menu-bar-options-menu [toggle-global-lazy-font-lock-mode]
89f1709f 599 (menu-bar-make-toggle toggle-global-lazy-font-lock-mode global-font-lock-mode
7f315c7c
EZ
600 "Highlight Syntax (Global Font Lock)"
601 "Syntax Highlighting %s"
602 "Highlights text based on language syntax"
8ad97b87
RS
603 ;; Make sure a support mode is used;
604 ;; otherwise Font Lock will be too slow.
21efd27b 605 (require 'font-lock)
8ad97b87
RS
606 (if (not global-font-lock-mode)
607 (or font-lock-support-mode
608 (setq font-lock-support-mode 'lazy-lock-mode)))
609 (global-font-lock-mode)))
7f315c7c
EZ
610
611
e5683624 612\f
7f315c7c
EZ
613;; The "Tools" menu items
614
615(defvar menu-bar-games-menu (make-sparse-keymap "Games"))
616
617(define-key menu-bar-tools-menu [games]
618 (list 'menu-item "Games" menu-bar-games-menu))
619
620(define-key menu-bar-tools-menu [separator-games]
621 '("--"))
622
623(define-key menu-bar-games-menu [yow]
624 '(menu-item "Random Quotation" yow
625 :help "Display a random Zippy quotation"))
626(define-key menu-bar-games-menu [tetris]
627 '(menu-item "Tetris" tetris))
628(define-key menu-bar-games-menu [solitaire]
629 '(menu-item "Solitaire" solitaire))
630(define-key menu-bar-games-menu [snake]
631 '(menu-item "Snake" snake
632 :help "Move snake around avoiding collisions"))
633(define-key menu-bar-games-menu [mult]
634 '(menu-item "Multiplication Puzzle" mpuz
635 :help "Excercise brain with multiplication"))
636(define-key menu-bar-games-menu [life]
637 '(menu-item "Life" life
638 :help "Watch how John Conway's cellular automaton evolves"))
639(define-key menu-bar-games-menu [hanoi]
640 '(menu-item "Towers of Hanoi" hanoi
641 :help "Watch Towers-of-Hanoi puzzle solved by Emacs"))
642(define-key menu-bar-games-menu [gomoku]
643 '(menu-item "Gomoku" gomoku
644 :help "Mark 5 contiguous squares (like tic-tac-toe)"))
645(define-key menu-bar-games-menu [black-box]
646 '(menu-item "Blackbox" blackbox
647 :help "Find balls in a black box by shooting rays"))
648(define-key menu-bar-games-menu [adventure]
649 '(menu-item "Adventure" dunnet
650 :help "Dunnet, a text Adventure game for Emacs"))
651(define-key menu-bar-games-menu [5x5]
652 '(menu-item "5x5" 5x5
653 :help "Fill in all the squares on a 5x5 board"))
654
655(define-key menu-bar-tools-menu [calendar]
656 '(menu-item "Display Calendar" calendar))
657(define-key menu-bar-tools-menu [speedbar]
658 '(menu-item "Display Speedbar" speedbar-frame-mode))
659(define-key menu-bar-tools-menu [directory-search]
660 '(menu-item "Directory Search" eudc-tools-menu
661 :help "Query directory servers via LDAP, CCSO PH/QI or BBDB"))
662(define-key menu-bar-tools-menu [compose-mail]
663 '(menu-item "Send Mail" compose-mail
664 :help "Send a mail message"))
665(define-key menu-bar-tools-menu [rmail]
666 '(menu-item "Read Mail" read-mail-command
667 :help "Read your mail and reply to it"))
668(define-key menu-bar-tools-menu [gnus]
669 '(menu-item "Read Net News" gnus
670 :help "Read network news groups"))
671
672(define-key menu-bar-tools-menu [separator-vc]
673 '("--"))
674
675(defvar vc-menu-map (make-sparse-keymap "Version Control"))
eccd9bd5
SM
676(define-key menu-bar-tools-menu [pcl-cvs]
677 `(menu-item "PCL-CVS" ,cvs-global-menu
678 :help "Module-level interface to CVS"))
7f315c7c
EZ
679(define-key menu-bar-tools-menu [vc]
680 (list 'menu-item "Version Control" vc-menu-map
681 :help "Interface to RCS, CVS, SCCS"))
682
683(define-key menu-bar-tools-menu [separator-compare]
684 '("--"))
685
686(define-key menu-bar-tools-menu [ediff-misc]
687 '(menu-item "Ediff Miscellanea" menu-bar-ediff-misc-menu
688 :help "Ediff manual, customization, sessions, etc."))
689(define-key menu-bar-tools-menu [epatch]
690 '(menu-item "Apply Patch" menu-bar-epatch-menu))
691(define-key menu-bar-tools-menu [ediff-merge]
692 '(menu-item "Merge" menu-bar-ediff-merge-menu
693 :help "Merge different revisions of files/directories"))
694(define-key menu-bar-tools-menu [compare]
695 '(menu-item "Compare (Ediff)" menu-bar-ediff-menu
696 :help "Display differences between files/directories"))
697
698
699(define-key menu-bar-tools-menu [separator-spell]
700 '("--"))
701
702(define-key menu-bar-tools-menu [spell]
703 '(menu-item "Spell Checking" ispell-menu-map))
704
705(define-key menu-bar-tools-menu [separator-prog]
706 '("--"))
707
708(define-key menu-bar-tools-menu [gdb]
709 '(menu-item "Debugger (GUD)..." gdb
710 :help "Debug a program from withing Emacs"))
711(define-key menu-bar-tools-menu [shell-on-region]
712 '(menu-item "Shell Command on Region..." shell-command-on-region
713 :enable mark-active
714 :help "Pass marked region to a shell command"))
715(define-key menu-bar-tools-menu [shell]
716 '(menu-item "Shell Command..." shell-command
717 :help "Invoke a shell command and catch its output"))
718(define-key menu-bar-tools-menu [compile]
719 '(menu-item "Compile..." compile
720 :help "Invoke compiler or Make, view compilation errors"))
721(define-key menu-bar-tools-menu [grep]
722 '(menu-item "Search Files (Grep)..." grep
723 :help "Search files for strings or regexps (with Grep)"))
724
725\f
726;; The "Help" menu items
727
e5683624
RS
728(defvar menu-bar-describe-menu (make-sparse-keymap "Describe"))
729
7f315c7c
EZ
730(define-key menu-bar-describe-menu [mule-diag]
731 '(menu-item "Show All of Mule Status" mule-diag
732 :visible default-enable-multibyte-characters
733 :help "Display multilingual environment settings"))
734(define-key menu-bar-describe-menu [describe-coding-system]
735 '(menu-item "Describe Coding System..." describe-coding-system
736 :visible default-enable-multibyte-characters))
737(define-key menu-bar-describe-menu [describe-input-method]
738 '(menu-item "Describe Input Method..." describe-input-method
739 :visible default-enable-multibyte-characters
740 :help "Keyboard layout for specific input method"))
741(define-key menu-bar-describe-menu [describe-language-environment]
742 '(menu-item "Describe Language Environment" describe-language-environment-map
743 :visible default-enable-multibyte-characters))
744
745(define-key menu-bar-describe-menu [separator-desc-mule]
746 '(menu-item "--" nil :visible default-enable-multibyte-characters))
747
748(define-key menu-bar-describe-menu [list-keybindings]
749 '(menu-item "List Key Bindings" describe-bindings
750 :help "Display a list of all current keybindings"))
751(define-key menu-bar-describe-menu [list-keybindings]
752 '(menu-item "List Key Bindings" describe-bindings
753 :help "Display a list of all current keybindings"))
e5683624 754(define-key menu-bar-describe-menu [describe-variable]
7f315c7c
EZ
755 '(menu-item "Describe Variable..." describe-variable
756 :help "Display documentation of variable/option"))
e5683624 757(define-key menu-bar-describe-menu [describe-function]
7f315c7c
EZ
758 '(menu-item "Describe Function..." describe-function
759 :help "Display documentation of function/command"))
e5683624 760(define-key menu-bar-describe-menu [describe-key]
7f315c7c
EZ
761 '(menu-item "Describe Key..." describe-key
762 :help "Display documentation of command bound to key"))
a16f6b16 763(define-key menu-bar-describe-menu [apropos-variables]
7f315c7c
EZ
764 '(menu-item "Apropos Variables..." apropos-variable
765 :help "List variables whose names match a regexp"))
a16f6b16 766(define-key menu-bar-describe-menu [apropos-commands]
7f315c7c
EZ
767 '(menu-item "Apropos Commands..." apropos-command
768 :help "List commands whose names match a regexp"))
e5683624 769(define-key menu-bar-describe-menu [describe-mode]
7f315c7c
EZ
770 '(menu-item "Describe Buffer Modes" describe-mode
771 :help "Describe this buffer's major and minor mode"))
e5683624
RS
772
773(defvar menu-bar-manuals-menu (make-sparse-keymap "Manuals"))
774
775(define-key menu-bar-manuals-menu [man]
7f315c7c
EZ
776 '(menu-item "Read Man Page..." manual-entry
777 :help "Man-page docs for external commands and libraries"))
e5683624
RS
778(define-key menu-bar-manuals-menu [sep2]
779 '("--"))
e5683624 780(define-key menu-bar-manuals-menu [info]
7f315c7c
EZ
781 '(menu-item "Browse Manuals with Info" info
782 :help "Read any of the installed manuals"))
783(define-key menu-bar-manuals-menu [command]
784 '(menu-item "Find Command in Manual" Info-goto-emacs-command-node
785 :help "Display manual section that describes a command"))
786(define-key menu-bar-manuals-menu [key]
787 '(menu-item "Find Key in Manual" Info-goto-emacs-key-command-node
788 :help "Display manual section that describes a key"))
bacb2d12 789
7f315c7c
EZ
790(define-key menu-bar-help-menu [eliza]
791 '(menu-item "Emacs Psychiatrist" doctor
792 :help "Our doctor will help you feel better"))
793(define-key menu-bar-help-menu [sep3]
794 '("--"))
f3e1e0dd 795(define-key menu-bar-help-menu [describe-no-warranty]
7f315c7c
EZ
796 '(menu-item "(Non)Warranty" describe-no-warranty
797 :help "Explain that Emacs has NO WARRANTY"))
f3e1e0dd 798(define-key menu-bar-help-menu [describe-copying]
7f315c7c
EZ
799 '(menu-item "Copying Conditions" describe-copying
800 :help "Show the Emacs license (GPL)"))
f3e1e0dd 801(define-key menu-bar-help-menu [describe-distribution]
7f315c7c
EZ
802 '(menu-item "Getting New Versions" describe-distribution
803 :help "How to get latest versions of Emacs"))
efb166ff 804(define-key menu-bar-help-menu [emacs-version]
7f315c7c 805 '(menu-item "Show Emacs Version" emacs-version))
e5683624
RS
806(define-key menu-bar-help-menu [sep2]
807 '("--"))
260130bb 808(define-key menu-bar-help-menu [finder-by-keyword]
7f315c7c
EZ
809 '(menu-item "Find Emacs Packages..." finder-by-keyword
810 :help "Find packages and features by keyword"))
e5683624 811(define-key menu-bar-help-menu [describe]
7f315c7c
EZ
812 (list 'menu-item "Describe" menu-bar-describe-menu
813 :help "Describe commands, variables, keys"))
e5683624 814(define-key menu-bar-help-menu [manuals]
7f315c7c 815 (list 'menu-item "Manuals" menu-bar-manuals-menu))
e5683624
RS
816(define-key menu-bar-help-menu [sep1]
817 '("--"))
7f315c7c
EZ
818(define-key menu-bar-help-menu [report-emacs-bug]
819 '(menu-item "Send Bug Report..." report-emacs-bug
820 :help "Send e-mail to Emacs maintainers"))
821(define-key menu-bar-help-menu [emacs-problems]
822 '(menu-item "Emacs Known Problems" view-emacs-problems))
823(define-key menu-bar-help-menu [emacs-news]
824 '(menu-item "Emacs News" view-emacs-news
825 :help "New features of this version"))
826(define-key menu-bar-help-menu [emacs-faq]
827 '(menu-item "Emacs FAQ" view-emacs-FAQ))
828(define-key menu-bar-help-menu [emacs-tutorial]
829 '(menu-item "Emacs Tutorial" help-with-tutorial
830 :help "Learn how to use Emacs"))
889560ed 831
db774a16
RS
832(defun kill-this-buffer () ; for the menubar
833 "Kills the current buffer."
834 (interactive)
835 (kill-buffer (current-buffer)))
836
2f1139a4
RS
837(defun kill-this-buffer-enabled-p ()
838 (let ((count 0)
839 (buffers (buffer-list)))
840 (while buffers
841 (or (string-match "^ " (buffer-name (car buffers)))
842 (setq count (1+ count)))
843 (setq buffers (cdr buffers)))
a6f8cbf1 844 (and (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1f50590a
RS
845 (> count 1))))
846
1f50590a 847(put 'dired 'menu-enable
a6f8cbf1 848 '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
1f50590a 849
a0213a97 850;; Permit deleting frame if it would leave a visible or iconified frame.
82a74107
KH
851(defun delete-frame-enabled-p ()
852 "Return non-nil if `delete-frame' should be enabled in the menu bar."
853 (let ((frames (frame-list))
27aa8132
RS
854 (count 0))
855 (while frames
856 (if (frame-visible-p (car frames))
857 (setq count (1+ count)))
858 (setq frames (cdr frames)))
859 (> count 1)))
2f1139a4 860
30e19aee
RS
861(defcustom yank-menu-length 20
862 "*Maximum length to display in the yank-menu."
863 :type 'integer
864 :group 'mouse)
3dd92899
KH
865
866(defun menu-bar-update-yank-menu (string old)
867 (let ((front (car (cdr yank-menu)))
868 (menu-string (if (<= (length string) yank-menu-length)
869 string
c3e1d435
RS
870 (concat
871 (substring string 0 (/ yank-menu-length 2))
872 "..."
873 (substring string (- (/ yank-menu-length 2)))))))
7c70a955
RS
874 ;; Don't let the menu string be all dashes
875 ;; because that has a special meaning in a menu.
876 (if (string-match "\\`-+\\'" menu-string)
877 (setq menu-string (concat menu-string " ")))
3dd92899
KH
878 ;; If we're supposed to be extending an existing string, and that
879 ;; string really is at the front of the menu, then update it in place.
880 (if (and old (or (eq old (car front))
881 (string= old (car front))))
dfabc98f 882 (progn
3dd92899
KH
883 (setcar front string)
884 (setcar (cdr front) menu-string))
885 (setcdr yank-menu
886 (cons
887 (cons string (cons menu-string 'menu-bar-select-yank))
888 (cdr yank-menu)))))
889 (if (> (length (cdr yank-menu)) kill-ring-max)
890 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
891
4cca6fbd 892(put 'menu-bar-select-yank 'apropos-inhibit t)
3dd92899
KH
893(defun menu-bar-select-yank ()
894 (interactive "*")
895 (push-mark (point))
896 (insert last-command-event))
40954111 897\f
d0690d12
RS
898(defvar list-buffers-directory nil)
899
08e8171f
RS
900(defvar menu-bar-update-buffers-maxbuf)
901
09642d97
RS
902(defun menu-bar-select-buffer ()
903 (interactive)
904 (switch-to-buffer last-command-event))
905
906(defun menu-bar-select-frame ()
907 (interactive)
908 (make-frame-visible last-command-event)
909 (raise-frame last-command-event)
910 (select-frame last-command-event))
911
c171b42f
RS
912(defun menu-bar-update-buffers-1 (elt)
913 (cons (format
08e8171f 914 (format "%%%ds %%s%%s %%s" menu-bar-update-buffers-maxbuf)
c171b42f
RS
915 (cdr elt)
916 (if (buffer-modified-p (car elt))
917 "*" " ")
918 (save-excursion
919 (set-buffer (car elt))
920 (if buffer-read-only "%" " "))
921 (let ((file
922 (or (buffer-file-name (car elt))
923 (save-excursion
924 (set-buffer (car elt))
925 list-buffers-directory)
926 "")))
927 (setq file (or (file-name-directory file)
928 ""))
929 (if (> (length file) 20)
930 (setq file (concat "..." (substring file -17))))
931 file))
932 (car elt)))
933
06ff7539
RS
934(defvar menu-bar-buffers-menu-list-buffers-entry nil)
935
09642d97 936(defun menu-bar-update-buffers ()
29397c58 937 ;; If user discards the Buffers item, play along.
4d587a6c 938 (and (lookup-key (current-global-map) [menu-bar buffer])
29397c58
RS
939 (frame-or-buffer-changed-p)
940 (let ((buffers (buffer-list))
941 (frames (frame-list))
b3398af1 942 (maxlen 0)
29397c58
RS
943 buffers-menu frames-menu)
944 ;; If requested, list only the N most recently selected buffers.
945 (if (and (integerp buffers-menu-max-size)
946 (> buffers-menu-max-size 1))
947 (if (> (length buffers) buffers-menu-max-size)
948 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
949
950 ;; Make the menu of buffers proper.
951 (setq buffers-menu
952 (cons "Select Buffer"
c171b42f
RS
953 (let* ((buffer-list
954 (mapcar 'list buffers))
955 tail
08e8171f 956 (menu-bar-update-buffers-maxbuf 0)
c171b42f
RS
957 alist
958 head)
959 ;; Put into each element of buffer-list
960 ;; the name for actual display,
961 ;; perhaps truncated in the middle.
962 (setq tail buffer-list)
963 (while tail
964 (let ((name (buffer-name (car (car tail)))))
965 (setcdr (car tail)
966 (if (> (length name) 27)
967 (concat (substring name 0 12)
968 "..."
969 (substring name -12))
970 name)))
971 (setq tail (cdr tail)))
972 ;; Compute the maximum length of any name.
973 (setq tail buffer-list)
29397c58 974 (while tail
c171b42f 975 (or (eq ?\ (aref (cdr (car tail)) 0))
08e8171f
RS
976 (setq menu-bar-update-buffers-maxbuf
977 (max menu-bar-update-buffers-maxbuf
c171b42f 978 (length (cdr (car tail))))))
29397c58 979 (setq tail (cdr tail)))
c171b42f
RS
980 ;; Set ALIST to an alist of the form
981 ;; ITEM-STRING . BUFFER
982 (setq tail buffer-list)
29397c58
RS
983 (while tail
984 (let ((elt (car tail)))
c171b42f 985 (or (eq ?\ (aref (cdr elt) 0))
29397c58 986 (setq alist (cons
c171b42f 987 (menu-bar-update-buffers-1 elt)
29397c58
RS
988 alist)))
989 (and alist (> (length (car (car alist))) maxlen)
990 (setq maxlen (length (car (car alist))))))
991 (setq tail (cdr tail)))
992 (setq alist (nreverse alist))
06ff7539
RS
993 ;; Make the menu item for list-buffers
994 ;; or reuse the one we already have.
995 ;; The advantage in reusing one
996 ;; is that it already has the keyboard equivalent
997 ;; cached, so we save the time to look that up again.
998 (or menu-bar-buffers-menu-list-buffers-entry
999 (setq menu-bar-buffers-menu-list-buffers-entry
1000 (cons
1001 'list-buffers
1002 (cons
1003 ""
1004 'list-buffers))))
1005 ;; Update the item string for menu's new width.
1006 (setcar (cdr menu-bar-buffers-menu-list-buffers-entry)
1007 (concat (make-string (max (- (/ maxlen 2) 8) 0)
1008 ?\ )
1009 "List All Buffers"))
1010 ;; Now make the actual list of items,
1011 ;; ending with the list-buffers item.
29397c58
RS
1012 (nconc (mapcar '(lambda (pair)
1013 ;; This is somewhat risque, to use
1014 ;; the buffer name itself as the event
1015 ;; type to define, but it works.
1016 ;; It would not work to use the buffer
1017 ;; since a buffer as an event has its
1018 ;; own meaning.
1019 (nconc (list (buffer-name (cdr pair))
1020 (car pair)
1021 (cons nil nil))
1022 'menu-bar-select-buffer))
1023 alist)
06ff7539 1024 (list menu-bar-buffers-menu-list-buffers-entry)))))
29397c58
RS
1025
1026
1027 ;; Make a Frames menu if we have more than one frame.
1028 (if (cdr frames)
b3398af1
RS
1029 (let ((name (concat (make-string (max (- (/ maxlen 2) 3) 0)
1030 ?\ )
1031 "Frames"))
1032 (frames-menu
1033 (cons 'keymap
1034 (cons "Select Frame"
1035 (mapcar '(lambda (frame)
1036 (nconc (list frame
1037 (cdr (assq 'name
1038 (frame-parameters frame)))
1039 (cons nil nil))
1040 'menu-bar-select-frame))
1041 frames)))))
1042 ;; Put it underneath the Buffers menu.
1043 (setq buffers-menu (cons (cons 'frames (cons name frames-menu))
1044 buffers-menu))))
29397c58
RS
1045 (if buffers-menu
1046 (setq buffers-menu (cons 'keymap buffers-menu)))
4d587a6c 1047 (define-key (current-global-map) [menu-bar buffer]
b3398af1 1048 (cons "Buffers" buffers-menu)))))
09642d97
RS
1049
1050(add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
2f1139a4 1051
3f557298
RS
1052(menu-bar-update-buffers)
1053
40954111
RS
1054;; this version is too slow
1055;;;(defun format-buffers-menu-line (buffer)
1056;;; "Returns a string to represent the given buffer in the Buffer menu.
1057;;;nil means the buffer shouldn't be listed. You can redefine this."
1058;;; (if (string-match "\\` " (buffer-name buffer))
1059;;; nil
1060;;; (save-excursion
1061;;; (set-buffer buffer)
1062;;; (let ((size (buffer-size)))
1063;;; (format "%s%s %-19s %6s %-15s %s"
1064;;; (if (buffer-modified-p) "*" " ")
1065;;; (if buffer-read-only "%" " ")
1066;;; (buffer-name)
1067;;; size
1068;;; mode-name
1069;;; (or (buffer-file-name) ""))))))
1070\f
25b048ee
RS
1071;;; Set up a menu bar menu for the minibuffer.
1072
1073(mapcar
1074 (function
1075 (lambda (map)
1076 (define-key map [menu-bar minibuf]
1077 (cons "Minibuf" (make-sparse-keymap "Minibuf")))))
1078 (list minibuffer-local-ns-map
1079 minibuffer-local-must-match-map
1080 minibuffer-local-isearch-map
1081 minibuffer-local-map
1082 minibuffer-local-completion-map))
1083
1084(mapcar
1085 (function
1086 (lambda (map)
1087 (define-key map [menu-bar minibuf ?\?]
7f315c7c
EZ
1088 (list 'menu-item "List Completions" 'minibuffer-completion-help
1089 :help "Display all possible completions"))
25b048ee 1090 (define-key map [menu-bar minibuf space]
7f315c7c
EZ
1091 (list 'menu-item "Complete Word" 'minibuffer-complete-word
1092 :help "Complete at most one word"))
25b048ee 1093 (define-key map [menu-bar minibuf tab]
7f315c7c
EZ
1094 (list 'menu-item "Complete" 'minibuffer-complete
1095 :help "Complete as far as possible"))
25b048ee
RS
1096 ))
1097 (list minibuffer-local-must-match-map
1098 minibuffer-local-completion-map))
1099
1100(mapcar
1101 (function
1102 (lambda (map)
1103 (define-key map [menu-bar minibuf quit]
7f315c7c
EZ
1104 (list 'menu-item "Quit" 'keyboard-escape-quit
1105 :help "Abort input and exit minibuffer"))
25b048ee 1106 (define-key map [menu-bar minibuf return]
7f315c7c
EZ
1107 (list 'menu-item "Enter" 'exit-minibuffer
1108 :help "Terminate input and exit minibuffer"))
25b048ee
RS
1109 ))
1110 (list minibuffer-local-ns-map
1111 minibuffer-local-must-match-map
1112 minibuffer-local-isearch-map
1113 minibuffer-local-map
1114 minibuffer-local-completion-map))
1115\f
88a26eb4
DL
1116(defcustom menu-bar-mode nil
1117 "Toggle display of a menu bar on each frame.
1118Setting this variable directly does not take effect;
1119use either \\[customize] or the function `menu-bar-mode'."
1120 :set (lambda (symbol value)
1121 (menu-bar-mode (or value 0)))
1122 :initialize 'custom-initialize-default
1123 :type 'boolean
1124 :group 'frames)
7b7d6615 1125
057d49d1 1126(defun menu-bar-mode (flag)
dfd29450 1127 "Toggle display of a menu bar on each frame.
057d49d1
RS
1128This command applies to all frames that exist and frames to be
1129created in the future.
e1d18ad8
RS
1130With a numeric argument, if the argument is positive,
1131turn on menu bars; otherwise, turn off menu bars."
dad8e392 1132 (interactive "P")
dad8e392 1133
7b7d6615
RS
1134 ;; Make menu-bar-mode and default-frame-alist consistent.
1135 (let ((default (assq 'menu-bar-lines default-frame-alist)))
1136 (if default
1137 (setq menu-bar-mode (not (eq (cdr default) 0)))
1138 (setq default-frame-alist
1139 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
1140 default-frame-alist))))
1141
1142 ;; Toggle or set the mode, according to FLAG.
1143 (setq menu-bar-mode (if (null flag) (not menu-bar-mode)
1144 (> (prefix-numeric-value flag) 0)))
1145
1146 ;; Apply it to default-frame-alist.
1147 (let ((parameter (assq 'menu-bar-lines default-frame-alist)))
1148 (if (consp parameter)
1149 (setcdr parameter (if menu-bar-mode 1 0))
1150 (setq default-frame-alist
1151 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
1152 default-frame-alist))))
1153
1154 ;; Apply it to existing frames.
1155 (let ((frames (frame-list)))
1156 (while frames
1157 (let ((height (cdr (assq 'height (frame-parameters (car frames))))))
1158 (modify-frame-parameters (car frames)
1159 (list (cons 'menu-bar-lines
1160 (if menu-bar-mode 1 0))))
1161 (modify-frame-parameters (car frames)
1162 (list (cons 'height height))))
1163 (setq frames (cdr frames)))))
1db87953 1164
bffa5d4d
RS
1165(provide 'menu-bar)
1166
235aa29b 1167;;; menu-bar.el ends here