menu-bar.el 45.7 KB
Newer Older
1 2
;;; menu-bar.el --- define a default menu bar.

3
;; Copyright (C) 1993, 1994, 1995, 2000 Free Software Foundation, Inc.
Erik Naggum's avatar
Erik Naggum committed
4

5
;; Author: RMS
Richard M. Stallman's avatar
Richard M. Stallman committed
6
;; Maintainer: FSF
Richard M. Stallman's avatar
Richard M. Stallman committed
7
;; Keywords: internal
8

Richard M. Stallman's avatar
Richard M. Stallman committed
9 10 11 12 13 14 15 16 17 18 19 20 21
;; This file is part of GNU Emacs.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
Erik Naggum's avatar
Erik Naggum committed
22 23 24
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
Richard M. Stallman's avatar
Richard M. Stallman committed
25

26 27
;; Avishai Yacobi suggested some menu rearrangements.

Erik Naggum's avatar
Erik Naggum committed
28 29
;;; Code:

30 31
;;; User options:

Richard M. Stallman's avatar
Richard M. Stallman committed
32
(defcustom buffers-menu-max-size 10
33 34 35
  "*Maximum number of entries which may appear on the Buffers menu.
If this is 10, then only the ten most-recently-selected buffers are shown.
If this is nil, then all buffers are shown.
Richard M. Stallman's avatar
Richard M. Stallman committed
36 37 38 39
A large number or nil slows down menu responsiveness."
  :type '(choice integer
		 (const :tag "All" nil))
  :group 'mouse)
40

41 42 43 44
;; Don't clobber an existing menu-bar keymap, to preserve any menu-bar key
;; definitions made in loaddefs.el.
(or (lookup-key global-map [menu-bar])
    (define-key global-map [menu-bar] (make-sparse-keymap "menu-bar")))
45
(defvar menu-bar-help-menu (make-sparse-keymap "Help"))
46 47

;; Force Help item to come last, after the major mode's own items.
48 49 50
;; The symbol used to be called `help', but that gets confused with the
;; help key.
(setq menu-bar-final-items '(help-menu))
51

52
(define-key global-map [menu-bar help-menu] (cons "Help" menu-bar-help-menu))
53 54
(defvar menu-bar-tools-menu (make-sparse-keymap "Tools"))
(define-key global-map [menu-bar tools] (cons "Tools" menu-bar-tools-menu))
55 56 57 58 59 60 61 62 63 64 65
;; This definition is just to show what this looks like.
;; It gets overridden below when menu-bar-update-buffers is called.
(define-key global-map [menu-bar buffer]
  (cons "Buffers" (make-sparse-keymap "Buffers")))
(defvar menu-bar-options-menu (make-sparse-keymap "Options"))
(define-key global-map [menu-bar options]
  (cons "Options" menu-bar-options-menu))
(defvar menu-bar-edit-menu (make-sparse-keymap "Edit"))
(define-key global-map [menu-bar edit] (cons "Edit" menu-bar-edit-menu))
(defvar menu-bar-files-menu (make-sparse-keymap "File"))
(define-key global-map [menu-bar files] (cons "File" menu-bar-files-menu))
66 67 68

;; This alias is for compatibility with 19.28 and before.
(defvar menu-bar-file-menu menu-bar-files-menu)
69

70
;; The "File" menu items
71
(define-key menu-bar-files-menu [exit-emacs]
72 73
  '(menu-item "Exit Emacs" save-buffers-kill-emacs
	      :help "Save unsaved buffers, then exit"))
74 75 76 77

(define-key menu-bar-files-menu [separator-exit]
  '("--"))

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
;; Don't use delete-frame as event name because that is a special
;; event.
(define-key menu-bar-files-menu [delete-this-frame]
  '(menu-item "Delete Frame" delete-frame
	      :visible (fboundp 'delete-frame)
	      :enable (delete-frame-enabled-p)
	      :help "Delete currently selected frame"))
(define-key menu-bar-files-menu [make-frame-on-display]
  '(menu-item "New Frame on Display..." make-frame-on-display
	      :visible (fboundp 'make-frame-on-display)
	      :help "Open a new frame on another display"))
(define-key menu-bar-files-menu [make-frame]
  '(menu-item "New Frame" make-frame-command
	      :visible (fboundp 'make-frame-command)
	      :help "Open a new frame"))

94
(define-key menu-bar-files-menu [one-window]
95 96 97
  '(menu-item "Unsplit Windows" delete-other-windows
	      :enable (not (one-window-p t nil))
	      :help "Make selected window fill its frame"))
98 99

(define-key menu-bar-files-menu [split-window]
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
  '(menu-item "Split Window" split-window-vertically
	      :help "Split selected window in two"))

(define-key menu-bar-files-menu [separator-window]
  '(menu-item "--"))

(define-key menu-bar-files-menu [ps-print-region]
  '(menu-item "Postscript Print Region" ps-print-region-with-faces
	      :enable mark-active
	      :help "Pretty-print marked region to PostScript printer"))
(define-key menu-bar-files-menu [ps-print-buffer]
  '(menu-item "Postscript Print Buffer" ps-print-buffer-with-faces
	      :help "Pretty-print current buffer to PostScript printer"))
(define-key menu-bar-files-menu [print-region]
  '(menu-item "Print Region" print-region
	      :enable mark-active
	      :help "Print region between mark and current position"))
(define-key menu-bar-files-menu [print-buffer]
  '(menu-item "Print Buffer" print-buffer
	      :help "Print current buffer with page headings"))

(define-key menu-bar-files-menu [separator-print]
  '(menu-item "--"))
123

124
(define-key menu-bar-files-menu [recover-session]
125 126 127 128 129 130 131 132 133 134 135
  '(menu-item "Recover Crashed Session..." recover-session
	      :enable (and auto-save-list-file-prefix
			   (directory-files
			    (file-name-directory auto-save-list-file-prefix)
			    nil
			    (concat "\\`"
				    (regexp-quote
				     (file-name-nondirectory
				      auto-save-list-file-prefix)))
			    t))
	      :help "Recover edits from a crashed session"))
136
(define-key menu-bar-files-menu [revert-buffer]
137 138 139 140 141 142 143 144
  '(menu-item "Revert Buffer" revert-buffer
	      :enable (or revert-buffer-function
			  revert-buffer-insert-file-contents-function
			  (and (buffer-file-name)
			       (or (buffer-modified-p)
				   (not (verify-visited-file-modtime
					 (current-buffer))))))
	      :help "Re-read current buffer from its file"))
