1 ;;; menu-bar.el --- define a default menu bar
3 ;; Copyright (C) 1993, 1994, 1995, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
8 ;; Keywords: internal, mouse
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
27 ;; Avishai Yacobi suggested some menu rearrangements.
35 (defcustom buffers-menu-max-size
10
36 "*Maximum number of entries which may appear on the Buffers menu.
37 If this is 10, then only the ten most-recently-selected buffers are shown.
38 If this is nil, then all buffers are shown.
39 A large number or nil slows down menu responsiveness."
40 :type
'(choice integer
41 (const :tag
"All" nil
))
44 ;; Don't clobber an existing menu-bar keymap, to preserve any menu-bar key
45 ;; definitions made in loaddefs.el.
46 (or (lookup-key global-map
[menu-bar
])
47 (define-key global-map
[menu-bar
] (make-sparse-keymap "menu-bar")))
48 (defvar menu-bar-help-menu
(make-sparse-keymap "Help"))
50 ;; Force Help item to come last, after the major mode's own items.
51 ;; The symbol used to be called `help', but that gets confused with the
53 (setq menu-bar-final-items
'(help-menu))
55 (define-key global-map
[menu-bar help-menu
] (cons "Help" menu-bar-help-menu
))
56 (defvar menu-bar-tools-menu
(make-sparse-keymap "Tools"))
57 (define-key global-map
[menu-bar tools
] (cons "Tools" menu-bar-tools-menu
))
58 ;; This definition is just to show what this looks like.
59 ;; It gets overridden below when menu-bar-update-buffers is called.
60 (define-key global-map
[menu-bar buffer
]
61 (cons "Buffers" (make-sparse-keymap "Buffers")))
62 (defvar menu-bar-options-menu
(make-sparse-keymap "Options"))
63 (define-key global-map
[menu-bar options
]
64 (cons "Options" menu-bar-options-menu
))
65 (defvar menu-bar-edit-menu
(make-sparse-keymap "Edit"))
66 (define-key global-map
[menu-bar edit
] (cons "Edit" menu-bar-edit-menu
))
67 (defvar menu-bar-file-menu
(make-sparse-keymap "File"))
68 (define-key global-map
[menu-bar file
] (cons "File" menu-bar-file-menu
))
70 ;; This alias is for compatibility with 19.28 and before.
71 (defvar menu-bar-files-menu menu-bar-file-menu
)
73 ;; This is referenced by some code below; it is defined in uniquify.el
74 (defvar uniquify-buffer-name-style
)
77 ;; The "File" menu items
78 (define-key menu-bar-file-menu
[exit-emacs
]
79 '(menu-item "Exit Emacs" save-buffers-kill-emacs
80 :help
"Save unsaved buffers, then exit"))
82 (define-key menu-bar-file-menu
[separator-exit
]
85 ;; Don't use delete-frame as event name because that is a special
87 (define-key menu-bar-file-menu
[delete-this-frame
]
88 '(menu-item "Delete Frame" delete-frame
89 :visible
(fboundp 'delete-frame
)
90 :enable
(delete-frame-enabled-p)
91 :help
"Delete currently selected frame"))
92 (define-key menu-bar-file-menu
[make-frame-on-display
]
93 '(menu-item "New Frame on Display..." make-frame-on-display
94 :visible
(fboundp 'make-frame-on-display
)
95 :help
"Open a new frame on another display"))
96 (define-key menu-bar-file-menu
[make-frame
]
97 '(menu-item "New Frame" make-frame-command
98 :visible
(fboundp 'make-frame-command
)
99 :help
"Open a new frame"))
101 (define-key menu-bar-file-menu
[one-window
]
102 '(menu-item "Remove Splits" delete-other-windows
103 :enable
(not (one-window-p t nil
))
104 :help
"Selected window grows to fill the whole frame"))
106 (define-key menu-bar-file-menu
[split-window
]
107 '(menu-item "Split Window" split-window-vertically
108 :enable
(and (menu-bar-menu-frame-live-and-visible-p)
109 (menu-bar-non-minibuffer-window-p))
110 :help
"Split selected window in two windows"))
112 (define-key menu-bar-file-menu
[separator-window
]
115 (define-key menu-bar-file-menu
[ps-print-region
]
116 '(menu-item "Postscript Print Region (B+W)" ps-print-region
118 :help
"Pretty-print marked region in black and white to PostScript printer"))
119 (define-key menu-bar-file-menu
[ps-print-buffer
]
120 '(menu-item "Postscript Print Buffer (B+W)" ps-print-buffer
121 :enable
(menu-bar-menu-frame-live-and-visible-p)
122 :help
"Pretty-print current buffer in black and white to PostScript printer"))
123 (define-key menu-bar-file-menu
[ps-print-region-faces
]
124 '(menu-item "Postscript Print Region" ps-print-region-with-faces
126 :help
"Pretty-print marked region to PostScript printer"))
127 (define-key menu-bar-file-menu
[ps-print-buffer-faces
]
128 '(menu-item "Postscript Print Buffer" ps-print-buffer-with-faces
129 :enable
(menu-bar-menu-frame-live-and-visible-p)
130 :help
"Pretty-print current buffer to PostScript printer"))
131 (define-key menu-bar-file-menu
[print-region
]
132 '(menu-item "Print Region" print-region
134 :help
"Print region between mark and current position"))
135 (define-key menu-bar-file-menu
[print-buffer
]
136 '(menu-item "Print Buffer" print-buffer
137 :enable
(menu-bar-menu-frame-live-and-visible-p)
138 :help
"Print current buffer with page headings"))
140 (define-key menu-bar-file-menu
[separator-print
]
143 (define-key menu-bar-file-menu
[recover-session
]
144 '(menu-item "Recover Crashed Session" recover-session
145 :enable
(and auto-save-list-file-prefix
147 (file-name-directory auto-save-list-file-prefix
))
149 (file-name-directory auto-save-list-file-prefix
)
153 (file-name-nondirectory
154 auto-save-list-file-prefix
)))
156 :help
"Recover edits from a crashed session"))
157 (define-key menu-bar-file-menu
[revert-buffer
]
158 '(menu-item "Revert Buffer" revert-buffer
159 :enable
(or revert-buffer-function
160 revert-buffer-insert-file-contents-function
161 (and buffer-file-number
162 (or (buffer-modified-p)
163 (not (verify-visited-file-modtime
164 (current-buffer))))))
165 :help
"Re-read current buffer from its file"))
166 (define-key menu-bar-file-menu
[write-file
]
167 '(menu-item "Save As..." write-file
168 :enable
(and (menu-bar-menu-frame-live-and-visible-p)
169 (menu-bar-non-minibuffer-window-p))
170 :help
"Write current buffer to another file"))
171 (define-key menu-bar-file-menu
[save-buffer
]
172 '(menu-item "Save" save-buffer
173 :enable
(and (buffer-modified-p)
175 (menu-bar-non-minibuffer-window-p))
176 :help
"Save current buffer to its file"))
178 (define-key menu-bar-file-menu
[separator-save
]
181 (define-key menu-bar-file-menu
[kill-buffer
]
182 '(menu-item "Close" kill-this-buffer
183 :enable
(kill-this-buffer-enabled-p)
184 :help
"Discard (kill) current buffer"))
185 (define-key menu-bar-file-menu
[insert-file
]
186 '(menu-item "Insert File..." insert-file
187 :enable
(menu-bar-non-minibuffer-window-p)
188 :help
"Insert another file into current buffer"))
189 (define-key menu-bar-file-menu
[dired]
190 '(menu-item "Open Directory..." dired
191 :enable (menu-bar-non-minibuffer-window-p)
192 :help "Read a directory, to operate on its files"))
193 (define-key menu-bar-file-menu [open-file]
194 '(menu-item "Open File..." find-file-existing
195 :enable (menu-bar-non-minibuffer-window-p)
196 :help "Read an existing file into an Emacs buffer"))
197 (define-key menu-bar-file-menu [new-file]
198 '(menu-item "Visit New File..." find-file
199 :enable (menu-bar-non-minibuffer-window-p)
200 :help "Specify a new file's name, to edit the file"))
203 ;; The "Edit" menu items
205 ;; The "Edit->Search" submenu
206 (defvar menu-bar-last-search-type nil
207 "Type of last non-incremental search command called from the menu.")
209 (defun nonincremental-repeat-search-forward ()
210 "Search forward for the previous search string or regexp."
213 ((and (eq menu-bar-last-search-type 'string)
215 (search-forward (car search-ring)))
216 ((and (eq menu-bar-last-search-type 'regexp)
218 (re-search-forward (car regexp-search-ring)))
220 (error "No previous search"))))
222 (defun nonincremental-repeat-search-backward ()
223 "Search backward for the previous search string or regexp."
226 ((and (eq menu-bar-last-search-type 'string)
228 (search-backward (car search-ring)))
229 ((and (eq menu-bar-last-search-type 'regexp)
231 (re-search-backward (car regexp-search-ring)))
233 (error "No previous search"))))
235 (defun nonincremental-search-forward (string)
236 "Read a string and search for it nonincrementally."
237 (interactive "sSearch for string: ")
238 (setq menu-bar-last-search-type 'string)
239 (if (equal string "")
240 (search-forward (car search-ring))
241 (isearch-update-ring string nil)
242 (search-forward string)))
244 (defun nonincremental-search-backward (string)
245 "Read a string and search backward for it nonincrementally."
246 (interactive "sSearch for string: ")
247 (setq menu-bar-last-search-type 'string)
248 (if (equal string "")
249 (search-backward (car search-ring))
250 (isearch-update-ring string nil)
251 (search-backward string)))
253 (defun nonincremental-re-search-forward (string)
254 "Read a regular expression and search for it nonincrementally."
255 (interactive "sSearch for regexp: ")
256 (setq menu-bar-last-search-type 'regexp)
257 (if (equal string "")
258 (re-search-forward (car regexp-search-ring))
259 (isearch-update-ring string t)
260 (re-search-forward string)))
262 (defun nonincremental-re-search-backward (string)
263 "Read a regular expression and search backward for it nonincrementally."
264 (interactive "sSearch for regexp: ")
265 (setq menu-bar-last-search-type 'regexp)
266 (if (equal string "")
267 (re-search-backward (car regexp-search-ring))
268 (isearch-update-ring string t)
269 (re-search-backward string)))
271 (defvar menu-bar-search-menu (make-sparse-keymap "Search"))
273 ;; The Edit->Search->Incremental Search menu
274 (defvar menu-bar-i-search-menu
275 (make-sparse-keymap "Incremental Search"))
277 (define-key menu-bar-i-search-menu [isearch-backward-regexp]
278 '(menu-item "Backward Regexp..." isearch-backward-regexp
279 :help "Search backwards for a regular expression as you type it"))
280 (define-key menu-bar-i-search-menu [isearch-forward-regexp]
281 '(menu-item "Forward Regexp..." isearch-forward-regexp
282 :help "Search forward for a regular expression as you type it"))
283 (define-key menu-bar-i-search-menu [isearch-backward]
284 '(menu-item "Backward String..." isearch-backward
285 :help "Search backwards for a string as you type it"))
286 (define-key menu-bar-i-search-menu [isearch-forward]
287 '(menu-item "Forward String..." isearch-forward
288 :help "Search forward for a string as you type it"))
291 (define-key menu-bar-search-menu [i-search]
292 (list 'menu-item "Incremental Search" menu-bar-i-search-menu
293 :help "Incremental Search finds partial matches while you type the search string.\nIt is most convenient from the keyboard. Try it!"))
294 (define-key menu-bar-search-menu [separator-tag-isearch]
297 (define-key menu-bar-search-menu [tags-continue]
298 '(menu-item "Continue Tags Search" tags-loop-continue
299 :help "Continue last tags search operation"))
300 (define-key menu-bar-search-menu [tags-srch]
301 '(menu-item "Search tagged files..." tags-search
302 :help "Search for a regexp in all tagged files"))
303 (define-key menu-bar-search-menu [separator-tag-search]
306 (define-key menu-bar-search-menu [repeat-search-back]
307 '(menu-item "Repeat Backwards" nonincremental-repeat-search-backward
308 :enable (or (and (eq menu-bar-last-search-type 'string)
310 (and (eq menu-bar-last-search-type 'regexp)
312 :help "Repeat last search backwards"))
313 (define-key menu-bar-search-menu [repeat-search-fwd]
314 '(menu-item "Repeat Forward" nonincremental-repeat-search-forward
315 :enable (or (and (eq menu-bar-last-search-type 'string)
317 (and (eq menu-bar-last-search-type 'regexp)
319 :help "Repeat last search forward"))
320 (define-key menu-bar-search-menu [separator-repeat-search]
323 (define-key menu-bar-search-menu [re-search-backward]
324 '(menu-item "Regexp Backwards..." nonincremental-re-search-backward
325 :help "Search backwards for a regular expression"))
326 (define-key menu-bar-search-menu [re-search-forward]
327 '(menu-item "Regexp Forward..." nonincremental-re-search-forward
328 :help "Search forward for a regular expression"))
330 (define-key menu-bar-search-menu [search-backward]
331 '(menu-item "String Backwards..." nonincremental-search-backward
332 :help "Search backwards for a string"))
333 (define-key menu-bar-search-menu [search-forward]
334 '(menu-item "String Forward..." nonincremental-search-forward
335 :help "Search forward for a string"))
337 ;; The Edit->Replace submenu
339 (defvar menu-bar-replace-menu (make-sparse-keymap "Replace"))
341 (define-key menu-bar-replace-menu [tags-repl-continue]
342 '(menu-item "Continue Replace" tags-loop-continue
343 :help "Continue last tags replace operation"))
344 (define-key menu-bar-replace-menu [tags-repl]
345 '(menu-item "Replace in tagged files..." tags-query-replace
346 :help "Interactively replace a regexp in all tagged files"))
347 (define-key menu-bar-replace-menu [separator-replace-tags]
350 (define-key menu-bar-replace-menu [query-replace-regexp]
351 '(menu-item "Replace Regexp..." query-replace-regexp
352 :enable (not buffer-read-only)
353 :help "Replace regular expression interactively, ask about each occurrence"))
354 (define-key menu-bar-replace-menu [query-replace]
355 '(menu-item "Replace String..." query-replace
356 :enable (not buffer-read-only)
357 :help "Replace string interactively, ask about each occurrence"))
359 ;;; Assemble the top-level Edit menu items.
360 (define-key menu-bar-edit-menu [props]
361 '(menu-item "Text Properties" facemenu-menu
362 :help "Change properties of text in region"))
364 (define-key menu-bar-edit-menu [fill]
365 '(menu-item "Fill" fill-region
366 :enable (and mark-active (not buffer-read-only))
368 "Fill text in region to fit between left and right margin"))
370 (define-key menu-bar-edit-menu [separator-bookmark]
373 (define-key menu-bar-edit-menu [bookmark]
374 '(menu-item "Bookmarks" menu-bar-bookmark-map
375 :help "Record positions and jump between them"))
377 (defvar menu-bar-goto-menu (make-sparse-keymap "Go To"))
379 (define-key menu-bar-goto-menu [set-tags-name]
380 '(menu-item "Set Tags File Name..." visit-tags-table
381 :help "Tell Tags commands which tag table file to use"))
383 (define-key menu-bar-goto-menu [separator-tag-file]
386 (define-key menu-bar-goto-menu [apropos-tags]
387 '(menu-item "Tags Apropos..." tags-apropos
388 :help "Find function/variables whose names match regexp"))
389 (define-key menu-bar-goto-menu [next-tag-otherw]
390 '(menu-item "Next Tag in Other Window"
391 menu-bar-next-tag-other-window
392 :enable (and (boundp 'tags-location-ring)
393 (not (ring-empty-p tags-location-ring)))
394 :help "Find next function/variable matching last tag name in another window"))
396 (defun menu-bar-next-tag-other-window ()
397 "Find the next definition of the tag already specified."
399 (find-tag-other-window nil t))
401 (defun menu-bar-next-tag ()
402 "Find the next definition of the tag already specified."
406 (define-key menu-bar-goto-menu [next-tag]
407 '(menu-item "Find Next Tag"
409 :enable (and (boundp 'tags-location-ring)
410 (not (ring-empty-p tags-location-ring)))
411 :help "Find next function/variable matching last tag name"))
412 (define-key menu-bar-goto-menu [find-tag-otherw]
413 '(menu-item "Find Tag in Other Window..." find-tag-other-window
414 :help "Find function/variable definition in another window"))
415 (define-key menu-bar-goto-menu [find-tag]
416 '(menu-item "Find Tag..." find-tag
417 :help "Find definition of function or variable"))
419 (define-key menu-bar-goto-menu [separator-tags]
422 (define-key menu-bar-goto-menu [end-of-buf]
423 '(menu-item "Goto End of Buffer" end-of-buffer))
424 (define-key menu-bar-goto-menu [beg-of-buf]
425 '(menu-item "Goto Beginning of Buffer" beginning-of-buffer))
426 (define-key menu-bar-goto-menu [go-to-pos]
427 '(menu-item "Goto Buffer Position..." goto-char
428 :help "Read a number N and go to buffer position N"))
429 (define-key menu-bar-goto-menu [go-to-line]
430 '(menu-item "Goto Line..." goto-line
431 :help "Read a line number and go to that line"))
433 (define-key menu-bar-edit-menu [goto]
434 (list 'menu-item "Go To" menu-bar-goto-menu))
436 (define-key menu-bar-edit-menu [replace]
437 (list 'menu-item "Replace" menu-bar-replace-menu))
439 (define-key menu-bar-edit-menu [search]
440 (list 'menu-item "Search" menu-bar-search-menu))
442 (define-key menu-bar-edit-menu [separator-search]
445 (define-key menu-bar-edit-menu [mark-whole-buffer]
446 '(menu-item "Select All" mark-whole-buffer
447 :help "Mark the whole buffer for a subsequent cut/copy."))
448 (define-key menu-bar-edit-menu [clear]
449 '(menu-item "Clear" delete-region
450 :enable (and mark-active
451 (not buffer-read-only)
452 (not (mouse-region-match)))
454 "Delete the text in region between mark and current position"))
455 (defvar yank-menu (cons "Select Yank" nil))
456 (fset 'yank-menu (cons 'keymap yank-menu))
457 (define-key menu-bar-edit-menu [select-paste]
458 '(menu-item "Select and Paste" yank-menu
459 :enable (and (cdr yank-menu) (not buffer-read-only))
460 :help "Paste (yank) text cut or copied earlier"))
461 (define-key menu-bar-edit-menu [paste]
462 '(menu-item "Paste" yank
464 ;; Emacs compiled --without-x doesn't have
465 ;; x-selection-exists-p.
466 (fboundp 'x-selection-exists-p)
467 (x-selection-exists-p) (not buffer-read-only))
468 :help "Paste (yank) text most recently cut/copied"))
469 (define-key menu-bar-edit-menu [copy]
470 '(menu-item "Copy" menu-bar-kill-ring-save
472 :help "Copy text in region between mark and current position"
473 :keys "\\[kill-ring-save]"))
474 (define-key menu-bar-edit-menu [cut]
475 '(menu-item "Cut" kill-region
476 :enable (and mark-active (not buffer-read-only))
478 "Cut (kill) text in region between mark and current position"))
479 (define-key menu-bar-edit-menu [undo]
480 '(menu-item "Undo" undo
481 :enable (and (not buffer-read-only)
482 (not (eq t buffer-undo-list))
483 (if (eq last-command 'undo)
485 (consp buffer-undo-list)))
486 :help "Undo last operation"))
489 (defun menu-bar-kill-ring-save (beg end)
491 (if (mouse-region-match)
492 (message "Selecting a region with the mouse does `copy' automatically")
493 (kill-ring-save beg end)))
495 ;; These are alternative definitions for the cut, paste and copy
496 ;; menu items. Use them if your system expects these to use the clipboard.
498 (put 'clipboard-kill-region 'menu-enable 'mark-active)
499 (put 'clipboard-kill-ring-save 'menu-enable 'mark-active)
500 (put 'clipboard-yank 'menu-enable
501 '(or (and (fboundp 'x-selection-exists-p) (x-selection-exists-p))
502 (x-selection-exists-p 'CLIPBOARD)))
504 (defun clipboard-yank ()
505 "Insert the clipboard contents, or the last stretch of killed text."
507 (let ((x-select-enable-clipboard t))
510 (defun clipboard-kill-ring-save (beg end)
511 "Copy region to kill ring, and save in the X clipboard."
513 (let ((x-select-enable-clipboard t))
514 (kill-ring-save beg end)))
516 (defun clipboard-kill-region (beg end)
517 "Kill the region, and save it in the X clipboard."
519 (let ((x-select-enable-clipboard t))
520 (kill-region beg end)))
522 (defun menu-bar-enable-clipboard ()
523 "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
524 Do the same for the keys of the same name."
526 ;; We can't use constant list structure here because it becomes pure,
527 ;; and because it gets modified with cache data.
528 (define-key menu-bar-edit-menu [paste]
529 (cons "Paste" (cons "Paste text from clipboard" 'clipboard-yank)))
530 (define-key menu-bar-edit-menu [copy]
531 (cons "Copy" (cons "Copy text in region to the clipboard"
532 'clipboard-kill-ring-save)))
533 (define-key menu-bar-edit-menu [cut]
534 (cons "Cut" (cons "Delete text in region and copy it to the clipboard"
535 'clipboard-kill-region)))
537 ;; These are Sun server keysyms for the Cut, Copy and Paste keys
538 ;; (also for XFree86 on Sun keyboard):
539 (define-key global-map [f20] 'clipboard-kill-region)
540 (define-key global-map [f16] 'clipboard-kill-ring-save)
541 (define-key global-map [f18] 'clipboard-yank)
543 (define-key global-map [cut] 'clipboard-kill-region)
544 (define-key global-map [copy] 'clipboard-kill-ring-save)
545 (define-key global-map [paste] 'clipboard-yank))
547 ;; The "Options" menu items
549 (defvar menu-bar-custom-menu (make-sparse-keymap "Customize"))
551 (define-key menu-bar-custom-menu [customize-apropos-groups]
552 '(menu-item "Groups Matching Regexp..." customize-apropos-groups
553 :help "Browse groups whose names match regexp"))
554 (define-key menu-bar-custom-menu [customize-apropos-faces]
555 '(menu-item "Faces Matching Regexp..." customize-apropos-faces
556 :help "Browse faces whose names match regexp"))
557 (define-key menu-bar-custom-menu [customize-apropos-options]
558 '(menu-item "Options Matching Regexp..." customize-apropos-options
559 :help "Browse options whose names match regexp"))
560 (define-key menu-bar-custom-menu [customize-apropos]
561 '(menu-item "Settings Matching Regexp..." customize-apropos
562 :help "Browse customizable settings whose names match regexp"))
563 (define-key menu-bar-custom-menu [separator-1]
565 (define-key menu-bar-custom-menu [customize-group]
566 '(menu-item "Specific Group..." customize-group
567 :help "Customize settings of specific group"))
568 (define-key menu-bar-custom-menu [customize-face]
569 '(menu-item "Specific Face..." customize-face
570 :help "Customize attributes of specific face"))
571 (define-key menu-bar-custom-menu [customize-option]
572 '(menu-item "Specific Option..." customize-option
573 :help "Customize value of specific option"))
574 (define-key menu-bar-custom-menu [separator-2]
576 (define-key menu-bar-custom-menu [customize-changed-options]
577 '(menu-item "New Options..." customize-changed-options
578 :help "Options added or changed in recent Emacs versions"))
579 (define-key menu-bar-custom-menu [customize-saved]
580 '(menu-item "Saved Options" customize-saved
581 :help "Customize previously saved options"))
582 (define-key menu-bar-custom-menu [separator-3]
584 (define-key menu-bar-custom-menu [customize-browse]
585 '(menu-item "Browse Customization Groups" customize-browse
586 :help "Browse all customization groups"))
587 (define-key menu-bar-custom-menu [customize]
588 '(menu-item "Top-level Customization Group" customize
589 :help "The master group called `Emacs'"))
591 ;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
593 (defmacro menu-bar-make-mm-toggle (fname doc help &optional props)
594 "Make a menu-item for a global minor mode toggle.
595 FNAME is the minor mode's name (variable and function).
596 DOC is the text to use for the menu entry.
597 HELP is the text to use for the tooltip.
598 PROPS are additional properties."
599 `'(menu-item ,doc ,fname
602 :button (:toggle . (and (default-boundp ',fname)
603 (default-value ',fname)))))
605 (defmacro menu-bar-make-toggle (name variable doc message help &rest body)
607 (defun ,name (&optional interactively)
608 ,(concat "Toggle whether to " (downcase (substring help 0 1))
609 (substring help 1) ".
610 In an interactive call, record this option as a candidate for saving
611 by \"Save Options\" in Custom buffers.")
613 (if ,(if body `(progn . ,body)
615 (custom-load-symbol ',variable)
616 (let ((set (or (get ',variable 'custom-set) 'set-default))
617 (get (or (get ',variable 'custom-get) 'default-value)))
618 (funcall set ',variable (not (funcall get ',variable))))))
619 (message ,message "enabled")
620 (message ,message "disabled"))
621 ;; The function `customize-mark-as-set' must only be called when
622 ;; a variable is set interactively, as the purpose is to mark it as
623 ;; a candidate for "Save Options", and we do not want to save options
624 ;; the user have already set explicitly in his init file.
625 (if interactively (customize-mark-as-set ',variable)))
626 '(menu-item ,doc ,name
628 :button (:toggle . (and (default-boundp ',variable)
629 (default-value ',variable))))))
631 ;;; Assemble all the top-level items of the "Options" menu
632 (define-key menu-bar-options-menu [customize]
633 (list 'menu-item "Customize Emacs" menu-bar-custom-menu
634 :help "Full customization of every Emacs feature"))
636 (defun menu-bar-options-save ()
637 "Save current values of Options menu items using Custom."
639 (let ((need-save nil))
640 ;; These are set with menu-bar-make-mm-toggle, which does not
641 ;; put on a customized-value property.
642 (dolist (elt '(line-number-mode column-number-mode size-indication-mode
643 cua-mode show-paren-mode transient-mark-mode
644 global-font-lock-mode blink-cursor-mode
645 display-time-mode display-battery-mode))
646 (and (customize-mark-to-save elt)
648 ;; These are set with `customize-set-variable'.
649 (dolist (elt '(scroll-bar-mode
650 debug-on-quit debug-on-error
651 tooltip-mode menu-bar-mode tool-bar-mode
652 save-place uniquify-buffer-name-style fringe-mode
653 indicate-empty-lines indicate-buffer-boundaries
655 current-language-environment default-input-method
656 ;; Saving `text-mode-hook' is somewhat questionable,
657 ;; as we might get more than we bargain for, if
658 ;; other code may has added hooks as well.
659 ;; Nonetheless, not saving it would like be confuse
661 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
663 (and (get elt 'customized-value)
664 (customize-mark-to-save elt)
666 ;; Save if we changed anything.
670 (define-key menu-bar-options-menu [save]
671 '(menu-item "Save Options" menu-bar-options-save
672 :help "Save options set from the menu above"))
674 (define-key menu-bar-options-menu [custom-separator]
677 (define-key menu-bar-options-menu [mouse-set-font]
678 '(menu-item "Set Font/Fontset..." mouse-set-font
679 :visible (display-multi-font-p)
680 :help "Select a font from list of known fonts/fontsets"))
682 ;; The "Show/Hide" submenu of menu "Options"
684 (defvar menu-bar-showhide-menu (make-sparse-keymap "Show/Hide"))
686 (define-key menu-bar-showhide-menu [column-number-mode]
687 (menu-bar-make-mm-toggle column-number-mode
689 "Show the current column number in the mode line"))
691 (define-key menu-bar-showhide-menu [line-number-mode]
692 (menu-bar-make-mm-toggle line-number-mode
694 "Show the current line number in the mode line"))
696 (define-key menu-bar-showhide-menu [size-indication-mode]
697 (menu-bar-make-mm-toggle size-indication-mode
699 "Show the size of the buffer in the mode line"))
701 (define-key menu-bar-showhide-menu [linecolumn-separator]
704 (define-key menu-bar-showhide-menu [showhide-battery]
705 (menu-bar-make-mm-toggle display-battery-mode
707 "Display battery status information in mode line"))
709 (define-key menu-bar-showhide-menu [showhide-date-time]
710 (menu-bar-make-mm-toggle display-time-mode
711 "Time, Load and Mail"
712 "Display time, system load averages and \
713 mail status in mode line"))
715 (define-key menu-bar-showhide-menu [datetime-separator]
718 (define-key menu-bar-showhide-menu [showhide-speedbar]
719 '(menu-item "Speedbar" speedbar-frame-mode
720 :help "Display a Speedbar quick-navigation frame"
722 . (and (boundp 'speedbar-frame)
723 (frame-live-p (symbol-value 'speedbar-frame))
725 (symbol-value 'speedbar-frame))))))
727 (defvar menu-bar-showhide-fringe-menu (make-sparse-keymap "Fringe"))
729 (defvar menu-bar-showhide-fringe-ind-menu
730 (make-sparse-keymap "Buffer boundaries"))
732 (defun menu-bar-showhide-fringe-ind-customize ()
733 "Show customization buffer for `indicate-buffer-boundaries'."
735 (customize-variable 'indicate-buffer-boundaries))
737 (define-key menu-bar-showhide-fringe-ind-menu [customize]
738 '(menu-item "Other (Customize)"
739 menu-bar-showhide-fringe-ind-customize
740 :help "Additional choices available through Custom buffer"
741 :visible (display-graphic-p)))
743 (defun menu-bar-showhide-fringe-ind-mixed ()
744 "Display top and bottom indicators in opposite fringes, arrows in right."
746 (customize-set-variable 'indicate-buffer-boundaries
747 '((t . right) (top . left))))
749 (define-key menu-bar-showhide-fringe-ind-menu [mixed]
750 '(menu-item "Opposite, Arrows Right" menu-bar-showhide-fringe-ind-mixed
752 "Show top/bottom indicators in opposite fringes, arrows in right"
753 :visible (display-graphic-p)
754 :button (:radio . (eq indicate-buffer-boundaries
755 '((t . right) (top . left))))))
757 (defun menu-bar-showhide-fringe-ind-box ()
758 "Display top and bottom indicators in opposite fringes."
760 (customize-set-variable 'indicate-buffer-boundaries
761 '((top . left) (bottom . right))))
763 (define-key menu-bar-showhide-fringe-ind-menu [box]
764 '(menu-item "Opposite, No Arrows" menu-bar-showhide-fringe-ind-box
765 :help "Show top/bottom indicators in opposite fringes, no arrows"
766 :visible (display-graphic-p)
767 :button (:radio . (eq indicate-buffer-boundaries
768 '((top . left) (bottom . right))))))
770 (defun menu-bar-showhide-fringe-ind-right ()
771 "Display buffer boundaries and arrows in the right fringe."
773 (customize-set-variable 'indicate-buffer-boundaries 'right))
775 (define-key menu-bar-showhide-fringe-ind-menu [right]
776 '(menu-item "In Right Fringe" menu-bar-showhide-fringe-ind-right
777 :help "Show buffer boundaries and arrows in right fringe"
778 :visible (display-graphic-p)
779 :button (:radio . (eq indicate-buffer-boundaries 'right))))
781 (defun menu-bar-showhide-fringe-ind-left ()
782 "Display buffer boundaries and arrows in the left fringe."
784 (customize-set-variable 'indicate-buffer-boundaries 'left))
786 (define-key menu-bar-showhide-fringe-ind-menu [left]
787 '(menu-item "In Left Fringe" menu-bar-showhide-fringe-ind-left
788 :help "Show buffer boundaries and arrows in left fringe"
789 :visible (display-graphic-p)
790 :button (:radio . (eq indicate-buffer-boundaries 'left))))
792 (defun menu-bar-showhide-fringe-ind-none ()
793 "Do not display any buffer boundary indicators."
795 (customize-set-variable 'indicate-buffer-boundaries nil))
797 (define-key menu-bar-showhide-fringe-ind-menu [none]
798 '(menu-item "No Indicators" menu-bar-showhide-fringe-ind-none
799 :help "Hide all buffer boundary indicators and arrows"
800 :visible (display-graphic-p)
801 :button (:radio . (eq indicate-buffer-boundaries nil))))
803 (define-key menu-bar-showhide-fringe-menu [showhide-fringe-ind]
804 (list 'menu-item "Buffer Boundaries" menu-bar-showhide-fringe-ind-menu
805 :visible `(display-graphic-p)
806 :help "Indicate buffer boundaries in fringe"))
808 (define-key menu-bar-showhide-fringe-menu [indicate-empty-lines]
809 (menu-bar-make-toggle toggle-indicate-empty-lines indicate-empty-lines
810 "Empty Line Indicators"
811 "Indicating of empty lines %s"
812 "Indicate trailing empty lines in fringe"))
814 (defun menu-bar-showhide-fringe-menu-customize ()
815 "Show customization buffer for `fringe-mode'."
817 (customize-variable 'fringe-mode))
819 (define-key menu-bar-showhide-fringe-menu [customize]
820 '(menu-item "Customize Fringe" menu-bar-showhide-fringe-menu-customize
821 :help "Detailed customization of fringe"
822 :visible (display-graphic-p)))
824 (defun menu-bar-showhide-fringe-menu-customize-reset ()
825 "Reset the fringe mode: display fringes on both sides of a window."
827 (customize-set-variable 'fringe-mode nil))
829 (define-key menu-bar-showhide-fringe-menu [default]
830 '(menu-item "Default" menu-bar-showhide-fringe-menu-customize-reset
831 :help "Default width fringe on both left and right side"
832 :visible (display-graphic-p)
833 :button (:radio . (eq fringe-mode nil))))
835 (defun menu-bar-showhide-fringe-menu-customize-left ()
836 "Display fringes only on the left of each window."
839 (customize-set-variable 'fringe-mode '(nil . 0)))
841 (define-key menu-bar-showhide-fringe-menu [left]
842 '(menu-item "On the Left" menu-bar-showhide-fringe-menu-customize-left
843 :help "Fringe only on the left side"
844 :visible (display-graphic-p)
845 :button (:radio . (equal fringe-mode '(nil . 0)))))
847 (defun menu-bar-showhide-fringe-menu-customize-right ()
848 "Display fringes only on the right of each window."
851 (customize-set-variable 'fringe-mode '(0 . nil)))
853 (define-key menu-bar-showhide-fringe-menu [right]
854 '(menu-item "On the Right" menu-bar-showhide-fringe-menu-customize-right
855 :help "Fringe only on the right side"
856 :visible (display-graphic-p)
857 :button (:radio . (equal fringe-mode '(0 . nil)))))
859 (defun menu-bar-showhide-fringe-menu-customize-disable ()
860 "Do not display window fringes."
863 (customize-set-variable 'fringe-mode 0))
865 (define-key menu-bar-showhide-fringe-menu [none]
866 '(menu-item "None" menu-bar-showhide-fringe-menu-customize-disable
867 :help "Turn off fringe"
868 :visible (display-graphic-p)
869 :button (:radio . (eq fringe-mode 0))))
871 (define-key menu-bar-showhide-menu [showhide-fringe]
872 (list 'menu-item "Fringe" menu-bar-showhide-fringe-menu
873 :visible `(display-graphic-p)
874 :help "Select fringe mode"))
876 (defvar menu-bar-showhide-scroll-bar-menu (make-sparse-keymap "Scroll-bar"))
878 (define-key menu-bar-showhide-scroll-bar-menu [right]
879 '(menu-item "On the Right"
880 menu-bar-right-scroll-bar
881 :help "Scroll-bar on the right side"
882 :visible (display-graphic-p)
883 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
884 (frame-parameters))) 'right))))
885 (defun menu-bar-right-scroll-bar ()
886 "Display scroll bars on the right of each window."
888 (customize-set-variable 'scroll-bar-mode 'right))
890 (define-key menu-bar-showhide-scroll-bar-menu [left]
891 '(menu-item "On the Left"
892 menu-bar-left-scroll-bar
893 :help "Scroll-bar on the left side"
894 :visible (display-graphic-p)
895 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
896 (frame-parameters))) 'left))))
898 (defun menu-bar-left-scroll-bar ()
899 "Display scroll bars on the left of each window."
901 (customize-set-variable 'scroll-bar-mode 'left))
903 (define-key menu-bar-showhide-scroll-bar-menu [none]
905 menu-bar-no-scroll-bar
906 :help "Turn off scroll-bar"
907 :visible (display-graphic-p)
908 :button (:radio . (eq (cdr (assq 'vertical-scroll-bars
909 (frame-parameters))) nil))))
911 (defun menu-bar-no-scroll-bar ()
912 "Turn off scroll bars."
914 (customize-set-variable 'scroll-bar-mode nil))
916 (define-key menu-bar-showhide-menu [showhide-scroll-bar]
917 (list 'menu-item "Scroll-bar" menu-bar-showhide-scroll-bar-menu
918 :visible `(display-graphic-p)
919 :help "Select scroll-bar mode"))
921 (define-key menu-bar-showhide-menu [showhide-tooltip-mode]
922 (list 'menu-item "Tooltips" 'tooltip-mode
923 :help "Toggle tooltips on/off"
924 :visible `(and (display-graphic-p) (fboundp 'x-show-tip))
925 :button `(:toggle . tooltip-mode)))
927 (define-key menu-bar-showhide-menu [menu-bar-mode]
928 '(menu-item "Menu-bar" menu-bar-mode
929 :help "Toggle menu-bar on/off"
930 :button (:toggle . menu-bar-mode)))
932 (define-key menu-bar-showhide-menu [showhide-tool-bar]
933 (list 'menu-item "Tool-bar" 'tool-bar-mode
934 :help "Turn tool-bar on/off"
935 :visible `(display-graphic-p)
936 :button `(:toggle . tool-bar-mode)))
938 (define-key menu-bar-options-menu [showhide]
939 (list 'menu-item "Show/Hide" menu-bar-showhide-menu
940 :help "Toggle on/off various display features"))
942 (define-key menu-bar-options-menu [showhide-separator]
945 (define-key menu-bar-options-menu [mule]
946 ;; It is better not to use backquote here,
947 ;; because that makes a bootstrapping problem
948 ;; if you need to recompile all the Lisp files using interpreted code.
949 (list 'menu-item "Mule (Multilingual Environment)" mule-menu-keymap
950 ;; Most of the MULE menu actually does make sense in unibyte mode,
951 ;; e.g. language selection.
952 ;;; ':visible 'default-enable-multibyte-characters
953 ':help "Default language, encodings, input method"))
954 ;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
955 ;(define-key menu-bar-options-menu [preferences]
956 ; (list 'menu-item "Preferences" menu-bar-preferences-menu
957 ; :help "Toggle important global options"))
959 (define-key menu-bar-options-menu [mule-separator]
962 (define-key menu-bar-options-menu [debug-on-quit]
963 (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
964 "Enter Debugger on Quit/C-g" "Debug on Quit %s"
965 "Enter Lisp debugger when C-g is pressed"))
966 (define-key menu-bar-options-menu [debug-on-error]
967 (menu-bar-make-toggle toggle-debug-on-error debug-on-error
968 "Enter Debugger on Error" "Debug on Error %s"
969 "Enter Lisp debugger when an error is signaled"))
970 (define-key menu-bar-options-menu [debugger-separator]
973 (define-key menu-bar-options-menu [blink-cursor-mode]
974 (menu-bar-make-mm-toggle blink-cursor-mode
976 "Whether the cursor blinks (Blink Cursor mode)"))
977 (define-key menu-bar-options-menu [cursor-separator]
980 (define-key menu-bar-options-menu [save-place]
981 (menu-bar-make-toggle toggle-save-place-globally save-place
982 "Save Place in Files between Sessions"
983 "Saving place in files %s"
984 "Visit files of previous session when restarting Emacs"
986 ;; Do it by name, to avoid a free-variable
987 ;; warning during byte compilation.
989 'save-place (not (symbol-value 'save-place)))))
991 (define-key menu-bar-options-menu [uniquify]
992 (menu-bar-make-toggle toggle-uniquify-buffer-names uniquify-buffer-name-style
993 "Use Directory Names in Buffer Names"
994 "Directory name in buffer names (uniquify) %s"
995 "Uniquify buffer names by adding parent directory names"
997 (setq uniquify-buffer-name-style
998 (if (not uniquify-buffer-name-style)
1001 (define-key menu-bar-options-menu [edit-options-separator]
1003 (define-key menu-bar-options-menu [cua-mode]
1004 (menu-bar-make-mm-toggle cua-mode
1005 "C-x/C-c/C-v Cut and Paste (CUA)"
1006 "Use C-z/C-x/C-c/C-v keys for undo/cut/copy/paste"))
1008 (define-key menu-bar-options-menu [case-fold-search]
1009 (menu-bar-make-toggle toggle-case-fold-search case-fold-search
1010 "Case-Insensitive Search"
1011 "Case-Insensitive Search %s"
1012 "Ignore letter-case in search"))
1014 (defun menu-bar-text-mode-auto-fill ()
1016 (toggle-text-mode-auto-fill)
1017 ;; This is somewhat questionable, as `text-mode-hook'
1018 ;; might have changed outside customize.
1019 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
1020 (customize-mark-as-set 'text-mode-hook))
1022 (define-key menu-bar-options-menu [auto-fill-mode]
1023 '(menu-item "Word Wrap in Text Modes"
1024 menu-bar-text-mode-auto-fill
1025 :help "Automatically fill text between left and right margins (Auto Fill)"
1026 :button (:toggle . (if (listp text-mode-hook)
1027 (member 'turn-on-auto-fill text-mode-hook)
1028 (eq 'turn-on-auto-fill text-mode-hook)))))
1029 (define-key menu-bar-options-menu [truncate-lines]
1030 '(menu-item "Truncate Long Lines in this Buffer"
1031 toggle-truncate-lines
1032 :help "Truncate long lines on the screen"
1033 :button (:toggle . truncate-lines)
1034 :enable (menu-bar-menu-frame-live-and-visible-p)))
1036 (define-key menu-bar-options-menu [highlight-separator]
1038 (define-key menu-bar-options-menu [highlight-paren-mode]
1039 (menu-bar-make-mm-toggle show-paren-mode
1040 "Paren Match Highlighting"
1041 "Highlight matching/mismatched parentheses at cursor (Show Paren mode)"))
1042 (define-key menu-bar-options-menu [transient-mark-mode]
1043 (menu-bar-make-mm-toggle transient-mark-mode
1044 "Active Region Highlighting"
1045 "Make text in active region stand out in color (Transient Mark mode)"
1046 (:enable (not cua-mode))))
1047 (define-key menu-bar-options-menu [toggle-global-lazy-font-lock-mode]
1048 (menu-bar-make-mm-toggle global-font-lock-mode
1049 "Syntax Highlighting"
1050 "Colorize text based on language syntax (Global Font Lock mode)"))
1053 ;; The "Tools" menu items
1055 (defun send-mail-item-name ()
1056 (let* ((known-send-mail-commands '((sendmail-user-agent . "sendmail")
1057 (mh-e-user-agent . "MH")
1058 (message-user-agent . "Gnus Message")
1059 (gnus-user-agent . "Gnus")))
1060 (name (assq mail-user-agent known-send-mail-commands)))
1062 (setq name (cdr name))
1063 (setq name (symbol-name mail-user-agent))
1064 (if (string-match "\\(.+\\)-user-agent" name)
1065 (setq name (match-string 1 name))))
1068 (defun read-mail-item-name ()
1069 (let* ((known-rmail-commands '((rmail . "RMAIL")
1072 (known (assq read-mail-command known-rmail-commands)))
1073 (if known (cdr known) (symbol-name read-mail-command))))
1075 (defvar menu-bar-games-menu (make-sparse-keymap "Games"))
1077 (define-key menu-bar-tools-menu [games]
1078 (list 'menu-item "Games" menu-bar-games-menu))
1080 (define-key menu-bar-tools-menu [separator-games]
1083 (define-key menu-bar-games-menu [zone]
1084 '(menu-item "Zone Out" zone
1085 :help "Play tricks with Emacs display when Emacs is idle"))
1086 (define-key menu-bar-games-menu [yow]
1087 '(menu-item "Random Quotation" yow
1088 :help "Display a random Zippy quotation"))
1089 (define-key menu-bar-games-menu [tetris]
1090 '(menu-item "Tetris" tetris))
1091 (define-key menu-bar-games-menu [solitaire]
1092 '(menu-item "Solitaire" solitaire))
1093 (define-key menu-bar-games-menu [snake]
1094 '(menu-item "Snake" snake
1095 :help "Move snake around avoiding collisions"))
1096 (define-key menu-bar-games-menu [mult]
1097 '(menu-item "Multiplication Puzzle" mpuz
1098 :help "Exercise brain with multiplication"))
1099 (define-key menu-bar-games-menu [life]
1100 '(menu-item "Life" life
1101 :help "Watch how John Conway's cellular automaton evolves"))
1102 (define-key menu-bar-games-menu [hanoi]
1103 '(menu-item "Towers of Hanoi" hanoi
1104 :help "Watch Towers-of-Hanoi puzzle solved by Emacs"))
1105 (define-key menu-bar-games-menu [gomoku]
1106 '(menu-item "Gomoku" gomoku
1107 :help "Mark 5 contiguous squares (like tic-tac-toe)"))
1108 (define-key menu-bar-games-menu [black-box]
1109 '(menu-item "Blackbox" blackbox
1110 :help "Find balls in a black box by shooting rays"))
1111 (define-key menu-bar-games-menu [adventure]
1112 '(menu-item "Adventure" dunnet
1113 :help "Dunnet, a text Adventure game for Emacs"))
1114 (define-key menu-bar-games-menu [5x5]
1115 '(menu-item "5x5" 5x5
1116 :help "Fill in all the squares on a 5x5 board"))
1118 (define-key menu-bar-tools-menu [simple-calculator]
1119 '(menu-item "Simple Calculator" calculator
1120 :help "Invoke the Emacs built-in quick calculator"))
1121 (define-key menu-bar-tools-menu [calc]
1122 '(menu-item "Programmable Calculator" calc
1123 :help "Invoke the Emacs built-in full scientific calculator"))
1124 (define-key menu-bar-tools-menu [calendar]
1125 '(menu-item "Display Calendar" calendar))
1127 (define-key menu-bar-tools-menu [separator-net]
1130 (define-key menu-bar-tools-menu [directory-search]
1131 '(menu-item "Directory Search" eudc-tools-menu
1132 :help "Query directory servers via LDAP, CCSO PH/QI or BBDB"))
1133 (define-key menu-bar-tools-menu [compose-mail]
1135 'menu-item `(format "Send Mail (with %s)" (send-mail-item-name))
1137 :visible `(and mail-user-agent (not (eq mail-user-agent 'ignore)))
1138 :help "Send a mail message"))
1139 (define-key menu-bar-tools-menu [rmail]
1141 'menu-item `(format "Read Mail (with %s)" (read-mail-item-name))
1143 :visible `(and read-mail-command (not (eq read-mail-command 'ignore)))
1144 :help "Read your mail and reply to it"))
1146 (defun menu-bar-read-mail ()
1147 "Read mail using `read-mail-command'."
1149 (call-interactively read-mail-command))
1151 (define-key menu-bar-tools-menu [gnus]
1152 '(menu-item "Read Net News (Gnus)" gnus
1153 :help "Read network news groups"))
1155 (define-key menu-bar-tools-menu [separator-vc]
1158 (defvar vc-menu-map (make-sparse-keymap "Version Control"))
1159 (define-key menu-bar-tools-menu [pcl-cvs]
1160 '(menu-item "PCL-CVS" cvs-global-menu
1161 :help "Module-level interface to CVS"))
1162 (define-key menu-bar-tools-menu [vc]
1163 (list 'menu-item "Version Control" vc-menu-map
1164 :help "Interface to RCS, CVS, SCCS"))
1166 (define-key menu-bar-tools-menu [separator-compare]
1169 (define-key menu-bar-tools-menu [ediff-misc]
1170 '(menu-item "Ediff Miscellanea" menu-bar-ediff-misc-menu
1171 :help "Ediff manual, customization, sessions, etc."))
1172 (define-key menu-bar-tools-menu [epatch]
1173 '(menu-item "Apply Patch" menu-bar-epatch-menu))
1174 (define-key menu-bar-tools-menu [ediff-merge]
1175 '(menu-item "Merge" menu-bar-ediff-merge-menu
1176 :help "Merge different revisions of files/directories"))
1177 (define-key menu-bar-tools-menu [compare]
1178 '(menu-item "Compare (Ediff)" menu-bar-ediff-menu
1179 :help "Display differences between files/directories"))
1182 (define-key menu-bar-tools-menu [separator-spell]
1185 (define-key menu-bar-tools-menu [spell]
1186 '(menu-item "Spell Checking" ispell-menu-map))
1188 (define-key menu-bar-tools-menu [separator-prog]
1191 (define-key menu-bar-tools-menu [gdb]
1192 '(menu-item "Debugger (GDB)..." gdb
1193 :help "Debug a program from within Emacs with GDB"))
1194 (define-key menu-bar-tools-menu [shell-on-region]
1195 '(menu-item "Shell Command on Region..." shell-command-on-region
1197 :help "Pass marked region to a shell command"))
1198 (define-key menu-bar-tools-menu [shell]
1199 '(menu-item "Shell Command..." shell-command
1200 :help "Invoke a shell command and catch its output"))
1201 (define-key menu-bar-tools-menu [compile]
1202 '(menu-item "Compile..." compile
1203 :help "Invoke compiler or Make, view compilation errors"))
1204 (define-key menu-bar-tools-menu [grep]
1205 '(menu-item "Search Files (with grep)..." grep
1206 :help "Search files for strings or regexps (with grep)"))
1209 ;; The "Help" menu items
1211 (defvar menu-bar-describe-menu (make-sparse-keymap "Describe"))
1213 (define-key menu-bar-describe-menu [mule-diag]
1214 '(menu-item "Show All of Mule Status" mule-diag
1215 :visible default-enable-multibyte-characters
1216 :help "Display multilingual environment settings"))
1217 (define-key menu-bar-describe-menu [describe-coding-system-briefly]
1218 '(menu-item "Describe Coding System (Briefly)..."
1219 describe-current-coding-system-briefly
1220 :visible default-enable-multibyte-characters))
1221 (define-key menu-bar-describe-menu [describe-coding-system]
1222 '(menu-item "Describe Coding System..." describe-coding-system
1223 :visible default-enable-multibyte-characters))
1224 (define-key menu-bar-describe-menu [describe-input-method]
1225 '(menu-item "Describe Input Method..." describe-input-method
1226 :visible default-enable-multibyte-characters
1227 :help "Keyboard layout for specific input method"))
1228 (define-key menu-bar-describe-menu [describe-language-environment]
1229 (list 'menu-item "Describe Language Environment"
1230 describe-language-environment-map
1231 :help "Show multilingual settings for a specific language"))
1233 (define-key menu-bar-describe-menu [separator-desc-mule]
1236 (define-key menu-bar-describe-menu [list-keybindings]
1237 '(menu-item "List Key Bindings" describe-bindings
1238 :help "Display a list of all current keybindings"))
1239 (define-key menu-bar-describe-menu [describe-current-display-table]
1240 '(menu-item "Describe Display Table" describe-current-display-table
1241 :help "Describe the current display table"))
1242 (define-key menu-bar-describe-menu [describe-face]
1243 '(menu-item "Describe Face..." describe-face
1244 :help "Display the properties of a face"))
1245 (define-key menu-bar-describe-menu [describe-variable]
1246 '(menu-item "Describe Variable..." describe-variable
1247 :help "Display documentation of variable/option"))
1248 (define-key menu-bar-describe-menu [describe-function]
1249 '(menu-item "Describe Function..." describe-function
1250 :help "Display documentation of function/command"))
1251 (define-key menu-bar-describe-menu [describe-key-1]
1252 '(menu-item "Describe Key or Mouse Operation..." describe-key
1253 ;; Users typically don't identify keys and menu items...
1254 :help "Display documentation of command bound to a \
1255 key, a click, or a menu-item"))
1256 (define-key menu-bar-describe-menu [describe-mode]
1257 '(menu-item "Describe Buffer Modes" describe-mode
1258 :help "Describe this buffer's major and minor mode"))
1260 (defvar menu-bar-apropos-menu (make-sparse-keymap "Apropos"))
1261 (defun menu-bar-read-lispref ()
1262 "Display the Emacs Lisp Reference manual in Info mode."
1266 (defun menu-bar-read-lispintro ()
1267 "Display the Introduction to Emacs Lisp Programming in Info mode."
1271 (defun search-emacs-glossary ()
1272 "Display the Glossary node of the Emacs manual in Info mode."
1274 (info "(emacs)Glossary"))
1276 (defun emacs-index-search (topic)
1277 "Look up TOPIC in the indices of the Emacs User Manual."
1278 (interactive "sSubject to look up: ")
1282 (defun elisp-index-search (topic)
1283 "Look up TOPIC in the indices of the Emacs Lisp Reference Manual."
1284 (interactive "sSubject to look up: ")
1288 (define-key menu-bar-apropos-menu [apropos-documentation]
1289 '(menu-item "Search Documentation Strings..." apropos-documentation
1291 "Find functions and variables whose doc strings match a regexp"))
1292 (define-key menu-bar-apropos-menu [apropos]
1293 '(menu-item "Find Any Object by Name..." apropos
1294 :help "Find symbols of any kind whose names match a regexp"))
1295 (define-key menu-bar-apropos-menu [apropos-value]
1296 '(menu-item "Find Options by Value..." apropos-value
1297 :help "Find variables whose values match a regexp"))
1298 (define-key menu-bar-apropos-menu [apropos-variables]
1299 '(menu-item "Find Options by Name..." apropos-variable
1300 :help "Find variables whose names match a regexp"))
1301 (define-key menu-bar-apropos-menu [apropos-commands]
1302 '(menu-item "Find Commands by Name..." apropos-command
1303 :help "Find commands whose names match a regexp"))
1304 (define-key menu-bar-apropos-menu [sep1]
1306 (define-key menu-bar-apropos-menu [elisp-index-search]
1307 '(menu-item "Look Up Subject in ELisp Manual..." elisp-index-search
1308 :help "Find description of a subject in Emacs Lisp manual"))
1309 (define-key menu-bar-apropos-menu [emacs-index-search]
1310 '(menu-item "Look Up Subject in User Manual..." emacs-index-search
1311 :help "Find description of a subject in Emacs User manual"))
1312 (define-key menu-bar-apropos-menu [emacs-glossary]
1313 '(menu-item "Emacs Terminology" search-emacs-glossary
1314 :help "Display the Glossary section of the Emacs manual"))
1316 (defvar menu-bar-manuals-menu (make-sparse-keymap "More Manuals"))
1318 (define-key menu-bar-manuals-menu [man]
1319 '(menu-item "Read Man Page..." manual-entry
1320 :help "Man-page docs for external commands and libraries"))
1321 (define-key menu-bar-manuals-menu [sep2]
1323 (define-key menu-bar-manuals-menu [order-emacs-manuals]
1324 '(menu-item "Ordering Manuals" view-order-manuals
1325 :help "How to order manuals from the Free Software Foundation"))
1326 (define-key menu-bar-manuals-menu [info]
1327 '(menu-item "All Other Manuals (Info)" Info-directory
1328 :help "Read any of the installed manuals"))
1329 (define-key menu-bar-manuals-menu [info-elisp]
1330 '(menu-item "Emacs Lisp Reference" menu-bar-read-lispref
1331 :help "Read the Emacs Lisp Reference manual"))
1332 (define-key menu-bar-manuals-menu [info-elintro]
1333 '(menu-item "Introduction to Emacs Lisp" menu-bar-read-lispintro
1334 :help "Read the Introduction to Emacs Lisp Programming"))
1335 (define-key menu-bar-manuals-menu [sep3]
1337 (define-key menu-bar-manuals-menu [command]
1338 '(menu-item "Find Command in Manual..." Info-goto-emacs-command-node
1339 :help "Display manual section that describes a command"))
1340 (define-key menu-bar-manuals-menu [key]
1341 '(menu-item "Find Key in Manual..." Info-goto-emacs-key-command-node
1342 :help "Display manual section that describes a key"))
1344 (define-key menu-bar-help-menu [eliza]
1345 '(menu-item "Emacs Psychiatrist" doctor
1346 :help "Our doctor will help you feel better"))
1347 (define-key menu-bar-help-menu [sep4]
1349 (define-key menu-bar-help-menu [describe-no-warranty]
1350 '(menu-item "(Non)Warranty" describe-no-warranty
1351 :help "Explain that Emacs has NO WARRANTY"))
1352 (define-key menu-bar-help-menu [describe-copying]
1353 '(menu-item "Copying Conditions" describe-copying
1354 :help "Show the Emacs license (GPL)"))
1355 (define-key menu-bar-help-menu [describe-distribution]
1356 '(menu-item "Getting New Versions" describe-distribution
1357 :help "How to get latest versions of Emacs"))
1358 (define-key menu-bar-help-menu [more]
1359 '(menu-item "Find Extra Packages"
1360 menu-bar-help-extra-packages
1361 :help "Where to find some extra packages and possible updates"))
1362 (defun menu-bar-help-extra-packages ()
1363 "Display help about some additional packages available for Emacs."
1365 (let (enable-local-variables)
1366 (view-file (expand-file-name "MORE.STUFF"
1369 (define-key menu-bar-help-menu [about]
1370 '(menu-item "About Emacs" display-splash-screen
1371 :help "Display version number, copyright info, and basic help"))
1372 (define-key menu-bar-help-menu [sep2]
1374 (define-key menu-bar-help-menu [finder-by-keyword]
1375 '(menu-item "Find Emacs Packages" finder-by-keyword
1376 :help "Find packages and features by keyword"))
1377 (define-key menu-bar-help-menu [manuals]
1378 (list 'menu-item "More Manuals" menu-bar-manuals-menu
1379 :help "Search and browse on-line manuals"))
1380 (define-key menu-bar-help-menu [emacs-manual]
1381 '(menu-item "Read the Emacs Manual" info-emacs-manual
1382 :help "Full documentation of Emacs features"))
1383 (define-key menu-bar-help-menu [describe]
1384 (list 'menu-item "Describe" menu-bar-describe-menu
1385 :help "Describe commands, variables, keys"))
1386 (define-key menu-bar-help-menu [apropos]
1387 (list 'menu-item "Search Documentation" menu-bar-apropos-menu
1388 :help "Look up terms, find commands, options, etc. (Apropos)"))
1389 (define-key menu-bar-help-menu [sep1]
1391 (define-key menu-bar-help-menu [report-emacs-bug]
1392 '(menu-item "Send Bug Report..." report-emacs-bug
1393 :help "Send e-mail to Emacs maintainers"))
1394 (define-key menu-bar-help-menu [emacs-problems]
1395 '(menu-item "Emacs Known Problems" view-emacs-problems))
1396 (define-key menu-bar-help-menu [emacs-news]
1397 '(menu-item "Emacs News" view-emacs-news
1398 :help "New features of this version"))
1399 (define-key menu-bar-help-menu [emacs-faq]
1400 '(menu-item "Emacs FAQ" view-emacs-FAQ))
1402 (defun help-with-tutorial-spec-language ()
1403 "Use the Emacs tutorial, specifying which language you want."
1405 (help-with-tutorial t))
1407 (define-key menu-bar-help-menu [emacs-tutorial-language-specific]
1408 '(menu-item "Emacs Tutorial (choose language)..."
1409 help-with-tutorial-spec-language
1410 :help "Learn how to use Emacs (choose a language)"))
1411 (define-key menu-bar-help-menu [emacs-tutorial]
1412 '(menu-item "Emacs Tutorial" help-with-tutorial
1413 :help "Learn how to use Emacs"))
1415 (defun menu-bar-menu-frame-live-and-visible-p ()
1416 "Return non-nil if the menu frame is alive and visible.
1417 The menu frame is the frame for which we are updating the menu."
1418 (let ((menu-frame (if (display-multi-frame-p) menu-updating-frame
1420 (and (frame-live-p menu-frame)
1421 (frame-visible-p menu-frame))))
1423 (defun menu-bar-non-minibuffer-window-p ()
1424 "Return non-nil if selected window of the menu frame is not a minibuf window.
1426 See the documentation of `menu-bar-menu-frame-live-and-visible-p'
1427 for the definition of the menu frame."
1428 (let ((menu-frame (if (display-multi-frame-p) menu-updating-frame
1430 (not (window-minibuffer-p (frame-selected-window menu-frame)))))
1432 (defun kill-this-buffer () ; for the menubar
1433 "Kill the current buffer."
1435 (kill-buffer (current-buffer)))
1437 (defun kill-this-buffer-enabled-p ()
1439 (buffers (buffer-list)))
1441 (or (string-match "^ " (buffer-name (car buffers)))
1442 (setq count (1+ count)))
1443 (setq buffers (cdr buffers)))
1444 (and (menu-bar-non-minibuffer-window-p)
1447 (put 'dired 'menu-enable '(menu-bar-non-minibuffer-window-p))
1449 ;; Permit deleting frame if it would leave a visible or iconified frame.
1450 (defun delete-frame-enabled-p ()
1451 "Return non-nil if `delete-frame' should be enabled in the menu bar."
1452 (let ((frames (frame-list))
1455 (if (frame-visible-p (car frames))
1456 (setq count (1+ count)))
1457 (setq frames (cdr frames)))
1460 (defcustom yank-menu-length 20
1461 "*Maximum length to display in the yank-menu."
1465 (defun menu-bar-update-yank-menu (string old)
1466 (let ((front (car (cdr yank-menu)))
1467 (menu-string (if (<= (length string) yank-menu-length)
1470 (substring string 0 (/ yank-menu-length 2))
1472 (substring string (- (/ yank-menu-length 2)))))))
1473 ;; Don't let the menu string be all dashes
1474 ;; because that has a special meaning in a menu.
1475 (if (string-match "\\`-+\\'" menu-string)
1476 (setq menu-string (concat menu-string " ")))
1477 ;; If we're supposed to be extending an existing string, and that
1478 ;; string really is at the front of the menu, then update it in place.
1479 (if (and old (or (eq old (car front))
1480 (string= old (car front))))
1482 (setcar front string)
1483 (setcar (cdr front) menu-string))
1486 (cons string (cons menu-string 'menu-bar-select-yank))
1488 (if (> (length (cdr yank-menu)) kill-ring-max)
1489 (setcdr (nthcdr kill-ring-max yank-menu) nil)))
1491 (put 'menu-bar-select-yank 'apropos-inhibit t)
1492 (defun menu-bar-select-yank ()
1495 (insert last-command-event))
1498 (defcustom buffers-menu-show-directories 'unless-uniquify
1499 "If non-nil, show directories in the Buffers menu for buffers that have them.
1500 The special value `unless-uniquify' means that directories will be shown
1501 unless `uniquify-buffer-name-style' is non-nil (in which case, buffer
1502 names should include enough of a buffer's directory to distinguish it
1503 from other buffers).
1505 Setting this variable directly does not take effect until next time the
1506 Buffers menu is regenerated."
1507 :set (lambda (symbol value)
1509 (menu-bar-update-buffers t))
1510 :initialize 'custom-initialize-default
1511 :type '(choice (const :tag "Never" nil)
1512 (const :tag "Unless uniquify is enabled" unless-uniquify)
1513 (const :tag "Always" t))
1516 (defcustom buffers-menu-show-status t
1517 "If non-nil, show modified/read-only status of buffers in the Buffers menu.
1518 Setting this variable directly does not take effect until next time the
1519 Buffers menu is regenerated."
1520 :set (lambda (symbol value)
1522 (menu-bar-update-buffers t))
1523 :initialize 'custom-initialize-default
1527 (defvar list-buffers-directory nil)
1529 (defvar menu-bar-update-buffers-maxbuf)
1531 (defun menu-bar-select-buffer ()
1533 (switch-to-buffer last-command-event))
1535 (defun menu-bar-select-frame ()
1538 (dolist (f (frame-list))
1539 (when (equal last-command-event (frame-parameter f 'name))
1541 ;; FRAME can be nil when user specifies the selected frame.
1542 (setq frame (or frame (selected-frame)))
1543 (make-frame-visible frame)
1545 (select-frame frame)))
1547 (defun menu-bar-update-buffers-1 (elt)
1548 (let* ((buf (car elt))
1550 (and (if (eq buffers-menu-show-directories 'unless-uniquify)
1551 (or (not (boundp 'uniquify-buffer-name-style))
1552 (null uniquify-buffer-name-style))
1553 buffers-menu-show-directories)
1554 (or (buffer-file-name buf)
1555 (buffer-local-value 'list-buffers-directory buf)))))
1557 (setq file (file-name-directory file)))
1558 (when (and file (> (length file) 20))
1559 (setq file (concat "..." (substring file -17))))
1560 (cons (if buffers-menu-show-status
1561 (let ((mod (if (buffer-modified-p buf) "*" ""))
1562 (ro (if (buffer-local-value 'buffer-read-only buf) "%" "")))
1564 (format "%s %s%s -- %s" (cdr elt) mod ro file)
1565 (format "%s %s%s" (cdr elt) mod ro)))
1567 (format "%s -- %s" (cdr elt) file)
1571 ;; Used to cache the menu entries for commands in the Buffers menu
1572 (defvar menu-bar-buffers-menu-command-entries nil)
1574 (defun menu-bar-update-buffers (&optional force)
1575 ;; If user discards the Buffers item, play along.
1576 (and (lookup-key (current-global-map) [menu-bar buffer])
1577 (or force (frame-or-buffer-changed-p))
1578 (let ((buffers (buffer-list))
1579 (frames (frame-list))
1580 buffers-menu frames-menu)
1581 ;; If requested, list only the N most recently selected buffers.
1582 (if (and (integerp buffers-menu-max-size)
1583 (> buffers-menu-max-size 1))
1584 (if (> (length buffers) buffers-menu-max-size)
1585 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
1587 ;; Make the menu of buffers proper.
1590 (mapcar 'list buffers))
1591 (menu-bar-update-buffers-maxbuf 0)
1593 ;; Put into each element of buffer-list
1594 ;; the name for actual display,
1595 ;; perhaps truncated in the middle.
1596 (dolist (buf buffer-list)
1597 (let ((name (buffer-name (car buf))))
1599 (if (> (length name) 27)
1600 (concat (substring name 0 12)
1602 (substring name -12))
1604 ;; Compute the maximum length of any name.
1605 (dolist (buf buffer-list)
1606 (unless (eq ?\ (aref (cdr buf) 0))
1607 (setq menu-bar-update-buffers-maxbuf
1608 (max menu-bar-update-buffers-maxbuf
1609 (length (cdr buf))))))
1610 ;; Set ALIST to an alist of the form
1611 ;; ITEM-STRING . BUFFER
1612 (dolist (buf buffer-list)
1613 (unless (eq ?\ (aref (cdr buf) 0))
1614 (push (menu-bar-update-buffers-1 buf) alist)))
1615 ;; Now make the actual list of items, and add
1616 ;; some miscellaneous buffer commands to the end.
1617 (mapcar (lambda (pair)
1618 ;; This is somewhat risque, to use
1619 ;; the buffer name itself as the event
1620 ;; type to define, but it works.
1621 ;; It would not work to use the buffer
1622 ;; since a buffer as an event has its
1624 (nconc (list (buffer-name (cdr pair))
1627 'menu-bar-select-buffer))
1630 ;; Make a Frames menu if we have more than one frame.
1634 (cons "Select Frame"
1638 (list (frame-parameter frame 'name)
1639 (frame-parameter frame 'name)
1641 'menu-bar-select-frame))
1643 ;; Put it after the normal buffers
1646 `((frames-separator "--")
1647 (frames menu-item "Frames" ,frames-menu))))))
1649 ;; Add in some normal commands at the end of the menu. We use
1650 ;; the copy cached in `menu-bar-buffers-menu-command-entries'
1651 ;; if it's been set already. Note that we can't use constant
1652 ;; lists for the menu-entries, because the low-level menu-code
1654 (unless menu-bar-buffers-menu-command-entries
1655 (setq menu-bar-buffers-menu-command-entries
1656 (list '(command-separator "--")
1661 :help "Switch to the \"next\" buffer in a cyclic order")
1666 :help "Switch to the \"previous\" buffer in a cyclic order")
1667 (list 'select-named-buffer
1669 "Select Named Buffer..."
1671 :help "Prompt for a buffer name, and select that buffer in the current window")
1672 (list 'list-all-buffers
1676 :help "Pop up a window listing all emacs buffers"
1679 (nconc buffers-menu menu-bar-buffers-menu-command-entries))
1681 (setq buffers-menu (cons 'keymap (cons "Select Buffer" buffers-menu)))
1682 (define-key (current-global-map) [menu-bar buffer]
1683 ;; Call copy-sequence so the string is not pure.
1684 (cons (copy-sequence "Buffers") buffers-menu)))))
1686 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
1688 (menu-bar-update-buffers)
1690 ;; this version is too slow
1691 ;;(defun format-buffers-menu-line (buffer)
1692 ;; "Returns a string to represent the given buffer in the Buffer menu.
1693 ;;nil means the buffer shouldn't be listed. You can redefine this."
1694 ;; (if (string-match "\\` " (buffer-name buffer))
1697 ;; (set-buffer buffer)
1698 ;; (let ((size (buffer-size)))
1699 ;; (format "%s%s %-19s %6s %-15s %s"
1700 ;; (if (buffer-modified-p) "*" " ")
1701 ;; (if buffer-read-only "%" " ")
1705 ;; (or (buffer-file-name) ""))))))
1707 ;;; Set up a menu bar menu for the minibuffer.
1709 (dolist (map (list minibuffer-local-map
1710 ;; This shouldn't be necessary, but there's a funny
1711 ;; bug in keymap.c that I don't understand yet. -stef
1712 minibuffer-local-completion-map))
1713 (define-key map [menu-bar minibuf]
1714 (cons "Minibuf" (make-sparse-keymap "Minibuf"))))
1716 (let ((map minibuffer-local-completion-map))
1717 (define-key map [menu-bar minibuf ?\?]
1718 (list 'menu-item "List Completions" 'minibuffer-completion-help
1719 :help "Display all possible completions"))
1720 (define-key map [menu-bar minibuf space]
1721 (list 'menu-item "Complete Word" 'minibuffer-complete-word
1722 :help "Complete at most one word"))
1723 (define-key map [menu-bar minibuf tab]
1724 (list 'menu-item "Complete" 'minibuffer-complete
1725 :help "Complete as far as possible")))
1727 (let ((map minibuffer-local-map))
1728 (define-key map [menu-bar minibuf quit]
1729 (list 'menu-item "Quit" 'keyboard-escape-quit
1730 :help "Abort input and exit minibuffer"))
1731 (define-key map [menu-bar minibuf return]
1732 (list 'menu-item "Enter" 'exit-minibuffer
1733 :help "Terminate input and exit minibuffer")))
1736 ;; This comment is taken from tool-bar.el near
1737 ;; (put 'tool-bar-mode ...)
1738 ;; We want to pretend the menu bar by standard is on, as this will make
1739 ;; customize consider disabling the menu bar a customization, and save
1740 ;; that. We could do this for real by setting :init-value below, but
1741 ;; that would overwrite disabling the tool bar from X resources.
1742 (put 'menu-bar-mode 'standard-value '(t))
1745 (define-minor-mode menu-bar-mode
1746 "Toggle display of a menu bar on each frame.
1747 This command applies to all frames that exist and frames to be
1748 created in the future.
1749 With a numeric argument, if the argument is positive,
1750 turn on menu bars; otherwise, turn off menu bars."
1754 ;; Make menu-bar-mode and default-frame-alist consistent.
1755 (let ((lines (if menu-bar-mode 1 0)))
1756 ;; Alter existing frames...
1757 (mapc (lambda (frame)
1758 (modify-frame-parameters frame
1759 (list (cons 'menu-bar-lines lines))))
1761 ;; ...and future ones.
1762 (let ((elt (assq 'menu-bar-lines default-frame-alist)))
1765 (add-to-list 'default-frame-alist (cons 'menu-bar-lines lines)))))
1767 ;; Make the message appear when Emacs is idle. We can not call message
1768 ;; directly. The minor-mode message "Menu-bar mode disabled" comes
1769 ;; after this function returns, overwriting any message we do here.
1770 (when (and (interactive-p) (not menu-bar-mode))
1771 (run-with-idle-timer 0 nil 'message
1772 "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear."))
1777 ;;; arch-tag: 6e6a3c22-4ec4-4d3d-8190-583f8ef94ced
1778 ;;; menu-bar.el ends here