145
(define-key menu-bar-files-menu [write-file]
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
  '(menu-item "Save Buffer As..." write-file
	      :enable (not (window-minibuffer-p
			    (frame-selected-window menu-updating-frame)))
	      :help "Write current buffer to another file"))
(define-key menu-bar-files-menu [save-buffer]
  '(menu-item "Save (current buffer)" save-buffer
	      :enable (and (buffer-modified-p)
			   (not (window-minibuffer-p
				 (frame-selected-window menu-updating-frame))))
	      :help "Save current buffer to its file"))

(define-key menu-bar-files-menu [separator-save]
  '(menu-item "--"))

(define-key menu-bar-files-menu [kill-buffer]
  '(menu-item "Close (current buffer)" kill-this-buffer
	      :enable (kill-this-buffer-enabled-p)
	      :help "Discard contents of current buffer"))
(define-key menu-bar-files-menu [insert-file]
  '(menu-item "Insert File..." insert-file
	      :enable (not (window-minibuffer-p
			    (frame-selected-window menu-updating-frame)))
	      :help "Insert another file into current buffer"))
(define-key menu-bar-files-menu [dired]
  '(menu-item "Open Directory..." dired
	      :help "Read a directory, operate on its files"))
(define-key menu-bar-files-menu [open-file]
  '(menu-item "Open File..." find-file
	      :enable (not (window-minibuffer-p
			    (frame-selected-window menu-updating-frame)))
	      :help "Read a file into an Emacs buffer"))

178

179
;; The "Edit" menu items
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
(defun nonincremental-search-forward (string)
  "Read a string and search for it nonincrementally."
  (interactive "sSearch for string: ")
  (if (equal string "")
      (search-forward (car search-ring))
    (isearch-update-ring string nil)
    (search-forward string)))

(defun nonincremental-search-backward (string)
  "Read a string and search backward for it nonincrementally."
  (interactive "sSearch for string: ")
  (if (equal string "")
      (search-backward (car search-ring))
    (isearch-update-ring string nil)
    (search-backward string)))

(defun nonincremental-re-search-forward (string)
  "Read a regular expression and search for it nonincrementally."
  (interactive "sSearch for regexp: ")
  (if (equal string "")
      (re-search-forward (car regexp-search-ring))
    (isearch-update-ring string t)
    (re-search-forward string)))

(defun nonincremental-re-search-backward (string)
  "Read a regular expression and search backward for it nonincrementally."
  (interactive "sSearch for regexp: ")
  (if (equal string "")
      (re-search-backward (car regexp-search-ring))
    (isearch-update-ring string t)
    (re-search-backward string)))

212
(defun nonincremental-repeat-search-forward ()
213 214
  "Search forward for the previous search string."
  (interactive)
215 216
  (if (null search-ring)
      (error "No previous search"))
217 218
  (search-forward (car search-ring)))

219
(defun nonincremental-repeat-search-backward ()
220 221
  "Search backward for the previous search string."
  (interactive)
222 223
  (if (null search-ring)
      (error "No previous search"))
224 225
  (search-backward (car search-ring)))

226
(defun nonincremental-repeat-re-search-forward ()
227 228
  "Search forward for the previous regular expression."
  (interactive)
Richard M. Stallman's avatar
Richard M. Stallman committed
229
  (if (null regexp-search-ring)
230
      (error "No previous search"))
231 232
  (re-search-forward (car regexp-search-ring)))

233
(defun nonincremental-repeat-re-search-backward ()
234 235
  "Search backward for the previous regular expression."
  (interactive)
Richard M. Stallman's avatar
Richard M. Stallman committed
236
  (if (null regexp-search-ring)
237
      (error "No previous search"))
238 239
  (re-search-backward (car regexp-search-ring)))

240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
(defvar menu-bar-search-menu (make-sparse-keymap "Search"))
(defvar menu-bar-adv-search-menu
  (make-sparse-keymap "Advanced Search/Replace"))

(define-key menu-bar-adv-search-menu [tags-continue]
  '(menu-item "Continue Tags Search/Replace" tags-loop-continue
	      :help "Continue last tags search/replace operation"))
(define-key menu-bar-adv-search-menu [tags-repl]
  '(menu-item "Replace in all tagged files" tags-query-replace
	      :help "Interactively replace a regexp in all tagged files"))
(define-key menu-bar-adv-search-menu [tags-srch]
  '(menu-item "Search in all tagged files" tags-search
	      :help "Search for a regexp in all tagged files"))

(define-key menu-bar-adv-search-menu [separator-tag-search]
  '(menu-item "--"))

(define-key menu-bar-adv-search-menu [query-replace-regexp]
  '(menu-item "Replace Regexp..." query-replace-regexp
	      :enable (not buffer-read-only)
	      :help "Replace regular expression, ask about each occurrence"))
(define-key menu-bar-adv-search-menu [repeat-regexp-back]
  '(menu-item "Repeat Regexp Backwards"
	      nonincremental-repeat-re-search-backward
	      :enable regexp-search-ring
	      :help "Repeat last regular expression search backwards"))
(define-key menu-bar-adv-search-menu [repeat-regexp-fwd]
  '(menu-item "Repeat Regexp" nonincremental-repeat-re-search-forward
	      :enable regexp-search-ring
	      :help "Repeat last regular expression search forward"))
(define-key menu-bar-adv-search-menu [re-search-backward]
  '(menu-item "Search Regexp Backwards..." nonincremental-re-search-backward
	      :help "Search backwards for a regular expression"))
(define-key menu-bar-adv-search-menu [re-search-forward]
  '(menu-item "Search Regexp..." nonincremental-re-search-forward
	      :help "Search forward for a regular expression"))
(define-key menu-bar-search-menu [re-search]
  (list 'menu-item "Advanced Search/Replace" menu-bar-adv-search-menu
	      :help "Regexp and Tags search and replace"))
279

280 281 282 283
(define-key menu-bar-search-menu [query-replace]
  '(menu-item "Replace..." query-replace
	      :enable (not buffer-read-only)
	      :help "Replace string interactively, ask about each occurrence"))
284
(define-key menu-bar-search-menu [repeat-search-back]
285 286 287
  '(menu-item "Repeat Backwards" nonincremental-repeat-search-backward
	      :enable search-ring
	      :help "Repeat last search backwards"))
288
(define-key menu-bar-search-menu [repeat-search-fwd]
289 290 291
  '(menu-item "Repeat Search" nonincremental-repeat-search-forward
	      :enable search-ring
	      :help "Repeat last search forward"))
292
(define-key menu-bar-search-menu [search-backward]
293 294
  '(menu-item "Search Backwards..." nonincremental-search-backward
	      :help "Search backwards for a string"))
295
(define-key menu-bar-search-menu [search-forward]
296 297
  '(menu-item "Search..." nonincremental-search-forward
	      :help "Search forward for a string"))
298

299 300 301 302
;;; Assemble the top-level Edit menu items.
(define-key menu-bar-edit-menu [props]
  '(menu-item "Text Properties" facemenu-menu
	      :help "Change properties of text in region"))
303

304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
(define-key menu-bar-search-menu [separator-search]
  '(menu-item "--"))

(define-key menu-bar-edit-menu [bookmark]
  '(menu-item "Bookmarks" menu-bar-bookmark-map
	      :help "Record positions and jump between them"))

(define-key menu-bar-edit-menu [separator-bookmark]
  '(menu-item "--"))

(defvar menu-bar-goto-menu (make-sparse-keymap "Go To"))

(define-key menu-bar-goto-menu [set-tags-name]
  '(menu-item "Set Tags File Name" visit-tags-table
	      :help "Tell Tags commands which tag table file to use"))

(define-key menu-bar-goto-menu [separator-tag-file]
  '(menu-item "--"))

(define-key menu-bar-goto-menu [apropos-tags]
  '(menu-item "Tags Apropos" tags-apropos
	      :help "Find function/variables whose names match regexp"))
(define-key menu-bar-goto-menu [next-tag-otherw]
  '(menu-item "Next Tag in Other Window"
	      (function (lambda () (find-tag-other-window nil t)))
329 330
	      :enable (and (boundp 'tags-location-ring)
			   (not (ring-empty-p tags-location-ring)))
331 332 333 334
	      :help "Find next function/variable matching last tag name in another window"))
(define-key menu-bar-goto-menu [next-tag]
  '(menu-item "Find Next Tag"
	      (function (lambda () (find-tag nil t)))
335 336
	      :enable (and (boundp 'tags-location-ring)
			   (not (ring-empty-p tags-location-ring)))
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
	      :help "Find next function/variable matching last tag name"))
(define-key menu-bar-goto-menu [find-tag-otherw]
  '(menu-item "Find Tag in Other Window..." find-tag-other-window
	      :help "Find function/variable definition in another window"))
(define-key menu-bar-goto-menu [find-tag]
  '(menu-item "Find Tag..." find-tag
	      :help "Find definition of function or variable"))

(define-key menu-bar-goto-menu [separator-tags]
  '(menu-item "--"))

(define-key menu-bar-goto-menu [end-of-buf]
  '(menu-item "Goto End of Buffer" end-of-buffer))
(define-key menu-bar-goto-menu [beg-of-buf]
  '(menu-item "Goto Beginning of Buffer" beginning-of-buffer))
(define-key menu-bar-goto-menu [go-to-pos]
  '(menu-item "Goto Buffer Position..." goto-char
	      :help "Read a number N and go to buffer position N"))
(define-key menu-bar-goto-menu [go-to-line]
  '(menu-item "Goto Line..." goto-line
	      :help "Read a line number and go to that line"))

(define-key menu-bar-edit-menu [goto]
  (list 'menu-item "Go To" menu-bar-goto-menu))

(define-key menu-bar-edit-menu [search]
  (list 'menu-item "Search" menu-bar-search-menu))

(define-key menu-bar-edit-menu [fill]
  '(menu-item "Fill" fill-region
	      :enable (and mark-active (not buffer-read-only))
	      :help
	      "Fill text in region to fit between left and right margin"))
(define-key menu-bar-edit-menu [clear]
  '(menu-item "Clear" delete-region
	      :enable (and mark-active
			   (not buffer-read-only)
			   (not (mouse-region-match)))
	      :help
	      "Delete the text in region between mark and current pos"))
377 378
(defvar yank-menu (cons "Select Yank" nil))
(fset 'yank-menu (cons 'keymap yank-menu))
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
(define-key menu-bar-edit-menu [select-paste]
  '(menu-item "Select and Paste" yank-menu
	      :enable (and (cdr yank-menu) (not buffer-read-only))
	      :help "Paste text cut/copied earlier"))
(define-key menu-bar-edit-menu [paste]
  '(menu-item "Paste" yank
	      :enable (and (x-selection-exists-p) (not buffer-read-only))
	      :help "Paste text most recently cut/copied"))
(define-key menu-bar-edit-menu [copy]
  '(menu-item "Copy" menu-bar-kill-ring-save
	      :enable mark-active
	      :help "Copy text in region between mark and current pos"))
(define-key menu-bar-edit-menu [cut]
  '(menu-item "Cut" kill-region
	      :enable (and mark-active (not buffer-read-only))
	      :help "Cut (kill) text in region between mark and current pos"))
(define-key menu-bar-edit-menu [undo]
  '(menu-item "Undo" undo
	      :enable (and (not buffer-read-only)
			   (not (eq t buffer-undo-list))
			   (if (eq last-command 'undo)
			       pending-undo-list
			     (consp buffer-undo-list)))
	      :help "Undo last operation"))

404

405 406 407
(defun menu-bar-kill-ring-save (beg end)
  (interactive "r")
  (if (mouse-region-match)
408
      (message "Selecting a region with the mouse does `copy' automatically")
409 410
    (kill-ring-save beg end)))

411 412
(autoload 'ispell-menu-map "ispell" nil t 'keymap)

413
;; These are alternative definitions for the cut, paste and copy
414
;; menu items.  Use them if your system expects these to use the clipboard.
415 416 417 418 419 420 421

(put 'clipboard-kill-region 'menu-enable 'mark-active)
(put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
(put 'clipboard-yank 'menu-enable
     '(or (x-selection-exists-p) (x-selection-exists-p 'CLIPBOARD)))

(defun clipboard-yank ()
422
  "Insert the clipboard contents, or the last stretch of killed text."
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
  (interactive)
  (let ((x-select-enable-clipboard t))
    (yank)))

(defun clipboard-kill-ring-save (beg end)
  "Copy region to kill ring, and save in the X clipboard."
  (interactive "r")
  (let ((x-select-enable-clipboard t))
    (kill-ring-save beg end)))

(defun clipboard-kill-region (beg end)
  "Kill the region, and save it in the X clipboard."
  (interactive "r")
  (let ((x-select-enable-clipboard t))
    (kill-region beg end)))

(defun menu-bar-enable-clipboard ()
440 441
  "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
Do the same for the keys of the same name."
442
  (interactive)
443 444 445
  ;; We can't use constant list structure here because it becomes pure,
  ;; and because it gets modified with cache data.
  (define-key menu-bar-edit-menu [paste]
446
    (cons "Paste" (cons "Paste text from clipboard" 'clipboard-yank)))
447
  (define-key menu-bar-edit-menu [copy]
448 449
    (cons "Copy" (cons "Copy text in region to the clipboard"
		       'clipboard-kill-ring-save)))
450
  (define-key menu-bar-edit-menu [cut]
451 452
    (cons "Cut" (cons "Delete text in region and copy it to the clipboard"
		      'clipboard-kill-region)))
453 454 455 456 457 458 459 460

  (define-key global-map [f20] 'clipboard-kill-region)
  (define-key global-map [f16] 'clipboard-kill-ring-save)
  (define-key global-map [f18] 'clipboard-yank)
  ;; X11R6 versions
  (define-key global-map [cut] 'clipboard-kill-region)
  (define-key global-map [copy] 'clipboard-kill-ring-save)
  (define-key global-map [paste] 'clipboard-yank))
461

462
;; The "Options" menu items
463 464 465

(defvar menu-bar-custom-menu (make-sparse-keymap "Customize"))

466
(define-key menu-bar-custom-menu [customize-apropos-groups]
467 468
  '(menu-item "Groups Matching Regexp..." customize-apropos-groups
	      :help "Browse groups whose names match regexp"))
469
(define-key menu-bar-custom-menu [customize-apropos-faces]
470 471
  '(menu-item "Faces Matching Regexp..." customize-apropos-faces
	      :help "Browse faces whose names match regexp"))
472
(define-key menu-bar-custom-menu [customize-apropos-options]
473 474
  '(menu-item "Options Matching Regexp..." customize-apropos-options
	      :help "Browse options whose names match regexp"))
475
(define-key menu-bar-custom-menu [customize-apropos]
476 477
  '(menu-item "Settings Matching Regexp..." customize-apropos
	      :help "Browse customizable settings whose names match regexp"))
478 479
(define-key menu-bar-custom-menu [separator-2]
  '("--"))
Richard M. Stallman's avatar
Richard M. Stallman committed
480
(define-key menu-bar-custom-menu [customize-group]
481 482
  '(menu-item "Specific Group..." customize-group
	      :help "Customize settings of specific group"))
483
(define-key menu-bar-custom-menu [customize-face]
484 485
  '(menu-item "Specific Face..." customize-face
	      :help "Customize attributes of specific face"))
486
(define-key menu-bar-custom-menu [customize-option]
487 488
  '(menu-item "Specific Option..." customize-option
	      :help "Change value of specific option"))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
489
(define-key menu-bar-custom-menu [customize-changed-options]
490 491
  '(menu-item "Recently Changed Options..." customize-changed-options
	      :help "Customize options changed in recent versions"))
492 493
(define-key menu-bar-custom-menu [separator-3]
  '("--"))
Per Abrahamsen's avatar
Per Abrahamsen committed
494
(define-key menu-bar-custom-menu [customize-browse]
495 496
  '(menu-item "Browse Customization Groups" customize-browse
	      :help "Browse all customization groups"))
497
(define-key menu-bar-custom-menu [customize]
498 499
  '(menu-item "Top-level Customization Group" customize
	      :help "The master group called `Emacs'"))
500

501
;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
502

503
(defmacro menu-bar-make-toggle (name variable doc message help &rest body)
504 505 506 507 508 509
  `(progn
     (defun ,name ()
       ,(concat doc ".")
       (interactive)
       (if ,(if body `(progn . ,body)
	      `(setq ,variable (not ,variable)))
510 511
  	   (message ,message "enabled")
  	 (message ,message "disabled")))
512 513 514 515 516 517 518 519
     '(menu-item ,doc ,name
		 :help ,help
                 :button (:toggle . (and (boundp ',variable) ,variable)))))

;;; Assemble all the top-level items of the "Options" menu
(define-key menu-bar-options-menu [customize]
  (list 'menu-item "Customize Emacs" menu-bar-custom-menu
	:help "Full customization of every Emacs feature"))
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545

(defun menu-bar-options-save ()
  "Save current values of Options menu items using Custom."
  (interactive)
  (dolist (elt '(debug-on-quit debug-on-error auto-compression-mode
		 case-fold-search truncate-lines show-paren-mode
		 transient-mark-mode global-font-lock-mode
		 current-language-environment default-input-method))
    (if (default-value elt)
	(customize-save-variable elt (default-value elt))))
  (if (memq 'turn-on-auto-fill text-mode-hook)
      (customize-save-variable 'text-mode-hook
			       (default-value 'text-mode-hook)))
  (if (featurep 'saveplace)
      (customize-save-variable 'save-place (default-value 'save-place)))
  (if (featurep 'uniquify)
      (customize-save-variable 'uniquify-buffer-name-style
			       (default-value 'uniquify-buffer-name-style))))

(define-key menu-bar-options-menu [save]
  '(menu-item "Save options" menu-bar-options-save
	      :help "Save options set from the menu above"))

(define-key menu-bar-options-menu [custom-separator]
  '("--"))

546 547 548 549 550
(define-key menu-bar-options-menu [mule]
  ;; It is better not to use backquote here,
  ;; because that makes a bootstrapping problem
  ;; if you need to recompile all the Lisp files using interpreted code.
  (list 'menu-item "Mule (Multilingual Environment)" mule-menu-keymap
551 552 553
;; Most of the MULE menu actually does make sense in unibyte mode,
;; e.g. language selection.
;;;	':visible 'default-enable-multibyte-characters
554 555 556 557 558 559 560
	':help "Default language, encodings, input method"))
;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
;(define-key menu-bar-options-menu [preferences]
;  (list 'menu-item "Preferences" menu-bar-preferences-menu
;	:help "Toggle important global options"))

(define-key menu-bar-options-menu [mule-separator]
561
  '("--"))
562 563 564

(define-key menu-bar-options-menu [debug-on-quit]
  (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
565 566
			"Enter Debugger on Quit/C-g" "Debug on Quit %s"
			"Enter Lisp debugger when C-g is pressed"))
567 568
(define-key menu-bar-options-menu [debug-on-error]
  (menu-bar-make-toggle toggle-debug-on-error debug-on-error
569 570 571
			"Enter Debugger on Error" "Debug on Error %s"
			"Enter Lisp debugger when error is signaled"))
(define-key menu-bar-options-menu [debugger-separator]
572
  '("--"))
573 574 575 576 577 578
(define-key menu-bar-options-menu [toggle-auto-compression]
  '(menu-item "Automatic File De/compression"
             auto-compression-mode
	     :help "Transparently decompress compressed files"
             :button (:toggle . (rassq 'jka-compr-handler
				       file-name-handler-alist))))
579 580
(define-key menu-bar-options-menu [save-place]
  (menu-bar-make-toggle toggle-save-place-globally save-place
581
			"Save Place in Files between Sessions"
582
			"Saving place in files %s"
583
			"Save Emacs state for next session"
584
                        (require 'saveplace)
585 586
			(setq-default save-place
				      (not (default-value save-place)))))
587 588
(define-key menu-bar-options-menu [uniquify]
  (menu-bar-make-toggle toggle-uniquify-buffer-names uniquify-buffer-name-style
589
			"Use Directory Names in Buffer Names"
590
			"Directory name in buffer names (uniquify) %s"
591
			nil
592 593 594 595
			(require 'uniquify)
			(setq uniquify-buffer-name-style
			      (if (not uniquify-buffer-name-style)
				  'forward))))
596 597
(define-key menu-bar-options-menu [edit-options-separator]
  '("--"))
598 599
(define-key menu-bar-options-menu [case-fold-search]
  (menu-bar-make-toggle toggle-case-fold-search case-fold-search
600 601 602 603 604 605 606 607
			"Case-Insensitive Search"
			"Case-Insensitive Search %s"
			"If checked, search ignores letter-case"))
(define-key menu-bar-options-menu [auto-fill-mode]
  '(menu-item "Word Wrap in Text Modes (Auto Fill)"
              toggle-text-mode-auto-fill
	      :help "Automatically fill text between left and right margins"
              :button (:toggle . (member 'turn-on-auto-fill text-mode-hook))))
608 609 610
(define-key menu-bar-options-menu [truncate-lines]
  (menu-bar-make-toggle
   toggle-truncate-lines truncate-lines
611
   "Truncate Long Lines in this Buffer" "Long Line Truncation %s"
612
   "If checked, long lines are truncated on the screen"
613 614
   (prog1 (setq truncate-lines (not truncate-lines))
     (set-buffer-modified-p (buffer-modified-p)))))
615 616 617 618 619 620 621
(define-key menu-bar-options-menu [highlight-separator]
  '("--"))
(define-key menu-bar-options-menu [highlight-paren-mode]
  (menu-bar-make-toggle toggle-highlight-paren-mode show-paren-mode
			"Highlight Matching Parentheses"
			"Show Paren mode %s"
			"Highlight matching and mismatched parentheses"))
622 623
(define-key menu-bar-options-menu [transient-mark-mode]
  (menu-bar-make-toggle toggle-transient-mark-mode transient-mark-mode
624
			"Transient Mark Mode (highlights region)"
625 626
			"Transient Mark mode %s"
			"Highlight the marked region when it's active"))
627
(define-key menu-bar-options-menu [toggle-global-lazy-font-lock-mode]
628
  (menu-bar-make-toggle toggle-global-lazy-font-lock-mode global-font-lock-mode
629 630 631
			"Highlight Syntax (Global Font Lock)"
			"Syntax Highlighting %s"
			"Highlights text based on language syntax"
632
			global-font-lock-mode))
633

634

635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
;; The "Tools" menu items

(defvar menu-bar-games-menu (make-sparse-keymap "Games"))

(define-key menu-bar-tools-menu [games]
  (list 'menu-item "Games" menu-bar-games-menu))

(define-key menu-bar-tools-menu [separator-games]
  '("--"))

(define-key menu-bar-games-menu [yow]
  '(menu-item "Random Quotation"  yow
	      :help "Display a random Zippy quotation"))
(define-key menu-bar-games-menu [tetris]
  '(menu-item "Tetris"  tetris))
(define-key menu-bar-games-menu [solitaire]
  '(menu-item "Solitaire"  solitaire))
(define-key menu-bar-games-menu [snake]
  '(menu-item "Snake"  snake
	      :help "Move snake around avoiding collisions"))
(define-key menu-bar-games-menu [mult]
  '(menu-item "Multiplication Puzzle"  mpuz
	      :help "Excercise brain with multiplication"))
(define-key menu-bar-games-menu [life]
  '(menu-item "Life"  life
	      :help "Watch how John Conway's cellular automaton evolves"))
(define-key menu-bar-games-menu [hanoi]
  '(menu-item "Towers of Hanoi" hanoi
	      :help "Watch Towers-of-Hanoi puzzle solved by Emacs"))
(define-key menu-bar-games-menu [gomoku]
  '(menu-item "Gomoku"  gomoku
	      :help "Mark 5 contiguous squares (like tic-tac-toe)"))
(define-key menu-bar-games-menu [black-box]
  '(menu-item "Blackbox"  blackbox
	      :help "Find balls in a black box by shooting rays"))
(define-key menu-bar-games-menu [adventure]
  '(menu-item "Adventure"  dunnet
	      :help "Dunnet, a text Adventure game for Emacs"))
(define-key menu-bar-games-menu [5x5]
  '(menu-item "5x5" 5x5
	      :help "Fill in all the squares on a 5x5 board"))

677
(define-key menu-bar-tools-menu [calendar]
678 679 680 681 682 683
  '(menu-item "Display Calendar" calendar))
(define-key menu-bar-tools-menu [speedbar]
  '(menu-item "Display Speedbar" speedbar-frame-mode))
(define-key menu-bar-tools-menu [directory-search]
  '(menu-item "Directory Search" eudc-tools-menu
	      :help "Query directory servers via LDAP, CCSO PH/QI or BBDB"))
684
(define-key menu-bar-tools-menu [compose-mail]
685 686
  '(menu-item "Send Mail" compose-mail
	      :help "Send a mail message"))
687
(define-key menu-bar-tools-menu [rmail]
688 689 690 691 692 693 694 695 696 697
  '(menu-item "Read Mail" read-mail-command
	      :help "Read your mail and reply to it"))
(define-key menu-bar-tools-menu [gnus]
  '(menu-item "Read Net News" gnus
	      :help "Read network news groups"))

(define-key menu-bar-tools-menu [separator-vc]
  '("--"))

(defvar vc-menu-map (make-sparse-keymap "Version Control"))
698 699 700
(define-key menu-bar-tools-menu [pcl-cvs]
  `(menu-item "PCL-CVS" ,cvs-global-menu
	      :help "Module-level interface to CVS"))
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
(define-key menu-bar-tools-menu [vc]
  (list 'menu-item "Version Control" vc-menu-map
	:help "Interface to RCS, CVS, SCCS"))

(define-key menu-bar-tools-menu [separator-compare]
  '("--"))

(define-key menu-bar-tools-menu [ediff-misc]
  '(menu-item "Ediff Miscellanea" menu-bar-ediff-misc-menu
	      :help "Ediff manual, customization, sessions, etc."))
(define-key menu-bar-tools-menu [epatch]
  '(menu-item "Apply Patch" menu-bar-epatch-menu))
(define-key menu-bar-tools-menu [ediff-merge]
  '(menu-item "Merge" menu-bar-ediff-merge-menu
	      :help "Merge different revisions of files/directories"))
(define-key menu-bar-tools-menu [compare]
  '(menu-item "Compare (Ediff)" menu-bar-ediff-menu
	      :help "Display differences between files/directories"))


(define-key menu-bar-tools-menu [separator-spell]
  '("--"))

(define-key menu-bar-tools-menu [spell]
  '(menu-item "Spell Checking" ispell-menu-map))

(define-key menu-bar-tools-menu [separator-prog]
  '("--"))

(define-key menu-bar-tools-menu [gdb]
  '(menu-item "Debugger (GUD)..." gdb
	      :help "Debug a program from withing Emacs"))
(define-key menu-bar-tools-menu [shell-on-region]
  '(menu-item "Shell Command on Region..." shell-command-on-region
	      :enable mark-active
	      :help "Pass marked region to a shell command"))
(define-key menu-bar-tools-menu [shell]
  '(menu-item "Shell Command..." shell-command
	      :help "Invoke a shell command and catch its output"))
(define-key menu-bar-tools-menu [compile]
  '(menu-item "Compile..." compile
	      :help "Invoke compiler or Make, view compilation errors"))
(define-key menu-bar-tools-menu [grep]
  '(menu-item "Search Files (Grep)..." grep
	      :help "Search files for strings or regexps (with Grep)"))


;; The "Help" menu items

750 751
(defvar menu-bar-describe-menu (make-sparse-keymap "Describe"))

752 753 754 755 756 757 758 759 760 761 762 763
(define-key menu-bar-describe-menu [mule-diag]
  '(menu-item "Show All of Mule Status" mule-diag
	      :visible default-enable-multibyte-characters
	      :help "Display multilingual environment settings"))
(define-key menu-bar-describe-menu [describe-coding-system]
  '(menu-item "Describe Coding System..." describe-coding-system
	      :visible default-enable-multibyte-characters))
(define-key menu-bar-describe-menu [describe-input-method]
  '(menu-item "Describe Input Method..." describe-input-method
	      :visible default-enable-multibyte-characters
	      :help "Keyboard layout for specific input method"))
(define-key menu-bar-describe-menu [describe-language-environment]
764 765 766
  (list 'menu-item "Describe Language Environment"
	describe-language-environment-map
	:help "Show multilingual settings for a specific language"))
767 768

(define-key menu-bar-describe-menu [separator-desc-mule]
769
  '("--"))
770 771 772 773 774 775 776

(define-key menu-bar-describe-menu [list-keybindings]
  '(menu-item "List Key Bindings" describe-bindings
	      :help "Display a list of all current keybindings"))
(define-key menu-bar-describe-menu [list-keybindings]
  '(menu-item "List Key Bindings" describe-bindings
	      :help "Display a list of all current keybindings"))
777
(define-key menu-bar-describe-menu [describe-variable]
778 779
  '(menu-item "Describe Variable..." describe-variable
	      :help "Display documentation of variable/option"))
780
(define-key menu-bar-describe-menu [describe-function]
781 782
  '(menu-item "Describe Function..." describe-function
	      :help "Display documentation of function/command"))
783
(define-key menu-bar-describe-menu [describe-key]
784
  '(menu-item "Describe Key..." describe-key
785 786 787
	      ;; Users typically don't identify keys and menu items...
	      :help "Display documentation of command bound to a \
key (or menu-item)"))
788
(define-key menu-bar-describe-menu [apropos-variables]
789 790
  '(menu-item "Apropos Variables..." apropos-variable
	      :help "List variables whose names match a regexp"))
791
(define-key menu-bar-describe-menu [apropos-commands]
792 793
  '(menu-item "Apropos Commands..." apropos-command
	      :help "List commands whose names match a regexp"))
794
(define-key menu-bar-describe-menu [describe-mode]
795 796
  '(menu-item "Describe Buffer Modes" describe-mode
	      :help "Describe this buffer's major and minor mode"))
797 798 799 800

(defvar menu-bar-manuals-menu (make-sparse-keymap "Manuals"))

(define-key menu-bar-manuals-menu [man]
801 802
  '(menu-item "Read Man Page..." manual-entry
	      :help "Man-page docs for external commands and libraries"))
803 804 805
(define-key menu-bar-manuals-menu [sep2]
  '("--"))
(define-key menu-bar-manuals-menu [info]
806
  '(menu-item "Browse Manuals with Info" Info-directory
807 808 809 810 811 812 813
	      :help "Read any of the installed manuals"))
(define-key menu-bar-manuals-menu [command]
  '(menu-item "Find Command in Manual" Info-goto-emacs-command-node
	      :help "Display manual section that describes a command"))
(define-key menu-bar-manuals-menu [key]
  '(menu-item "Find Key in Manual" Info-goto-emacs-key-command-node
	      :help "Display manual section that describes a key"))
814

815 816 817 818 819
(define-key menu-bar-help-menu [eliza]
  '(menu-item "Emacs Psychiatrist" doctor
	      :help "Our doctor will help you feel better"))
(define-key menu-bar-help-menu [sep3]
  '("--"))
820
(define-key menu-bar-help-menu [describe-no-warranty]
821 822
  '(menu-item "(Non)Warranty" describe-no-warranty
	      :help "Explain that Emacs has NO WARRANTY"))
823
(define-key menu-bar-help-menu [describe-copying]
824 825
  '(menu-item "Copying Conditions" describe-copying
	      :help "Show the Emacs license (GPL)"))
826
(define-key menu-bar-help-menu [describe-distribution]
827 828
  '(menu-item "Getting New Versions" describe-distribution
	      :help "How to get latest versions of Emacs"))
829
(define-key menu-bar-help-menu [emacs-version]
830
  '(menu-item "Show Emacs Version" emacs-version))
831 832
(define-key menu-bar-help-menu [sep2]
  '("--"))
833
(define-key menu-bar-help-menu [finder-by-keyword]
834 835
  '(menu-item "Find Emacs Packages..." finder-by-keyword
	      :help "Find packages and features by keyword"))
836
(define-key menu-bar-help-menu [describe]
837 838
  (list 'menu-item "Describe" menu-bar-describe-menu
	:help "Describe commands, variables, keys"))
839
(define-key menu-bar-help-menu [manuals]
840
  (list 'menu-item "Manuals" menu-bar-manuals-menu))
841 842
(define-key menu-bar-help-menu [sep1]
  '("--"))
843 844 845
(define-key menu-bar-help-menu [report-emacs-bug]
  '(menu-item "Send Bug Report..." report-emacs-bug
	      :help "Send e-mail to Emacs maintainers"))
846 847 848
(define-key menu-bar-help-menu [emacs-manual]
  '(menu-item "Read the Emacs manual"
	      (lambda () (interactive) (info "emacs"))))
849 850 851 852 853 854 855
(define-key menu-bar-help-menu [emacs-problems]
  '(menu-item "Emacs Known Problems" view-emacs-problems))
(define-key menu-bar-help-menu [emacs-news]
  '(menu-item "Emacs News" view-emacs-news
	      :help "New features of this version"))
(define-key menu-bar-help-menu [emacs-faq]
  '(menu-item "Emacs FAQ" view-emacs-FAQ))
856 857 858 859
(define-key menu-bar-help-menu [emacs-tutorial-language-specific]
  '(menu-item "Emacs Tutorial (choose language)..."
	      (lambda () (interactive) (help-with-tutorial t))
	      :help "Learn how to use Emacs (choose a language)"))
860 861 862
(define-key menu-bar-help-menu [emacs-tutorial]
  '(menu-item "Emacs Tutorial" help-with-tutorial
	      :help "Learn how to use Emacs"))
863

Richard M. Stallman's avatar
Richard M. Stallman committed
864
(defun kill-this-buffer ()	; for the menubar
865
  "Kill the current buffer."
Richard M. Stallman's avatar
Richard M. Stallman committed
866 867 868
  (interactive)
  (kill-buffer (current-buffer)))

869 870 871 872 873 874 875
(defun kill-this-buffer-enabled-p ()
  (let ((count 0)
	(buffers (buffer-list)))
    (while buffers
      (or (string-match "^ " (buffer-name (car buffers)))
	  (setq count (1+ count)))
      (setq buffers (cdr buffers)))
876
    (and (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
877 878 879
	 (> count 1))))

(put 'dired 'menu-enable
880
     '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
881

882
;; Permit deleting frame if it would leave a visible or iconified frame.
883 884 885
(defun delete-frame-enabled-p ()
  "Return non-nil if `delete-frame' should be enabled in the menu bar."
  (let ((frames (frame-list))
Richard M. Stallman's avatar
Richard M. Stallman committed
886 887 888 889 890 891
	(count 0))
    (while frames
      (if (frame-visible-p (car frames))
	  (setq count (1+ count)))
      (setq frames (cdr frames)))
    (> count 1)))
892

Richard M. Stallman's avatar
Richard M. Stallman committed
893 894 895 896
(defcustom yank-menu-length 20
  "*Maximum length to display in the yank-menu."
  :type 'integer
  :group 'mouse)
897 898 899 900 901

(defun menu-bar-update-yank-menu (string old)
  (let ((front (car (cdr yank-menu)))
	(menu-string (if (<= (length string) yank-menu-length)
			 string
902 903 904 905
		       (concat
			(substring string 0 (/ yank-menu-length 2))
			"..."
			(substring string (- (/ yank-menu-length 2)))))))
906 907 908 909
    ;; Don't let the menu string be all dashes
    ;; because that has a special meaning in a menu.
    (if (string-match "\\`-+\\'" menu-string)
	(setq menu-string (concat menu-string " ")))
910 911 912 913
    ;; If we're supposed to be extending an existing string, and that
    ;; string really is at the front of the menu, then update it in place.
    (if (and old (or (eq old (car front))
		     (string= old (car front))))
914
	(progn
915 916 917 918 919 920 921 922 923
	  (setcar front string)
	  (setcar (cdr front) menu-string))
      (setcdr yank-menu
	      (cons
	       (cons string (cons menu-string 'menu-bar-select-yank))
	       (cdr yank-menu)))))
  (if (> (length (cdr yank-menu)) kill-ring-max)
      (setcdr (nthcdr kill-ring-max yank-menu) nil)))

924
(put 'menu-bar-select-yank 'apropos-inhibit t)
925 926 927 928
(defun menu-bar-select-yank ()
  (interactive "*")
  (push-mark (point))
  (insert last-command-event))
929

930 931
(defvar list-buffers-directory nil)

932 933
(defvar menu-bar-update-buffers-maxbuf)

934 935 936 937 938 939 940 941 942 943
(defun menu-bar-select-buffer ()
  (interactive)
  (switch-to-buffer last-command-event))

(defun menu-bar-select-frame ()
  (interactive)
  (make-frame-visible last-command-event)
  (raise-frame last-command-event)
  (select-frame last-command-event))

944 945
(defun menu-bar-update-buffers-1 (elt)
  (cons (format
946
	 (format "%%%ds  %%s%%s  %%s" menu-bar-update-buffers-maxbuf)
947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965
	 (cdr elt)
	 (if (buffer-modified-p (car elt))
	     "*" " ")
	 (save-excursion
	   (set-buffer (car elt))
	   (if buffer-read-only "%" " "))
	 (let ((file
		(or (buffer-file-name (car elt))
		    (save-excursion
		      (set-buffer (car elt))
		      list-buffers-directory)
		    "")))
	   (setq file (or (file-name-directory file)
			  ""))
	   (if (> (length file) 20)
	       (setq file (concat "..." (substring file -17))))
	   file))
	(car elt)))

966 967
(defvar menu-bar-buffers-menu-list-buffers-entry nil)

968
(defun menu-bar-update-buffers ()
969
  ;; If user discards the Buffers item, play along.
970
  (and (lookup-key (current-global-map) [menu-bar buffer])
971 972 973
       (frame-or-buffer-changed-p)
       (let ((buffers (buffer-list))
	     (frames (frame-list))
974
	     (maxlen 0)
975 976 977 978 979 980 981 982 983 984
	     buffers-menu frames-menu)
	 ;; If requested, list only the N most recently selected buffers.
	 (if (and (integerp buffers-menu-max-size)
		  (> buffers-menu-max-size 1))
	     (if (> (length buffers) buffers-menu-max-size)
		 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))

	 ;; Make the menu of buffers proper.
	 (setq buffers-menu
	       (cons "Select Buffer"
985 986 987
		     (let* ((buffer-list
			     (mapcar 'list buffers))
			    tail
988
			    (menu-bar-update-buffers-maxbuf 0)
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
			    alist
			    head)
		       ;; Put into each element of buffer-list
		       ;; the name for actual display,
		       ;; perhaps truncated in the middle.
		       (setq tail buffer-list)
		       (while tail
			 (let ((name (buffer-name (car (car tail)))))
			   (setcdr (car tail)
				   (if (> (length name) 27)
				       (concat (substring name 0 12)
					       "..."
					       (substring name -12))
				     name)))
			 (setq tail (cdr tail)))
		       ;; Compute the maximum length of any name.
		       (setq tail buffer-list)
1006
		       (while tail
1007
			 (or (eq ?\ (aref (cdr (car tail)) 0))
1008 1009
			     (setq menu-bar-update-buffers-maxbuf
				   (max menu-bar-update-buffers-maxbuf
1010
					(length (cdr (car tail))))))
1011
			 (setq tail (cdr tail)))
1012 1013 1014
		       ;; Set ALIST to an alist of the form
		       ;; ITEM-STRING . BUFFER
		       (setq tail buffer-list)
1015 1016
		       (while tail
			 (let ((elt (car tail)))
1017
			   (or (eq ?\ (aref (cdr elt) 0))
1018
			       (setq alist (cons
1019
					    (menu-bar-update-buffers-1 elt)
1020 1021 1022 1023 1024
					    alist)))
			   (and alist (> (length (car (car alist))) maxlen)
				(setq maxlen (length (car (car alist))))))
			 (setq tail (cdr tail)))
		       (setq alist (nreverse alist))
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043
		       ;; Make the menu item for list-buffers
		       ;; or reuse the one we already have.
		       ;; The advantage in reusing one
		       ;; is that it already has the keyboard equivalent
		       ;; cached, so we save the time to look that up again.
		       (or menu-bar-buffers-menu-list-buffers-entry
			   (setq menu-bar-buffers-menu-list-buffers-entry
				 (cons
				  'list-buffers
				  (cons
				   ""
				   'list-buffers))))
		       ;; Update the item string for menu's new width.
		       (setcar (cdr menu-bar-buffers-menu-list-buffers-entry)
			       (concat (make-string (max (- (/ maxlen 2) 8) 0)
						    ?\ )
				       "List All Buffers"))
		       ;; Now make the actual list of items,
		       ;; ending with the list-buffers item.
1044
		       (nconc (mapcar (lambda (pair)
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
					;; This is somewhat risque, to use
					;; the buffer name itself as the event
					;; type to define, but it works.
					;; It would not work to use the buffer
					;; since a buffer as an event has its
					;; own meaning.
					(nconc (list (buffer-name (cdr pair))
						     (car pair)
						     (cons nil nil))
					       'menu-bar-select-buffer))
1055
				      alist)
1056
			      (list menu-bar-buffers-menu-list-buffers-entry)))))
1057 1058 1059 1060


	 ;; Make a Frames menu if we have more than one frame.
	 (if (cdr frames)
1061 1062 1063 1064 1065 1066
	     (let ((name (concat (make-string (max (- (/ maxlen 2) 3) 0)
					      ?\ )
				 "Frames"))
		   (frames-menu
		    (cons 'keymap
			  (cons "Select Frame"
1067 1068 1069 1070 1071 1072 1073 1074
				(mapcar
				 (lambda (frame)
				   (nconc
				    (list frame
					  (cdr (assq 'name
						     (frame-parameters frame)))
					  (cons nil nil))
					  'menu-bar-select-frame))
1075 1076 1077 1078
					frames)))))
	       ;; Put it underneath the Buffers menu.
	       (setq buffers-menu (cons (cons 'frames (cons name frames-menu))
					buffers-menu))))
1079 1080
	 (if buffers-menu
	     (setq buffers-menu (cons 'keymap buffers-menu)))
1081
	 (define-key (current-global-map) [menu-bar buffer]
1082
	   (cons "Buffers" buffers-menu)))))
1083 1084

(add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
1085

1086 1087
(menu-bar-update-buffers)

1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104
;; this version is too slow
;;;(defun format-buffers-menu-line (buffer)
;;;  "Returns a string to represent the given buffer in the Buffer menu.
;;;nil means the buffer shouldn't be listed.  You can redefine this."
;;;  (if (string-match "\\` " (buffer-name buffer))
;;;      nil
;;;    (save-excursion
;;;     (set-buffer buffer)
;;;     (let ((size (buffer-size)))
;;;       (format "%s%s %-19s %6s %-15s %s"
;;;	       (if (buffer-modified-p) "*" " ")
;;;	       (if buffer-read-only "%" " ")
;;;	       (buffer-name)
;;;	       size
;;;	       mode-name
;;;	       (or (buffer-file-name) ""))))))

1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121
;;; Set up a menu bar menu for the minibuffer.

(mapcar
 (function
  (lambda (map)
    (define-key map [menu-bar minibuf]
      (cons "Minibuf" (make-sparse-keymap "Minibuf")))))
 (list minibuffer-local-ns-map
       minibuffer-local-must-match-map
       minibuffer-local-isearch-map
       minibuffer-local-map
       minibuffer-local-completion-map))

(mapcar
 (function
  (lambda (map)
    (define-key map [menu-bar minibuf ?\?]
1122 1123
      (list 'menu-item "List Completions" 'minibuffer-completion-help
	    :help "Display all possible completions"))
1124
    (define-key map [menu-bar minibuf space]
1125 1126
      (list 'menu-item "Complete Word" 'minibuffer-complete-word
	    :help "Complete at most one word"))
1127
    (define-key map [menu-bar minibuf tab]
1128 1129
      (list 'menu-item "Complete" 'minibuffer-complete
	    :help "Complete as far as possible"))
1130 1131 1132 1133 1134 1135 1136 1137
    ))
 (list minibuffer-local-must-match-map
       minibuffer-local-completion-map))

(mapcar
 (function
  (lambda (map)
    (define-key map [menu-bar minibuf quit]
1138 1139
      (list 'menu-item "Quit" 'keyboard-escape-quit
	    :help "Abort input and exit minibuffer"))
1140
    (define-key map [menu-bar minibuf return]
1141 1142
      (list 'menu-item "Enter" 'exit-minibuffer
	    :help "Terminate input and exit minibuffer"))
1143 1144 1145 1146 1147 1148 1149
    ))
 (list minibuffer-local-ns-map
       minibuffer-local-must-match-map
       minibuffer-local-isearch-map
       minibuffer-local-map
       minibuffer-local-completion-map))

Dave Love's avatar
Dave Love committed
1150 1151 1152 1153 1154 1155 1156 1157 1158
(defcustom menu-bar-mode nil
  "Toggle display of a menu bar on each frame.
Setting this variable directly does not take effect;
use either \\[customize] or the function `menu-bar-mode'."
  :set (lambda (symbol value)
	 (menu-bar-mode (or value 0)))
  :initialize 'custom-initialize-default
  :type 'boolean
  :group 'frames)