Commit | Line | Data |
---|---|---|
55535639 | 1 | ;;; menu-bar.el --- define a default menu bar |
235aa29b | 2 | |
ba318903 | 3 | ;; Copyright (C) 1993-1995, 2000-2014 Free Software Foundation, Inc. |
b578f267 | 4 | |
b59e2fba | 5 | ;; Author: Richard M. Stallman |
34dc21db | 6 | ;; Maintainer: emacs-devel@gnu.org |
dbcee71a | 7 | ;; Keywords: internal, mouse |
bd78fa1d | 8 | ;; Package: emacs |
235aa29b | 9 | |
1db87953 RS |
10 | ;; This file is part of GNU Emacs. |
11 | ||
eb3fa2cf | 12 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
1db87953 | 13 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
14 | ;; the Free Software Foundation, either version 3 of the License, or |
15 | ;; (at your option) any later version. | |
1db87953 RS |
16 | |
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. | |
21 | ||
22 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 23 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
1db87953 | 24 | |
260130bb KH |
25 | ;; Avishai Yacobi suggested some menu rearrangements. |
26 | ||
55535639 PJ |
27 | ;;; Commentary: |
28 | ||
b578f267 EN |
29 | ;;; Code: |
30 | ||
b016851c SM |
31 | ;; This is referenced by some code below; it is defined in uniquify.el |
32 | (defvar uniquify-buffer-name-style) | |
33 | ||
34 | ;; From emulation/cua-base.el; used below | |
35 | (defvar cua-enable-cua-keys) | |
36 | ||
37 | ||
b132f2b1 RM |
38 | ;; Don't clobber an existing menu-bar keymap, to preserve any menu-bar key |
39 | ;; definitions made in loaddefs.el. | |
40 | (or (lookup-key global-map [menu-bar]) | |
41 | (define-key global-map [menu-bar] (make-sparse-keymap "menu-bar"))) | |
ffbdd83d | 42 | |
5f161884 JD |
43 | ;; Force Help item to come last, after the major mode's own items. |
44 | ;; The symbol used to be called `help', but that gets confused with the | |
45 | ;; help key. | |
46 | (setq menu-bar-final-items '(help-menu)) | |
b3edb781 | 47 | |
7f315c7c | 48 | ;; This definition is just to show what this looks like. |
bf902855 SM |
49 | ;; It gets modified in place when menu-bar-update-buffers is called. |
50 | (defvar global-buffers-menu-map (make-sparse-keymap "Buffers")) | |
1b009b97 | 51 | |
aab705a2 | 52 | ;; Only declared obsolete (and only made a proper alias) in 23.3. |
b016851c SM |
53 | (define-obsolete-variable-alias |
54 | 'menu-bar-files-menu 'menu-bar-file-menu "22.1") | |
55 | (defvar menu-bar-file-menu | |
56 | (let ((menu (make-sparse-keymap "File"))) | |
57 | ||
58 | ;; The "File" menu items | |
1ec4b7b2 SM |
59 | (bindings--define-key menu [exit-emacs] |
60 | '(menu-item "Quit" save-buffers-kill-terminal | |
61 | :help "Save unsaved buffers, then exit")) | |
1becddbb | 62 | |
1ec4b7b2 | 63 | (bindings--define-key menu [separator-exit] |
b016851c SM |
64 | menu-bar-separator) |
65 | ||
66 | ;; Don't use delete-frame as event name because that is a special | |
67 | ;; event. | |
1ec4b7b2 SM |
68 | (bindings--define-key menu [delete-this-frame] |
69 | '(menu-item "Delete Frame" delete-frame | |
b016851c SM |
70 | :visible (fboundp 'delete-frame) |
71 | :enable (delete-frame-enabled-p) | |
1ec4b7b2 SM |
72 | :help "Delete currently selected frame")) |
73 | (bindings--define-key menu [make-frame-on-display] | |
74 | '(menu-item "New Frame on Display..." make-frame-on-display | |
b016851c | 75 | :visible (fboundp 'make-frame-on-display) |
1ec4b7b2 SM |
76 | :help "Open a new frame on another display")) |
77 | (bindings--define-key menu [make-frame] | |
78 | '(menu-item "New Frame" make-frame-command | |
b016851c | 79 | :visible (fboundp 'make-frame-command) |
1ec4b7b2 | 80 | :help "Open a new frame")) |
b016851c | 81 | |
1ec4b7b2 | 82 | (bindings--define-key menu [separator-frame] |
b8f7ff0d MR |
83 | menu-bar-separator) |
84 | ||
1ec4b7b2 SM |
85 | (bindings--define-key menu [one-window] |
86 | '(menu-item "Remove Other Windows" delete-other-windows | |
b016851c | 87 | :enable (not (one-window-p t nil)) |
1ec4b7b2 | 88 | :help "Make selected window fill whole frame")) |
b8f7ff0d | 89 | |
1ec4b7b2 SM |
90 | (bindings--define-key menu [new-window-on-right] |
91 | '(menu-item "New Window on Right" split-window-right | |
b8f7ff0d MR |
92 | :enable (and (menu-bar-menu-frame-live-and-visible-p) |
93 | (menu-bar-non-minibuffer-window-p)) | |
1ec4b7b2 | 94 | :help "Make new window on right of selected one")) |
b016851c | 95 | |
1ec4b7b2 SM |
96 | (bindings--define-key menu [new-window-below] |
97 | '(menu-item "New Window Below" split-window-below | |
b016851c SM |
98 | :enable (and (menu-bar-menu-frame-live-and-visible-p) |
99 | (menu-bar-non-minibuffer-window-p)) | |
1ec4b7b2 | 100 | :help "Make new window below selected one")) |
b016851c | 101 | |
1ec4b7b2 | 102 | (bindings--define-key menu [separator-window] |
b016851c SM |
103 | menu-bar-separator) |
104 | ||
1ec4b7b2 SM |
105 | (bindings--define-key menu [ps-print-region] |
106 | '(menu-item "PostScript Print Region (B+W)" ps-print-region | |
b016851c | 107 | :enable mark-active |
1ec4b7b2 SM |
108 | :help "Pretty-print marked region in black and white to PostScript printer")) |
109 | (bindings--define-key menu [ps-print-buffer] | |
110 | '(menu-item "PostScript Print Buffer (B+W)" ps-print-buffer | |
b016851c | 111 | :enable (menu-bar-menu-frame-live-and-visible-p) |
1ec4b7b2 SM |
112 | :help "Pretty-print current buffer in black and white to PostScript printer")) |
113 | (bindings--define-key menu [ps-print-region-faces] | |
114 | '(menu-item "PostScript Print Region" | |
b016851c SM |
115 | ps-print-region-with-faces |
116 | :enable mark-active | |
1ec4b7b2 SM |
117 | :help "Pretty-print marked region to PostScript printer")) |
118 | (bindings--define-key menu [ps-print-buffer-faces] | |
119 | '(menu-item "PostScript Print Buffer" | |
b016851c SM |
120 | ps-print-buffer-with-faces |
121 | :enable (menu-bar-menu-frame-live-and-visible-p) | |
1ec4b7b2 SM |
122 | :help "Pretty-print current buffer to PostScript printer")) |
123 | (bindings--define-key menu [print-region] | |
124 | '(menu-item "Print Region" print-region | |
b016851c | 125 | :enable mark-active |
1ec4b7b2 SM |
126 | :help "Print region between mark and current position")) |
127 | (bindings--define-key menu [print-buffer] | |
128 | '(menu-item "Print Buffer" print-buffer | |
b016851c | 129 | :enable (menu-bar-menu-frame-live-and-visible-p) |
1ec4b7b2 | 130 | :help "Print current buffer with page headings")) |
b016851c | 131 | |
1ec4b7b2 | 132 | (bindings--define-key menu [separator-print] |
b016851c SM |
133 | menu-bar-separator) |
134 | ||
1ec4b7b2 SM |
135 | (bindings--define-key menu [recover-session] |
136 | '(menu-item "Recover Crashed Session" recover-session | |
b016851c SM |
137 | :enable |
138 | (and auto-save-list-file-prefix | |
139 | (file-directory-p | |
140 | (file-name-directory auto-save-list-file-prefix)) | |
141 | (directory-files | |
142 | (file-name-directory auto-save-list-file-prefix) | |
143 | nil | |
144 | (concat "\\`" | |
145 | (regexp-quote | |
146 | (file-name-nondirectory | |
147 | auto-save-list-file-prefix))) | |
148 | t)) | |
1ec4b7b2 SM |
149 | :help "Recover edits from a crashed session")) |
150 | (bindings--define-key menu [revert-buffer] | |
151 | '(menu-item "Revert Buffer" revert-buffer | |
0b908bf2 GM |
152 | :enable (or (not (eq revert-buffer-function |
153 | 'revert-buffer--default)) | |
154 | (not (eq | |
155 | revert-buffer-insert-file-contents-function | |
156 | 'revert-buffer-insert-file-contents--default-function)) | |
b016851c SM |
157 | (and buffer-file-number |
158 | (or (buffer-modified-p) | |
159 | (not (verify-visited-file-modtime | |
160 | (current-buffer)))))) | |
1ec4b7b2 SM |
161 | :help "Re-read current buffer from its file")) |
162 | (bindings--define-key menu [write-file] | |
163 | '(menu-item "Save As..." write-file | |
b016851c SM |
164 | :enable (and (menu-bar-menu-frame-live-and-visible-p) |
165 | (menu-bar-non-minibuffer-window-p)) | |
1ec4b7b2 SM |
166 | :help "Write current buffer to another file")) |
167 | (bindings--define-key menu [save-buffer] | |
168 | '(menu-item "Save" save-buffer | |
b016851c SM |
169 | :enable (and (buffer-modified-p) |
170 | (buffer-file-name) | |
171 | (menu-bar-non-minibuffer-window-p)) | |
1ec4b7b2 | 172 | :help "Save current buffer to its file")) |
b016851c | 173 | |
1ec4b7b2 | 174 | (bindings--define-key menu [separator-save] |
b016851c SM |
175 | menu-bar-separator) |
176 | ||
177 | ||
1ec4b7b2 SM |
178 | (bindings--define-key menu [kill-buffer] |
179 | '(menu-item "Close" kill-this-buffer | |
b016851c | 180 | :enable (kill-this-buffer-enabled-p) |
1ec4b7b2 SM |
181 | :help "Discard (kill) current buffer")) |
182 | (bindings--define-key menu [insert-file] | |
183 | '(menu-item "Insert File..." insert-file | |
b016851c | 184 | :enable (menu-bar-non-minibuffer-window-p) |
1ec4b7b2 SM |
185 | :help "Insert another file into current buffer")) |
186 | (bindings--define-key menu [dired] | |
187 | '(menu-item "Open Directory..." dired | |
b016851c | 188 | :enable (menu-bar-non-minibuffer-window-p) |
1ec4b7b2 SM |
189 | :help "Read a directory, to operate on its files")) |
190 | (bindings--define-key menu [open-file] | |
191 | '(menu-item "Open File..." menu-find-file-existing | |
b016851c | 192 | :enable (menu-bar-non-minibuffer-window-p) |
1ec4b7b2 SM |
193 | :help "Read an existing file into an Emacs buffer")) |
194 | (bindings--define-key menu [new-file] | |
195 | '(menu-item "Visit New File..." find-file | |
b016851c | 196 | :enable (menu-bar-non-minibuffer-window-p) |
1ec4b7b2 | 197 | :help "Specify a new file's name, to edit the file")) |
b016851c SM |
198 | |
199 | menu)) | |
7f315c7c | 200 | |
7b5836c7 JD |
201 | (defun menu-find-file-existing () |
202 | "Edit the existing file FILENAME." | |
203 | (interactive) | |
204 | (let* ((mustmatch (not (and (fboundp 'x-uses-old-gtk-dialog) | |
205 | (x-uses-old-gtk-dialog)))) | |
206 | (filename (car (find-file-read-args "Find file: " mustmatch)))) | |
207 | (if mustmatch | |
208 | (find-file-existing filename) | |
209 | (find-file filename)))) | |
210 | ||
bac6e4e2 KS |
211 | ;; The "Edit->Search" submenu |
212 | (defvar menu-bar-last-search-type nil | |
213 | "Type of last non-incremental search command called from the menu.") | |
214 | ||
215 | (defun nonincremental-repeat-search-forward () | |
216 | "Search forward for the previous search string or regexp." | |
217 | (interactive) | |
218 | (cond | |
219 | ((and (eq menu-bar-last-search-type 'string) | |
220 | search-ring) | |
221 | (search-forward (car search-ring))) | |
222 | ((and (eq menu-bar-last-search-type 'regexp) | |
223 | regexp-search-ring) | |
224 | (re-search-forward (car regexp-search-ring))) | |
225 | (t | |
226 | (error "No previous search")))) | |
227 | ||
228 | (defun nonincremental-repeat-search-backward () | |
229 | "Search backward for the previous search string or regexp." | |
230 | (interactive) | |
231 | (cond | |
232 | ((and (eq menu-bar-last-search-type 'string) | |
233 | search-ring) | |
234 | (search-backward (car search-ring))) | |
235 | ((and (eq menu-bar-last-search-type 'regexp) | |
236 | regexp-search-ring) | |
237 | (re-search-backward (car regexp-search-ring))) | |
238 | (t | |
239 | (error "No previous search")))) | |
240 | ||
ffbdd83d RS |
241 | (defun nonincremental-search-forward (string) |
242 | "Read a string and search for it nonincrementally." | |
243 | (interactive "sSearch for string: ") | |
bac6e4e2 | 244 | (setq menu-bar-last-search-type 'string) |
ffbdd83d RS |
245 | (if (equal string "") |
246 | (search-forward (car search-ring)) | |
247 | (isearch-update-ring string nil) | |
248 | (search-forward string))) | |
249 | ||
250 | (defun nonincremental-search-backward (string) | |
251 | "Read a string and search backward for it nonincrementally." | |
252 | (interactive "sSearch for string: ") | |
bac6e4e2 | 253 | (setq menu-bar-last-search-type 'string) |
ffbdd83d RS |
254 | (if (equal string "") |
255 | (search-backward (car search-ring)) | |
256 | (isearch-update-ring string nil) | |
257 | (search-backward string))) | |
258 | ||
259 | (defun nonincremental-re-search-forward (string) | |
260 | "Read a regular expression and search for it nonincrementally." | |
261 | (interactive "sSearch for regexp: ") | |
bac6e4e2 | 262 | (setq menu-bar-last-search-type 'regexp) |
ffbdd83d RS |
263 | (if (equal string "") |
264 | (re-search-forward (car regexp-search-ring)) | |
265 | (isearch-update-ring string t) | |
266 | (re-search-forward string))) | |
267 | ||
268 | (defun nonincremental-re-search-backward (string) | |
269 | "Read a regular expression and search backward for it nonincrementally." | |
270 | (interactive "sSearch for regexp: ") | |
bac6e4e2 | 271 | (setq menu-bar-last-search-type 'regexp) |
ffbdd83d RS |
272 | (if (equal string "") |
273 | (re-search-backward (car regexp-search-ring)) | |
274 | (isearch-update-ring string t) | |
275 | (re-search-backward string))) | |
276 | ||
bac6e4e2 KS |
277 | ;; The Edit->Search->Incremental Search menu |
278 | (defvar menu-bar-i-search-menu | |
b016851c | 279 | (let ((menu (make-sparse-keymap "Incremental Search"))) |
1ec4b7b2 SM |
280 | (bindings--define-key menu [isearch-backward-regexp] |
281 | '(menu-item "Backward Regexp..." isearch-backward-regexp | |
282 | :help "Search backwards for a regular expression as you type it")) | |
283 | (bindings--define-key menu [isearch-forward-regexp] | |
284 | '(menu-item "Forward Regexp..." isearch-forward-regexp | |
285 | :help "Search forward for a regular expression as you type it")) | |
286 | (bindings--define-key menu [isearch-backward] | |
287 | '(menu-item "Backward String..." isearch-backward | |
288 | :help "Search backwards for a string as you type it")) | |
289 | (bindings--define-key menu [isearch-forward] | |
290 | '(menu-item "Forward String..." isearch-forward | |
291 | :help "Search forward for a string as you type it")) | |
b016851c SM |
292 | menu)) |
293 | ||
294 | (defvar menu-bar-search-menu | |
295 | (let ((menu (make-sparse-keymap "Search"))) | |
296 | ||
1ec4b7b2 SM |
297 | (bindings--define-key menu [i-search] |
298 | `(menu-item "Incremental Search" ,menu-bar-i-search-menu)) | |
299 | (bindings--define-key menu [separator-tag-isearch] | |
b016851c SM |
300 | menu-bar-separator) |
301 | ||
1ec4b7b2 SM |
302 | (bindings--define-key menu [tags-continue] |
303 | '(menu-item "Continue Tags Search" tags-loop-continue | |
304 | :help "Continue last tags search operation")) | |
305 | (bindings--define-key menu [tags-srch] | |
306 | '(menu-item "Search Tagged Files..." tags-search | |
307 | :help "Search for a regexp in all tagged files")) | |
308 | (bindings--define-key menu [separator-tag-search] menu-bar-separator) | |
b016851c | 309 | |
1ec4b7b2 SM |
310 | (bindings--define-key menu [repeat-search-back] |
311 | '(menu-item "Repeat Backwards" | |
b016851c SM |
312 | nonincremental-repeat-search-backward |
313 | :enable (or (and (eq menu-bar-last-search-type 'string) | |
314 | search-ring) | |
315 | (and (eq menu-bar-last-search-type 'regexp) | |
316 | regexp-search-ring)) | |
1ec4b7b2 SM |
317 | :help "Repeat last search backwards")) |
318 | (bindings--define-key menu [repeat-search-fwd] | |
319 | '(menu-item "Repeat Forward" | |
b016851c SM |
320 | nonincremental-repeat-search-forward |
321 | :enable (or (and (eq menu-bar-last-search-type 'string) | |
322 | search-ring) | |
323 | (and (eq menu-bar-last-search-type 'regexp) | |
324 | regexp-search-ring)) | |
1ec4b7b2 SM |
325 | :help "Repeat last search forward")) |
326 | (bindings--define-key menu [separator-repeat-search] | |
b016851c SM |
327 | menu-bar-separator) |
328 | ||
1ec4b7b2 SM |
329 | (bindings--define-key menu [re-search-backward] |
330 | '(menu-item "Regexp Backwards..." | |
b016851c | 331 | nonincremental-re-search-backward |
1ec4b7b2 SM |
332 | :help "Search backwards for a regular expression")) |
333 | (bindings--define-key menu [re-search-forward] | |
334 | '(menu-item "Regexp Forward..." | |
b016851c | 335 | nonincremental-re-search-forward |
1ec4b7b2 | 336 | :help "Search forward for a regular expression")) |
b016851c | 337 | |
1ec4b7b2 SM |
338 | (bindings--define-key menu [search-backward] |
339 | '(menu-item "String Backwards..." | |
b016851c | 340 | nonincremental-search-backward |
1ec4b7b2 SM |
341 | :help "Search backwards for a string")) |
342 | (bindings--define-key menu [search-forward] | |
343 | '(menu-item "String Forward..." nonincremental-search-forward | |
344 | :help "Search forward for a string")) | |
b016851c | 345 | menu)) |
9bb8e471 | 346 | |
bac6e4e2 KS |
347 | ;; The Edit->Replace submenu |
348 | ||
b016851c SM |
349 | (defvar menu-bar-replace-menu |
350 | (let ((menu (make-sparse-keymap "Replace"))) | |
1ec4b7b2 SM |
351 | (bindings--define-key menu [tags-repl-continue] |
352 | '(menu-item "Continue Replace" tags-loop-continue | |
353 | :help "Continue last tags replace operation")) | |
354 | (bindings--define-key menu [tags-repl] | |
355 | '(menu-item "Replace in Tagged Files..." tags-query-replace | |
356 | :help "Interactively replace a regexp in all tagged files")) | |
357 | (bindings--define-key menu [separator-replace-tags] | |
b016851c SM |
358 | menu-bar-separator) |
359 | ||
1ec4b7b2 SM |
360 | (bindings--define-key menu [query-replace-regexp] |
361 | '(menu-item "Replace Regexp..." query-replace-regexp | |
b016851c | 362 | :enable (not buffer-read-only) |
1ec4b7b2 SM |
363 | :help "Replace regular expression interactively, ask about each occurrence")) |
364 | (bindings--define-key menu [query-replace] | |
365 | '(menu-item "Replace String..." query-replace | |
b016851c | 366 | :enable (not buffer-read-only) |
1ec4b7b2 | 367 | :help "Replace string interactively, ask about each occurrence")) |
b016851c | 368 | menu)) |
bac6e4e2 | 369 | |
7f315c7c | 370 | ;;; Assemble the top-level Edit menu items. |
b016851c SM |
371 | (defvar menu-bar-goto-menu |
372 | (let ((menu (make-sparse-keymap "Go To"))) | |
373 | ||
1ec4b7b2 SM |
374 | (bindings--define-key menu [set-tags-name] |
375 | '(menu-item "Set Tags File Name..." visit-tags-table | |
376 | :help "Tell Tags commands which tag table file to use")) | |
b016851c | 377 | |
1ec4b7b2 | 378 | (bindings--define-key menu [separator-tag-file] |
b016851c SM |
379 | menu-bar-separator) |
380 | ||
1ec4b7b2 SM |
381 | (bindings--define-key menu [apropos-tags] |
382 | '(menu-item "Tags Apropos..." tags-apropos | |
383 | :help "Find function/variables whose names match regexp")) | |
384 | (bindings--define-key menu [next-tag-otherw] | |
385 | '(menu-item "Next Tag in Other Window" | |
b016851c SM |
386 | menu-bar-next-tag-other-window |
387 | :enable (and (boundp 'tags-location-ring) | |
388 | (not (ring-empty-p tags-location-ring))) | |
1ec4b7b2 | 389 | :help "Find next function/variable matching last tag name in another window")) |
b016851c | 390 | |
1ec4b7b2 SM |
391 | (bindings--define-key menu [next-tag] |
392 | '(menu-item "Find Next Tag" | |
b016851c SM |
393 | menu-bar-next-tag |
394 | :enable (and (boundp 'tags-location-ring) | |
395 | (not (ring-empty-p tags-location-ring))) | |
1ec4b7b2 SM |
396 | :help "Find next function/variable matching last tag name")) |
397 | (bindings--define-key menu [find-tag-otherw] | |
398 | '(menu-item "Find Tag in Other Window..." find-tag-other-window | |
399 | :help "Find function/variable definition in another window")) | |
400 | (bindings--define-key menu [find-tag] | |
401 | '(menu-item "Find Tag..." find-tag | |
402 | :help "Find definition of function or variable")) | |
403 | ||
404 | (bindings--define-key menu [separator-tags] | |
b016851c SM |
405 | menu-bar-separator) |
406 | ||
1ec4b7b2 SM |
407 | (bindings--define-key menu [end-of-buf] |
408 | '(menu-item "Goto End of Buffer" end-of-buffer)) | |
409 | (bindings--define-key menu [beg-of-buf] | |
410 | '(menu-item "Goto Beginning of Buffer" beginning-of-buffer)) | |
411 | (bindings--define-key menu [go-to-pos] | |
412 | '(menu-item "Goto Buffer Position..." goto-char | |
413 | :help "Read a number N and go to buffer position N")) | |
414 | (bindings--define-key menu [go-to-line] | |
415 | '(menu-item "Goto Line..." goto-line | |
416 | :help "Read a line number and go to that line")) | |
b016851c | 417 | menu)) |
7f315c7c | 418 | |
7f315c7c | 419 | |
b016851c SM |
420 | (defvar yank-menu (cons (purecopy "Select Yank") nil)) |
421 | (fset 'yank-menu (cons 'keymap yank-menu)) | |
7f315c7c | 422 | |
b016851c SM |
423 | (defvar menu-bar-edit-menu |
424 | (let ((menu (make-sparse-keymap "Edit"))) | |
b8f7ff0d | 425 | |
1ec4b7b2 SM |
426 | (bindings--define-key menu [props] |
427 | `(menu-item "Text Properties" facemenu-menu)) | |
b016851c | 428 | |
e1dbe924 | 429 | ;; ns-win.el said: Add spell for platform consistency. |
b016851c | 430 | (if (featurep 'ns) |
1ec4b7b2 SM |
431 | (bindings--define-key menu [spell] |
432 | `(menu-item "Spell" ispell-menu-map))) | |
b016851c | 433 | |
1ec4b7b2 SM |
434 | (bindings--define-key menu [fill] |
435 | `(menu-item "Fill" fill-region | |
b016851c SM |
436 | :enable (and mark-active (not buffer-read-only)) |
437 | :help | |
1ec4b7b2 | 438 | "Fill text in region to fit between left and right margin")) |
b016851c | 439 | |
1ec4b7b2 | 440 | (bindings--define-key menu [separator-bookmark] |
b016851c SM |
441 | menu-bar-separator) |
442 | ||
1ec4b7b2 SM |
443 | (bindings--define-key menu [bookmark] |
444 | `(menu-item "Bookmarks" menu-bar-bookmark-map)) | |
b016851c | 445 | |
1ec4b7b2 SM |
446 | (bindings--define-key menu [goto] |
447 | `(menu-item "Go To" ,menu-bar-goto-menu)) | |
b016851c | 448 | |
1ec4b7b2 SM |
449 | (bindings--define-key menu [replace] |
450 | `(menu-item "Replace" ,menu-bar-replace-menu)) | |
b016851c | 451 | |
1ec4b7b2 SM |
452 | (bindings--define-key menu [search] |
453 | `(menu-item "Search" ,menu-bar-search-menu)) | |
b016851c | 454 | |
1ec4b7b2 | 455 | (bindings--define-key menu [separator-search] |
b016851c SM |
456 | menu-bar-separator) |
457 | ||
1ec4b7b2 SM |
458 | (bindings--define-key menu [mark-whole-buffer] |
459 | '(menu-item "Select All" mark-whole-buffer | |
460 | :help "Mark the whole buffer for a subsequent cut/copy")) | |
461 | (bindings--define-key menu [clear] | |
462 | '(menu-item "Clear" delete-region | |
b016851c SM |
463 | :enable (and mark-active |
464 | (not buffer-read-only)) | |
465 | :help | |
1ec4b7b2 | 466 | "Delete the text in region between mark and current position")) |
b016851c SM |
467 | |
468 | ||
1ec4b7b2 | 469 | (bindings--define-key menu (if (featurep 'ns) [select-paste] |
b016851c SM |
470 | [paste-from-menu]) |
471 | ;; ns-win.el said: Change text to be more consistent with | |
472 | ;; surrounding menu items `paste', etc." | |
1ec4b7b2 SM |
473 | `(menu-item ,(if (featurep 'ns) "Select and Paste" |
474 | "Paste from Kill Menu") yank-menu | |
475 | :enable (and (cdr yank-menu) (not buffer-read-only)) | |
476 | :help "Choose a string from the kill ring and paste it")) | |
477 | (bindings--define-key menu [paste] | |
478 | '(menu-item "Paste" yank | |
b016851c SM |
479 | :enable (and (or |
480 | ;; Emacs compiled --without-x (or --with-ns) | |
481 | ;; doesn't have x-selection-exists-p. | |
482 | (and (fboundp 'x-selection-exists-p) | |
483 | (x-selection-exists-p 'CLIPBOARD)) | |
484 | (if (featurep 'ns) ; like paste-from-menu | |
485 | (cdr yank-menu) | |
486 | kill-ring)) | |
487 | (not buffer-read-only)) | |
1ec4b7b2 SM |
488 | :help "Paste (yank) text most recently cut/copied")) |
489 | (bindings--define-key menu [copy] | |
b016851c SM |
490 | ;; ns-win.el said: Substitute a Copy function that works better |
491 | ;; under X (for GNUstep). | |
1ec4b7b2 SM |
492 | `(menu-item "Copy" ,(if (featurep 'ns) |
493 | 'ns-copy-including-secondary | |
494 | 'kill-ring-save) | |
b016851c | 495 | :enable mark-active |
1ec4b7b2 SM |
496 | :help "Copy text in region between mark and current position" |
497 | :keys ,(if (featurep 'ns) | |
498 | "\\[ns-copy-including-secondary]" | |
499 | "\\[kill-ring-save]"))) | |
500 | (bindings--define-key menu [cut] | |
501 | '(menu-item "Cut" kill-region | |
b016851c SM |
502 | :enable (and mark-active (not buffer-read-only)) |
503 | :help | |
1ec4b7b2 | 504 | "Cut (kill) text in region between mark and current position")) |
b016851c SM |
505 | ;; ns-win.el said: Separate undo from cut/paste section. |
506 | (if (featurep 'ns) | |
1ec4b7b2 | 507 | (bindings--define-key menu [separator-undo] menu-bar-separator)) |
b016851c | 508 | |
1ec4b7b2 SM |
509 | (bindings--define-key menu [undo] |
510 | '(menu-item "Undo" undo | |
b016851c SM |
511 | :enable (and (not buffer-read-only) |
512 | (not (eq t buffer-undo-list)) | |
513 | (if (eq last-command 'undo) | |
514 | (listp pending-undo-list) | |
515 | (consp buffer-undo-list))) | |
1ec4b7b2 | 516 | :help "Undo last operation")) |
b016851c SM |
517 | |
518 | menu)) | |
277e0f9d RS |
519 | |
520 | (defun menu-bar-next-tag-other-window () | |
521 | "Find the next definition of the tag already specified." | |
522 | (interactive) | |
523 | (find-tag-other-window nil t)) | |
524 | ||
525 | (defun menu-bar-next-tag () | |
526 | "Find the next definition of the tag already specified." | |
527 | (interactive) | |
528 | (find-tag nil t)) | |
529 | ||
3f95d7ff CY |
530 | (define-obsolete-function-alias |
531 | 'menu-bar-kill-ring-save 'kill-ring-save "24.1") | |
4c0317b1 | 532 | |
f9cf0be2 | 533 | ;; These are alternative definitions for the cut, paste and copy |
4c0317b1 | 534 | ;; menu items. Use them if your system expects these to use the clipboard. |
f9cf0be2 | 535 | |
c3283990 MR |
536 | (put 'clipboard-kill-region 'menu-enable |
537 | '(and mark-active (not buffer-read-only))) | |
f9cf0be2 RS |
538 | (put 'clipboard-kill-ring-save 'menu-enable 'mark-active) |
539 | (put 'clipboard-yank 'menu-enable | |
a728dc59 DR |
540 | '(and (or (not (fboundp 'x-selection-exists-p)) |
541 | (x-selection-exists-p) | |
c3283990 | 542 | (x-selection-exists-p 'CLIPBOARD)) |
a728dc59 | 543 | (not buffer-read-only))) |
f9cf0be2 RS |
544 | |
545 | (defun clipboard-yank () | |
ee497664 | 546 | "Insert the clipboard contents, or the last stretch of killed text." |
1d45e02e | 547 | (interactive "*") |
f9cf0be2 RS |
548 | (let ((x-select-enable-clipboard t)) |
549 | (yank))) | |
550 | ||
6f8dfccf | 551 | (defun clipboard-kill-ring-save (beg end &optional region) |
f9cf0be2 | 552 | "Copy region to kill ring, and save in the X clipboard." |
6f8dfccf | 553 | (interactive "r\np") |
f9cf0be2 | 554 | (let ((x-select-enable-clipboard t)) |
6f8dfccf | 555 | (kill-ring-save beg end region))) |
f9cf0be2 | 556 | |
6f8dfccf | 557 | (defun clipboard-kill-region (beg end &optional region) |
f9cf0be2 | 558 | "Kill the region, and save it in the X clipboard." |
6f8dfccf | 559 | (interactive "r\np") |
f9cf0be2 | 560 | (let ((x-select-enable-clipboard t)) |
6f8dfccf | 561 | (kill-region beg end region))) |
f9cf0be2 RS |
562 | |
563 | (defun menu-bar-enable-clipboard () | |
5cbdeb30 RS |
564 | "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard. |
565 | Do the same for the keys of the same name." | |
f9cf0be2 | 566 | (interactive) |
e3fa3057 DL |
567 | ;; These are Sun server keysyms for the Cut, Copy and Paste keys |
568 | ;; (also for XFree86 on Sun keyboard): | |
5cbdeb30 RS |
569 | (define-key global-map [f20] 'clipboard-kill-region) |
570 | (define-key global-map [f16] 'clipboard-kill-ring-save) | |
571 | (define-key global-map [f18] 'clipboard-yank) | |
e3fa3057 | 572 | ;; X11R6 versions: |
5cbdeb30 RS |
573 | (define-key global-map [cut] 'clipboard-kill-region) |
574 | (define-key global-map [copy] 'clipboard-kill-ring-save) | |
575 | (define-key global-map [paste] 'clipboard-yank)) | |
f9cf0be2 | 576 | \f |
7f315c7c | 577 | ;; The "Options" menu items |
a9f53ffb | 578 | |
b016851c SM |
579 | (defvar menu-bar-custom-menu |
580 | (let ((menu (make-sparse-keymap "Customize"))) | |
581 | ||
1ec4b7b2 SM |
582 | (bindings--define-key menu [customize-apropos-faces] |
583 | '(menu-item "Faces Matching..." customize-apropos-faces | |
584 | :help "Browse faces matching a regexp or word list")) | |
585 | (bindings--define-key menu [customize-apropos-options] | |
586 | '(menu-item "Options Matching..." customize-apropos-options | |
587 | :help "Browse options matching a regexp or word list")) | |
588 | (bindings--define-key menu [customize-apropos] | |
589 | '(menu-item "All Settings Matching..." customize-apropos | |
590 | :help "Browse customizable settings matching a regexp or word list")) | |
591 | (bindings--define-key menu [separator-1] | |
b016851c | 592 | menu-bar-separator) |
1ec4b7b2 SM |
593 | (bindings--define-key menu [customize-group] |
594 | '(menu-item "Specific Group..." customize-group | |
595 | :help "Customize settings of specific group")) | |
596 | (bindings--define-key menu [customize-face] | |
597 | '(menu-item "Specific Face..." customize-face | |
598 | :help "Customize attributes of specific face")) | |
599 | (bindings--define-key menu [customize-option] | |
600 | '(menu-item "Specific Option..." customize-option | |
601 | :help "Customize value of specific option")) | |
602 | (bindings--define-key menu [separator-2] | |
b016851c | 603 | menu-bar-separator) |
1ec4b7b2 SM |
604 | (bindings--define-key menu [customize-changed-options] |
605 | '(menu-item "New Options..." customize-changed-options | |
606 | :help "Options added or changed in recent Emacs versions")) | |
607 | (bindings--define-key menu [customize-saved] | |
608 | '(menu-item "Saved Options" customize-saved | |
609 | :help "Customize previously saved options")) | |
610 | (bindings--define-key menu [separator-3] | |
b016851c | 611 | menu-bar-separator) |
1ec4b7b2 SM |
612 | (bindings--define-key menu [customize-browse] |
613 | '(menu-item "Browse Customization Groups" customize-browse | |
614 | :help "Browse all customization groups")) | |
615 | (bindings--define-key menu [customize] | |
616 | '(menu-item "Top-level Customization Group" customize | |
617 | :help "The master group called `Emacs'")) | |
618 | (bindings--define-key menu [customize-themes] | |
619 | '(menu-item "Custom Themes" customize-themes | |
620 | :help "Choose a pre-defined customization theme")) | |
b016851c | 621 | menu)) |
7f315c7c | 622 | ;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences")) |
bacb2d12 | 623 | |
09bfa5ca SM |
624 | (defmacro menu-bar-make-mm-toggle (fname doc help &optional props) |
625 | "Make a menu-item for a global minor mode toggle. | |
626 | FNAME is the minor mode's name (variable and function). | |
7faa9d02 | 627 | DOC is the text to use for the menu entry. |
09bfa5ca SM |
628 | HELP is the text to use for the tooltip. |
629 | PROPS are additional properties." | |
651eaf36 AS |
630 | `'(menu-item ,doc ,fname |
631 | ,@props | |
632 | :help ,help | |
633 | :button (:toggle . (and (default-boundp ',fname) | |
634 | (default-value ',fname))))) | |
09bfa5ca | 635 | |
a9d96061 | 636 | (defmacro menu-bar-make-toggle (name variable doc message help &rest body) |
bacb2d12 | 637 | `(progn |
da67fa9a | 638 | (defun ,name (&optional interactively) |
e8dd28e7 | 639 | ,(concat "Toggle whether to " (downcase (substring help 0 1)) |
d02c57d3 | 640 | (substring help 1) ". |
da67fa9a RS |
641 | In an interactive call, record this option as a candidate for saving |
642 | by \"Save Options\" in Custom buffers.") | |
643 | (interactive "p") | |
bacb2d12 | 644 | (if ,(if body `(progn . ,body) |
bc6f3791 | 645 | `(progn |
4f9b9060 PA |
646 | (custom-load-symbol ',variable) |
647 | (let ((set (or (get ',variable 'custom-set) 'set-default)) | |
648 | (get (or (get ',variable 'custom-get) 'default-value))) | |
649 | (funcall set ',variable (not (funcall get ',variable)))))) | |
b36e96c8 RS |
650 | (message ,message "enabled globally") |
651 | (message ,message "disabled globally")) | |
a9d96061 SM |
652 | ;; The function `customize-mark-as-set' must only be called when |
653 | ;; a variable is set interactively, as the purpose is to mark it as | |
654 | ;; a candidate for "Save Options", and we do not want to save options | |
655 | ;; the user have already set explicitly in his init file. | |
da67fa9a | 656 | (if interactively (customize-mark-as-set ',variable))) |
651eaf36 AS |
657 | '(menu-item ,doc ,name |
658 | :help ,help | |
659 | :button (:toggle . (and (default-boundp ',variable) | |
660 | (default-value ',variable)))))) | |
7f315c7c | 661 | |
ba858bf9 CY |
662 | ;; Function for setting/saving default font. |
663 | ||
664 | (defun menu-set-font () | |
13a83f05 | 665 | "Interactively select a font and make it the default on all existing frames." |
ba858bf9 | 666 | (interactive) |
fce3fdeb CY |
667 | (set-frame-font (if (fboundp 'x-select-font) |
668 | (x-select-font) | |
669 | (mouse-select-font)) | |
670 | nil t)) | |
ba858bf9 | 671 | |
10013d74 DL |
672 | (defun menu-bar-options-save () |
673 | "Save current values of Options menu items using Custom." | |
674 | (interactive) | |
414fd702 | 675 | (let ((need-save nil)) |
5373d675 RS |
676 | ;; These are set with menu-bar-make-mm-toggle, which does not |
677 | ;; put on a customized-value property. | |
e1573595 LK |
678 | (dolist (elt '(line-number-mode column-number-mode size-indication-mode |
679 | cua-mode show-paren-mode transient-mark-mode | |
639b9d87 GM |
680 | blink-cursor-mode display-time-mode display-battery-mode |
681 | ;; These are set by other functions that don't set | |
682 | ;; the customized state. Having them here has the | |
683 | ;; side-effect that turning them off via X | |
684 | ;; resources acts like having customized them, but | |
685 | ;; that seems harmless. | |
686 | menu-bar-mode tool-bar-mode)) | |
687 | ;; FIXME ? It's a little annoying that running this command | |
688 | ;; always loads cua-base, paren, time, and battery, even if they | |
689 | ;; have not been customized in any way. (Due to custom-load-symbol.) | |
5373d675 RS |
690 | (and (customize-mark-to-save elt) |
691 | (setq need-save t))) | |
4f9b9060 | 692 | ;; These are set with `customize-set-variable'. |
5373d675 | 693 | (dolist (elt '(scroll-bar-mode |
73ae229c | 694 | debug-on-quit debug-on-error |
639b9d87 GM |
695 | ;; Somehow this works, when tool-bar and menu-bar don't. |
696 | tooltip-mode | |
8cfa1cd5 | 697 | save-place uniquify-buffer-name-style fringe-mode |
622a8785 | 698 | indicate-empty-lines indicate-buffer-boundaries |
ad413b35 | 699 | case-fold-search font-use-system-font |
f4990970 | 700 | current-language-environment default-input-method |
4f9b9060 PA |
701 | ;; Saving `text-mode-hook' is somewhat questionable, |
702 | ;; as we might get more than we bargain for, if | |
703 | ;; other code may has added hooks as well. | |
704 | ;; Nonetheless, not saving it would like be confuse | |
705 | ;; more often. | |
706 | ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11. | |
36a1b6db | 707 | text-mode-hook tool-bar-position)) |
4f9b9060 PA |
708 | (and (get elt 'customized-value) |
709 | (customize-mark-to-save elt) | |
710 | (setq need-save t))) | |
e34b0c60 CY |
711 | (when (get 'default 'customized-face) |
712 | (put 'default 'saved-face (get 'default 'customized-face)) | |
713 | (put 'default 'customized-face nil) | |
714 | (setq need-save t)) | |
414fd702 PA |
715 | ;; Save if we changed anything. |
716 | (when need-save | |
717 | (custom-save-all)))) | |
10013d74 | 718 | |
637fa988 | 719 | |
b016851c | 720 | ;;; Assemble all the top-level items of the "Options" menu |
637fa988 | 721 | |
c2ca4bab PJ |
722 | ;; The "Show/Hide" submenu of menu "Options" |
723 | ||
622a8785 LT |
724 | (defun menu-bar-showhide-fringe-ind-customize () |
725 | "Show customization buffer for `indicate-buffer-boundaries'." | |
f7481749 | 726 | (interactive) |
622a8785 | 727 | (customize-variable 'indicate-buffer-boundaries)) |
f7481749 | 728 | |
f7481749 | 729 | (defun menu-bar-showhide-fringe-ind-mixed () |
622a8785 | 730 | "Display top and bottom indicators in opposite fringes, arrows in right." |
f7481749 | 731 | (interactive) |
622a8785 LT |
732 | (customize-set-variable 'indicate-buffer-boundaries |
733 | '((t . right) (top . left)))) | |
f7481749 | 734 | |
f7481749 KS |
735 | (defun menu-bar-showhide-fringe-ind-box () |
736 | "Display top and bottom indicators in opposite fringes." | |
737 | (interactive) | |
622a8785 LT |
738 | (customize-set-variable 'indicate-buffer-boundaries |
739 | '((top . left) (bottom . right)))) | |
f7481749 | 740 | |
f7481749 | 741 | (defun menu-bar-showhide-fringe-ind-right () |
622a8785 | 742 | "Display buffer boundaries and arrows in the right fringe." |
f7481749 | 743 | (interactive) |
622a8785 | 744 | (customize-set-variable 'indicate-buffer-boundaries 'right)) |
f7481749 | 745 | |
f7481749 | 746 | (defun menu-bar-showhide-fringe-ind-left () |
622a8785 | 747 | "Display buffer boundaries and arrows in the left fringe." |
f7481749 | 748 | (interactive) |
622a8785 | 749 | (customize-set-variable 'indicate-buffer-boundaries 'left)) |
f7481749 | 750 | |
f7481749 | 751 | (defun menu-bar-showhide-fringe-ind-none () |
622a8785 | 752 | "Do not display any buffer boundary indicators." |
f7481749 | 753 | (interactive) |
622a8785 | 754 | (customize-set-variable 'indicate-buffer-boundaries nil)) |
f7481749 | 755 | |
b016851c SM |
756 | (defvar menu-bar-showhide-fringe-ind-menu |
757 | (let ((menu (make-sparse-keymap "Buffer boundaries"))) | |
758 | ||
1ec4b7b2 SM |
759 | (bindings--define-key menu [customize] |
760 | '(menu-item "Other (Customize)" | |
b016851c | 761 | menu-bar-showhide-fringe-ind-customize |
1ec4b7b2 | 762 | :help "Additional choices available through Custom buffer" |
b016851c SM |
763 | :visible (display-graphic-p) |
764 | :button (:radio . (not (member indicate-buffer-boundaries | |
765 | '(nil left right | |
766 | ((top . left) (bottom . right)) | |
767 | ((t . right) (top . left)))))))) | |
768 | ||
1ec4b7b2 SM |
769 | (bindings--define-key menu [mixed] |
770 | '(menu-item "Opposite, Arrows Right" menu-bar-showhide-fringe-ind-mixed | |
b016851c | 771 | :help |
1ec4b7b2 | 772 | "Show top/bottom indicators in opposite fringes, arrows in right" |
b016851c SM |
773 | :visible (display-graphic-p) |
774 | :button (:radio . (equal indicate-buffer-boundaries | |
775 | '((t . right) (top . left)))))) | |
776 | ||
1ec4b7b2 SM |
777 | (bindings--define-key menu [box] |
778 | '(menu-item "Opposite, No Arrows" menu-bar-showhide-fringe-ind-box | |
779 | :help "Show top/bottom indicators in opposite fringes, no arrows" | |
b016851c SM |
780 | :visible (display-graphic-p) |
781 | :button (:radio . (equal indicate-buffer-boundaries | |
782 | '((top . left) (bottom . right)))))) | |
783 | ||
1ec4b7b2 SM |
784 | (bindings--define-key menu [right] |
785 | '(menu-item "In Right Fringe" menu-bar-showhide-fringe-ind-right | |
786 | :help "Show buffer boundaries and arrows in right fringe" | |
b016851c SM |
787 | :visible (display-graphic-p) |
788 | :button (:radio . (eq indicate-buffer-boundaries 'right)))) | |
789 | ||
1ec4b7b2 SM |
790 | (bindings--define-key menu [left] |
791 | '(menu-item "In Left Fringe" menu-bar-showhide-fringe-ind-left | |
792 | :help "Show buffer boundaries and arrows in left fringe" | |
b016851c SM |
793 | :visible (display-graphic-p) |
794 | :button (:radio . (eq indicate-buffer-boundaries 'left)))) | |
795 | ||
1ec4b7b2 SM |
796 | (bindings--define-key menu [none] |
797 | '(menu-item "No Indicators" menu-bar-showhide-fringe-ind-none | |
798 | :help "Hide all buffer boundary indicators and arrows" | |
b016851c SM |
799 | :visible (display-graphic-p) |
800 | :button (:radio . (eq indicate-buffer-boundaries nil)))) | |
801 | menu)) | |
8cfa1cd5 SJ |
802 | |
803 | (defun menu-bar-showhide-fringe-menu-customize () | |
804 | "Show customization buffer for `fringe-mode'." | |
805 | (interactive) | |
806 | (customize-variable 'fringe-mode)) | |
807 | ||
8cfa1cd5 | 808 | (defun menu-bar-showhide-fringe-menu-customize-reset () |
277e0f9d | 809 | "Reset the fringe mode: display fringes on both sides of a window." |
8cfa1cd5 SJ |
810 | (interactive) |
811 | (customize-set-variable 'fringe-mode nil)) | |
812 | ||
8cfa1cd5 | 813 | (defun menu-bar-showhide-fringe-menu-customize-right () |
277e0f9d | 814 | "Display fringes only on the right of each window." |
8cfa1cd5 | 815 | (interactive) |
00cb70dc MB |
816 | (require 'fringe) |
817 | (customize-set-variable 'fringe-mode '(0 . nil))) | |
8cfa1cd5 | 818 | |
4c0252a5 JD |
819 | (defun menu-bar-showhide-fringe-menu-customize-left () |
820 | "Display fringes only on the left of each window." | |
821 | (interactive) | |
822 | (require 'fringe) | |
823 | (customize-set-variable 'fringe-mode '(nil . 0))) | |
824 | ||
8cfa1cd5 | 825 | (defun menu-bar-showhide-fringe-menu-customize-disable () |
277e0f9d | 826 | "Do not display window fringes." |
8cfa1cd5 | 827 | (interactive) |
00cb70dc MB |
828 | (require 'fringe) |
829 | (customize-set-variable 'fringe-mode 0)) | |
8cfa1cd5 | 830 | |
b016851c SM |
831 | (defvar menu-bar-showhide-fringe-menu |
832 | (let ((menu (make-sparse-keymap "Fringe"))) | |
833 | ||
1ec4b7b2 SM |
834 | (bindings--define-key menu [showhide-fringe-ind] |
835 | `(menu-item "Buffer Boundaries" ,menu-bar-showhide-fringe-ind-menu | |
b016851c | 836 | :visible (display-graphic-p) |
1ec4b7b2 | 837 | :help "Indicate buffer boundaries in fringe")) |
b016851c | 838 | |
1ec4b7b2 | 839 | (bindings--define-key menu [indicate-empty-lines] |
b016851c SM |
840 | (menu-bar-make-toggle toggle-indicate-empty-lines indicate-empty-lines |
841 | "Empty Line Indicators" | |
842 | "Indicating of empty lines %s" | |
843 | "Indicate trailing empty lines in fringe, globally")) | |
844 | ||
1ec4b7b2 SM |
845 | (bindings--define-key menu [customize] |
846 | '(menu-item "Customize Fringe" menu-bar-showhide-fringe-menu-customize | |
847 | :help "Detailed customization of fringe" | |
b016851c SM |
848 | :visible (display-graphic-p))) |
849 | ||
1ec4b7b2 SM |
850 | (bindings--define-key menu [default] |
851 | '(menu-item "Default" menu-bar-showhide-fringe-menu-customize-reset | |
852 | :help "Default width fringe on both left and right side" | |
b016851c SM |
853 | :visible (display-graphic-p) |
854 | :button (:radio . (eq fringe-mode nil)))) | |
855 | ||
1ec4b7b2 SM |
856 | (bindings--define-key menu [right] |
857 | '(menu-item "On the Right" menu-bar-showhide-fringe-menu-customize-right | |
858 | :help "Fringe only on the right side" | |
b016851c SM |
859 | :visible (display-graphic-p) |
860 | :button (:radio . (equal fringe-mode '(0 . nil))))) | |
861 | ||
1ec4b7b2 SM |
862 | (bindings--define-key menu [left] |
863 | '(menu-item "On the Left" menu-bar-showhide-fringe-menu-customize-left | |
864 | :help "Fringe only on the left side" | |
b016851c SM |
865 | :visible (display-graphic-p) |
866 | :button (:radio . (equal fringe-mode '(nil . 0))))) | |
867 | ||
1ec4b7b2 SM |
868 | (bindings--define-key menu [none] |
869 | '(menu-item "None" menu-bar-showhide-fringe-menu-customize-disable | |
870 | :help "Turn off fringe" | |
b016851c SM |
871 | :visible (display-graphic-p) |
872 | :button (:radio . (eq fringe-mode 0)))) | |
873 | menu)) | |
874 | ||
277e0f9d RS |
875 | (defun menu-bar-right-scroll-bar () |
876 | "Display scroll bars on the right of each window." | |
877 | (interactive) | |
878 | (customize-set-variable 'scroll-bar-mode 'right)) | |
c2ca4bab | 879 | |
277e0f9d RS |
880 | (defun menu-bar-left-scroll-bar () |
881 | "Display scroll bars on the left of each window." | |
882 | (interactive) | |
0e5ddee1 | 883 | (customize-set-variable 'scroll-bar-mode 'left)) |
277e0f9d | 884 | |
277e0f9d RS |
885 | (defun menu-bar-no-scroll-bar () |
886 | "Turn off scroll bars." | |
887 | (interactive) | |
888 | (customize-set-variable 'scroll-bar-mode nil)) | |
889 | ||
b016851c SM |
890 | (defvar menu-bar-showhide-scroll-bar-menu |
891 | (let ((menu (make-sparse-keymap "Scroll-bar"))) | |
892 | ||
1ec4b7b2 SM |
893 | (bindings--define-key menu [right] |
894 | '(menu-item "On the Right" | |
b016851c | 895 | menu-bar-right-scroll-bar |
1ec4b7b2 | 896 | :help "Scroll-bar on the right side" |
b016851c SM |
897 | :visible (display-graphic-p) |
898 | :button (:radio . (eq (cdr (assq 'vertical-scroll-bars | |
899 | (frame-parameters))) 'right)))) | |
900 | ||
1ec4b7b2 SM |
901 | (bindings--define-key menu [left] |
902 | '(menu-item "On the Left" | |
b016851c | 903 | menu-bar-left-scroll-bar |
1ec4b7b2 | 904 | :help "Scroll-bar on the left side" |
b016851c SM |
905 | :visible (display-graphic-p) |
906 | :button (:radio . (eq (cdr (assq 'vertical-scroll-bars | |
907 | (frame-parameters))) 'left)))) | |
908 | ||
1ec4b7b2 SM |
909 | (bindings--define-key menu [none] |
910 | '(menu-item "None" | |
b016851c | 911 | menu-bar-no-scroll-bar |
1ec4b7b2 | 912 | :help "Turn off scroll-bar" |
b016851c SM |
913 | :visible (display-graphic-p) |
914 | :button (:radio . (eq (cdr (assq 'vertical-scroll-bars | |
915 | (frame-parameters))) nil)))) | |
916 | menu)) | |
73ae229c | 917 | |
f68ab99b EZ |
918 | (defun menu-bar-frame-for-menubar () |
919 | "Return the frame suitable for updating the menu bar." | |
920 | (or (and (framep menu-updating-frame) | |
921 | menu-updating-frame) | |
922 | (selected-frame))) | |
923 | ||
924 | (defun menu-bar-positive-p (val) | |
d136f184 | 925 | "Return non-nil if VAL is a positive number." |
f68ab99b EZ |
926 | (and (numberp val) |
927 | (> val 0))) | |
928 | ||
2b4e6277 J |
929 | (defun menu-bar-set-tool-bar-position (position) |
930 | (customize-set-variable 'tool-bar-mode t) | |
36a1b6db | 931 | (customize-set-variable 'tool-bar-position position)) |
bfeabdc3 JD |
932 | (defun menu-bar-showhide-tool-bar-menu-customize-disable () |
933 | "Do not display tool bars." | |
934 | (interactive) | |
935 | (customize-set-variable 'tool-bar-mode nil)) | |
936 | (defun menu-bar-showhide-tool-bar-menu-customize-enable-left () | |
937 | "Display tool bars on the left side." | |
938 | (interactive) | |
2b4e6277 | 939 | (menu-bar-set-tool-bar-position 'left)) |
bfeabdc3 JD |
940 | (defun menu-bar-showhide-tool-bar-menu-customize-enable-right () |
941 | "Display tool bars on the right side." | |
942 | (interactive) | |
2b4e6277 | 943 | (menu-bar-set-tool-bar-position 'right)) |
bfeabdc3 JD |
944 | (defun menu-bar-showhide-tool-bar-menu-customize-enable-top () |
945 | "Display tool bars on the top side." | |
946 | (interactive) | |
2b4e6277 | 947 | (menu-bar-set-tool-bar-position 'top)) |
bfeabdc3 JD |
948 | (defun menu-bar-showhide-tool-bar-menu-customize-enable-bottom () |
949 | "Display tool bars on the bottom side." | |
950 | (interactive) | |
2b4e6277 | 951 | (menu-bar-set-tool-bar-position 'bottom)) |
bfeabdc3 | 952 | |
b016851c SM |
953 | (when (featurep 'move-toolbar) |
954 | (defvar menu-bar-showhide-tool-bar-menu | |
955 | (let ((menu (make-sparse-keymap "Tool-bar"))) | |
956 | ||
1ec4b7b2 SM |
957 | (bindings--define-key menu [showhide-tool-bar-left] |
958 | '(menu-item "On the Left" | |
b016851c | 959 | menu-bar-showhide-tool-bar-menu-customize-enable-left |
1ec4b7b2 | 960 | :help "Tool-bar at the left side" |
b016851c SM |
961 | :visible (display-graphic-p) |
962 | :button | |
963 | (:radio . (and tool-bar-mode | |
964 | (eq (frame-parameter | |
965 | (menu-bar-frame-for-menubar) | |
966 | 'tool-bar-position) | |
967 | 'left))))) | |
968 | ||
1ec4b7b2 SM |
969 | (bindings--define-key menu [showhide-tool-bar-right] |
970 | '(menu-item "On the Right" | |
b016851c | 971 | menu-bar-showhide-tool-bar-menu-customize-enable-right |
1ec4b7b2 | 972 | :help "Tool-bar at the right side" |
b016851c SM |
973 | :visible (display-graphic-p) |
974 | :button | |
975 | (:radio . (and tool-bar-mode | |
976 | (eq (frame-parameter | |
977 | (menu-bar-frame-for-menubar) | |
978 | 'tool-bar-position) | |
979 | 'right))))) | |
980 | ||
1ec4b7b2 SM |
981 | (bindings--define-key menu [showhide-tool-bar-bottom] |
982 | '(menu-item "On the Bottom" | |
b016851c | 983 | menu-bar-showhide-tool-bar-menu-customize-enable-bottom |
1ec4b7b2 | 984 | :help "Tool-bar at the bottom" |
b016851c SM |
985 | :visible (display-graphic-p) |
986 | :button | |
987 | (:radio . (and tool-bar-mode | |
988 | (eq (frame-parameter | |
989 | (menu-bar-frame-for-menubar) | |
990 | 'tool-bar-position) | |
991 | 'bottom))))) | |
992 | ||
1ec4b7b2 SM |
993 | (bindings--define-key menu [showhide-tool-bar-top] |
994 | '(menu-item "On the Top" | |
b016851c | 995 | menu-bar-showhide-tool-bar-menu-customize-enable-top |
1ec4b7b2 | 996 | :help "Tool-bar at the top" |
b016851c SM |
997 | :visible (display-graphic-p) |
998 | :button | |
999 | (:radio . (and tool-bar-mode | |
1000 | (eq (frame-parameter | |
1001 | (menu-bar-frame-for-menubar) | |
1002 | 'tool-bar-position) | |
1003 | 'top))))) | |
1004 | ||
1ec4b7b2 SM |
1005 | (bindings--define-key menu [showhide-tool-bar-none] |
1006 | '(menu-item "None" | |
b016851c | 1007 | menu-bar-showhide-tool-bar-menu-customize-disable |
1ec4b7b2 | 1008 | :help "Turn tool-bar off" |
b016851c SM |
1009 | :visible (display-graphic-p) |
1010 | :button (:radio . (eq tool-bar-mode nil)))) | |
1011 | menu))) | |
1012 | ||
1013 | (defvar menu-bar-showhide-menu | |
1014 | (let ((menu (make-sparse-keymap "Show/Hide"))) | |
1015 | ||
1ec4b7b2 | 1016 | (bindings--define-key menu [column-number-mode] |
b016851c SM |
1017 | (menu-bar-make-mm-toggle column-number-mode |
1018 | "Column Numbers" | |
1019 | "Show the current column number in the mode line")) | |
1020 | ||
1ec4b7b2 | 1021 | (bindings--define-key menu [line-number-mode] |
b016851c SM |
1022 | (menu-bar-make-mm-toggle line-number-mode |
1023 | "Line Numbers" | |
1024 | "Show the current line number in the mode line")) | |
1025 | ||
1ec4b7b2 | 1026 | (bindings--define-key menu [size-indication-mode] |
b016851c SM |
1027 | (menu-bar-make-mm-toggle size-indication-mode |
1028 | "Size Indication" | |
1029 | "Show the size of the buffer in the mode line")) | |
1030 | ||
1ec4b7b2 | 1031 | (bindings--define-key menu [linecolumn-separator] |
b016851c SM |
1032 | menu-bar-separator) |
1033 | ||
1ec4b7b2 | 1034 | (bindings--define-key menu [showhide-battery] |
b016851c SM |
1035 | (menu-bar-make-mm-toggle display-battery-mode |
1036 | "Battery Status" | |
1037 | "Display battery status information in mode line")) | |
1038 | ||
1ec4b7b2 | 1039 | (bindings--define-key menu [showhide-date-time] |
b016851c SM |
1040 | (menu-bar-make-mm-toggle display-time-mode |
1041 | "Time, Load and Mail" | |
1042 | "Display time, system load averages and \ | |
1043 | mail status in mode line")) | |
1044 | ||
1ec4b7b2 | 1045 | (bindings--define-key menu [datetime-separator] |
b016851c SM |
1046 | menu-bar-separator) |
1047 | ||
1ec4b7b2 SM |
1048 | (bindings--define-key menu [showhide-speedbar] |
1049 | '(menu-item "Speedbar" speedbar-frame-mode | |
1050 | :help "Display a Speedbar quick-navigation frame" | |
b016851c SM |
1051 | :button (:toggle |
1052 | . (and (boundp 'speedbar-frame) | |
1053 | (frame-live-p (symbol-value 'speedbar-frame)) | |
1054 | (frame-visible-p | |
1055 | (symbol-value 'speedbar-frame)))))) | |
1056 | ||
1ec4b7b2 SM |
1057 | (bindings--define-key menu [showhide-fringe] |
1058 | `(menu-item "Fringe" ,menu-bar-showhide-fringe-menu | |
b016851c SM |
1059 | :visible (display-graphic-p))) |
1060 | ||
1ec4b7b2 SM |
1061 | (bindings--define-key menu [showhide-scroll-bar] |
1062 | `(menu-item "Scroll-bar" ,menu-bar-showhide-scroll-bar-menu | |
b016851c SM |
1063 | :visible (display-graphic-p))) |
1064 | ||
1ec4b7b2 SM |
1065 | (bindings--define-key menu [showhide-tooltip-mode] |
1066 | '(menu-item "Tooltips" tooltip-mode | |
1067 | :help "Turn tooltips on/off" | |
b016851c SM |
1068 | :visible (and (display-graphic-p) (fboundp 'x-show-tip)) |
1069 | :button (:toggle . tooltip-mode))) | |
1070 | ||
1ec4b7b2 SM |
1071 | (bindings--define-key menu [menu-bar-mode] |
1072 | '(menu-item "Menu-bar" toggle-menu-bar-mode-from-frame | |
1073 | :help "Turn menu-bar on/off" | |
b016851c SM |
1074 | :button |
1075 | (:toggle . (menu-bar-positive-p | |
1076 | (frame-parameter (menu-bar-frame-for-menubar) | |
1077 | 'menu-bar-lines))))) | |
1078 | ||
1079 | (if (and (boundp 'menu-bar-showhide-tool-bar-menu) | |
1080 | (keymapp menu-bar-showhide-tool-bar-menu)) | |
1ec4b7b2 SM |
1081 | (bindings--define-key menu [showhide-tool-bar] |
1082 | `(menu-item "Tool-bar" ,menu-bar-showhide-tool-bar-menu | |
b016851c SM |
1083 | :visible (display-graphic-p))) |
1084 | ;; else not tool bar that can move. | |
1ec4b7b2 SM |
1085 | (bindings--define-key menu [showhide-tool-bar] |
1086 | '(menu-item "Tool-bar" toggle-tool-bar-mode-from-frame | |
1087 | :help "Turn tool-bar on/off" | |
b016851c SM |
1088 | :visible (display-graphic-p) |
1089 | :button | |
1090 | (:toggle . (menu-bar-positive-p | |
1091 | (frame-parameter (menu-bar-frame-for-menubar) | |
1092 | 'tool-bar-lines)))))) | |
1093 | menu)) | |
277e0f9d | 1094 | |
b016851c SM |
1095 | (defvar menu-bar-line-wrapping-menu |
1096 | (let ((menu (make-sparse-keymap "Line Wrapping"))) | |
1097 | ||
1ec4b7b2 SM |
1098 | (bindings--define-key menu [word-wrap] |
1099 | `(menu-item "Word Wrap (Visual Line mode)" | |
1100 | ,(lambda () | |
1101 | (interactive) | |
1102 | (unless visual-line-mode | |
1103 | (visual-line-mode 1)) | |
1104 | (message "Visual-Line mode enabled")) | |
1105 | :help "Wrap long lines at word boundaries" | |
1106 | :button (:radio | |
1107 | . (and (null truncate-lines) | |
1108 | (not (truncated-partial-width-window-p)) | |
1109 | word-wrap)) | |
1110 | :visible (menu-bar-menu-frame-live-and-visible-p))) | |
1111 | ||
1112 | (bindings--define-key menu [truncate] | |
1113 | `(menu-item "Truncate Long Lines" | |
1114 | ,(lambda () | |
1115 | (interactive) | |
1116 | (if visual-line-mode (visual-line-mode 0)) | |
1117 | (setq word-wrap nil) | |
1118 | (toggle-truncate-lines 1)) | |
1119 | :help "Truncate long lines at window edge" | |
b016851c SM |
1120 | :button (:radio . (or truncate-lines |
1121 | (truncated-partial-width-window-p))) | |
1122 | :visible (menu-bar-menu-frame-live-and-visible-p) | |
1123 | :enable (not (truncated-partial-width-window-p)))) | |
1124 | ||
1ec4b7b2 SM |
1125 | (bindings--define-key menu [window-wrap] |
1126 | `(menu-item "Wrap at Window Edge" | |
1127 | ,(lambda () (interactive) | |
1128 | (if visual-line-mode (visual-line-mode 0)) | |
1129 | (setq word-wrap nil) | |
1130 | (if truncate-lines (toggle-truncate-lines -1))) | |
1131 | :help "Wrap long lines at window edge" | |
1132 | :button (:radio | |
1133 | . (and (null truncate-lines) | |
1134 | (not (truncated-partial-width-window-p)) | |
1135 | (not word-wrap))) | |
b016851c SM |
1136 | :visible (menu-bar-menu-frame-live-and-visible-p) |
1137 | :enable (not (truncated-partial-width-window-p)))) | |
1138 | menu)) | |
1139 | ||
1140 | (defvar menu-bar-options-menu | |
1141 | (let ((menu (make-sparse-keymap "Options"))) | |
1ec4b7b2 SM |
1142 | (bindings--define-key menu [customize] |
1143 | `(menu-item "Customize Emacs" ,menu-bar-custom-menu)) | |
b016851c | 1144 | |
1ec4b7b2 | 1145 | (bindings--define-key menu [package] |
b016851c SM |
1146 | '(menu-item "Manage Emacs Packages" package-list-packages |
1147 | :help "Install or uninstall additional Emacs packages")) | |
1148 | ||
1ec4b7b2 SM |
1149 | (bindings--define-key menu [save] |
1150 | '(menu-item "Save Options" menu-bar-options-save | |
1151 | :help "Save options set from the menu above")) | |
b016851c | 1152 | |
1ec4b7b2 | 1153 | (bindings--define-key menu [custom-separator] |
b016851c SM |
1154 | menu-bar-separator) |
1155 | ||
1ec4b7b2 SM |
1156 | (bindings--define-key menu [menu-set-font] |
1157 | '(menu-item "Set Default Font..." menu-set-font | |
b016851c | 1158 | :visible (display-multi-font-p) |
1ec4b7b2 | 1159 | :help "Select a default font")) |
b016851c SM |
1160 | |
1161 | (if (featurep 'system-font-setting) | |
1ec4b7b2 | 1162 | (bindings--define-key menu [menu-system-font] |
b016851c SM |
1163 | (menu-bar-make-toggle |
1164 | toggle-use-system-font font-use-system-font | |
7cc6e154 | 1165 | "Use System Font" |
b016851c SM |
1166 | "Use system font: %s" |
1167 | "Use the monospaced font defined by the system"))) | |
1168 | ||
1ec4b7b2 SM |
1169 | (bindings--define-key menu [showhide] |
1170 | `(menu-item "Show/Hide" ,menu-bar-showhide-menu)) | |
b016851c | 1171 | |
1ec4b7b2 | 1172 | (bindings--define-key menu [showhide-separator] |
b016851c SM |
1173 | menu-bar-separator) |
1174 | ||
1ec4b7b2 | 1175 | (bindings--define-key menu [mule] |
b016851c SM |
1176 | ;; It is better not to use backquote here, |
1177 | ;; because that makes a bootstrapping problem | |
1178 | ;; if you need to recompile all the Lisp files using interpreted code. | |
1ec4b7b2 | 1179 | `(menu-item "Multilingual Environment" ,mule-menu-keymap |
b016851c SM |
1180 | ;; Most of the MULE menu actually does make sense in |
1181 | ;; unibyte mode, e.g. language selection. | |
1182 | ;; :visible '(default-value 'enable-multibyte-characters) | |
1183 | )) | |
1184 | ;;(setq menu-bar-final-items (cons 'mule menu-bar-final-items)) | |
1ec4b7b2 SM |
1185 | ;;(bindings--define-key menu [preferences] |
1186 | ;; `(menu-item "Preferences" ,menu-bar-preferences-menu | |
1187 | ;; :help "Toggle important global options")) | |
b016851c | 1188 | |
1ec4b7b2 | 1189 | (bindings--define-key menu [mule-separator] |
b016851c SM |
1190 | menu-bar-separator) |
1191 | ||
1ec4b7b2 | 1192 | (bindings--define-key menu [debug-on-quit] |
b016851c SM |
1193 | (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit |
1194 | "Enter Debugger on Quit/C-g" "Debug on Quit %s" | |
1195 | "Enter Lisp debugger when C-g is pressed")) | |
1ec4b7b2 | 1196 | (bindings--define-key menu [debug-on-error] |
b016851c SM |
1197 | (menu-bar-make-toggle toggle-debug-on-error debug-on-error |
1198 | "Enter Debugger on Error" "Debug on Error %s" | |
1199 | "Enter Lisp debugger when an error is signaled")) | |
1ec4b7b2 | 1200 | (bindings--define-key menu [debugger-separator] |
b016851c SM |
1201 | menu-bar-separator) |
1202 | ||
1ec4b7b2 | 1203 | (bindings--define-key menu [blink-cursor-mode] |
0a1848ec LMI |
1204 | (menu-bar-make-mm-toggle |
1205 | blink-cursor-mode | |
1206 | "Blink Cursor" | |
1207 | "Whether the cursor blinks (Blink Cursor mode)")) | |
1ec4b7b2 | 1208 | (bindings--define-key menu [cursor-separator] |
b016851c SM |
1209 | menu-bar-separator) |
1210 | ||
1ec4b7b2 | 1211 | (bindings--define-key menu [save-place] |
0a1848ec LMI |
1212 | (menu-bar-make-toggle |
1213 | toggle-save-place-globally save-place | |
1214 | "Save Place in Files between Sessions" | |
1215 | "Saving place in files %s" | |
1216 | "Visit files of previous session when restarting Emacs" | |
1217 | (require 'saveplace) | |
1218 | ;; Do it by name, to avoid a free-variable | |
1219 | ;; warning during byte compilation. | |
1220 | (set-default | |
1221 | 'save-place (not (symbol-value 'save-place))))) | |
b016851c | 1222 | |
1ec4b7b2 | 1223 | (bindings--define-key menu [uniquify] |
0a1848ec LMI |
1224 | (menu-bar-make-toggle |
1225 | toggle-uniquify-buffer-names uniquify-buffer-name-style | |
1226 | "Use Directory Names in Buffer Names" | |
1227 | "Directory name in buffer names (uniquify) %s" | |
1228 | "Uniquify buffer names by adding parent directory names" | |
0a1848ec LMI |
1229 | (setq uniquify-buffer-name-style |
1230 | (if (not uniquify-buffer-name-style) | |
d5ccb7be | 1231 | 'post-forward-angle-brackets)))) |
b016851c | 1232 | |
1ec4b7b2 | 1233 | (bindings--define-key menu [edit-options-separator] |
b016851c | 1234 | menu-bar-separator) |
1ec4b7b2 | 1235 | (bindings--define-key menu [cua-mode] |
0a1848ec LMI |
1236 | (menu-bar-make-mm-toggle |
1237 | cua-mode | |
14cc04aa | 1238 | "Use CUA Keys (Cut/Paste with C-x/C-c/C-v)" |
0a1848ec LMI |
1239 | "Use C-z/C-x/C-c/C-v keys for undo/cut/copy/paste" |
1240 | (:visible (or (not (boundp 'cua-enable-cua-keys)) | |
1241 | cua-enable-cua-keys)))) | |
b016851c | 1242 | |
1ec4b7b2 | 1243 | (bindings--define-key menu [cua-emulation-mode] |
0a1848ec LMI |
1244 | (menu-bar-make-mm-toggle |
1245 | cua-mode | |
1246 | "Shift movement mark region (CUA)" | |
1247 | "Use shifted movement keys to set and extend the region" | |
1248 | (:visible (and (boundp 'cua-enable-cua-keys) | |
1249 | (not cua-enable-cua-keys))))) | |
b016851c | 1250 | |
1ec4b7b2 | 1251 | (bindings--define-key menu [case-fold-search] |
0a1848ec LMI |
1252 | (menu-bar-make-toggle |
1253 | toggle-case-fold-search case-fold-search | |
1254 | "Ignore Case for Search" | |
1255 | "Case-Insensitive Search %s" | |
1256 | "Ignore letter-case in search commands")) | |
b016851c | 1257 | |
1ec4b7b2 SM |
1258 | (bindings--define-key menu [line-wrapping] |
1259 | `(menu-item "Line Wrapping in This Buffer" | |
0a1848ec | 1260 | ,menu-bar-line-wrapping-menu)) |
b016851c SM |
1261 | |
1262 | ||
1ec4b7b2 | 1263 | (bindings--define-key menu [highlight-separator] |
b016851c | 1264 | menu-bar-separator) |
1ec4b7b2 | 1265 | (bindings--define-key menu [highlight-paren-mode] |
0a1848ec LMI |
1266 | (menu-bar-make-mm-toggle |
1267 | show-paren-mode | |
14cc04aa | 1268 | "Highlight Matching Parentheses" |
0a1848ec | 1269 | "Highlight matching/mismatched parentheses at cursor (Show Paren mode)")) |
1ec4b7b2 | 1270 | (bindings--define-key menu [transient-mark-mode] |
0a1848ec LMI |
1271 | (menu-bar-make-mm-toggle |
1272 | transient-mark-mode | |
1273 | "Highlight Active Region" | |
1274 | "Make text in active region stand out in color (Transient Mark mode)" | |
1275 | (:enable (not cua-mode)))) | |
b016851c | 1276 | menu)) |
7f315c7c | 1277 | |
e5683624 | 1278 | \f |
7f315c7c EZ |
1279 | ;; The "Tools" menu items |
1280 | ||
b016851c SM |
1281 | (defvar menu-bar-games-menu |
1282 | (let ((menu (make-sparse-keymap "Games"))) | |
1283 | ||
1ec4b7b2 SM |
1284 | (bindings--define-key menu [zone] |
1285 | '(menu-item "Zone Out" zone | |
1286 | :help "Play tricks with Emacs display when Emacs is idle")) | |
1287 | (bindings--define-key menu [tetris] | |
1288 | '(menu-item "Tetris" tetris | |
1289 | :help "Falling blocks game")) | |
1290 | (bindings--define-key menu [solitaire] | |
1291 | '(menu-item "Solitaire" solitaire | |
1292 | :help "Get rid of all the stones")) | |
1293 | (bindings--define-key menu [snake] | |
1294 | '(menu-item "Snake" snake | |
1295 | :help "Move snake around avoiding collisions")) | |
1296 | (bindings--define-key menu [pong] | |
1297 | '(menu-item "Pong" pong | |
1298 | :help "Bounce the ball to your opponent")) | |
1299 | (bindings--define-key menu [mult] | |
1300 | '(menu-item "Multiplication Puzzle" mpuz | |
1301 | :help "Exercise brain with multiplication")) | |
1302 | (bindings--define-key menu [life] | |
1303 | '(menu-item "Life" life | |
1304 | :help "Watch how John Conway's cellular automaton evolves")) | |
1305 | (bindings--define-key menu [land] | |
1306 | '(menu-item "Landmark" landmark | |
1307 | :help "Watch a neural-network robot learn landmarks")) | |
1308 | (bindings--define-key menu [hanoi] | |
1309 | '(menu-item "Towers of Hanoi" hanoi | |
1310 | :help "Watch Towers-of-Hanoi puzzle solved by Emacs")) | |
1311 | (bindings--define-key menu [gomoku] | |
1312 | '(menu-item "Gomoku" gomoku | |
1313 | :help "Mark 5 contiguous squares (like tic-tac-toe)")) | |
1314 | (bindings--define-key menu [bubbles] | |
1315 | '(menu-item "Bubbles" bubbles | |
1316 | :help "Remove all bubbles using the fewest moves")) | |
1317 | (bindings--define-key menu [black-box] | |
1318 | '(menu-item "Blackbox" blackbox | |
1319 | :help "Find balls in a black box by shooting rays")) | |
1320 | (bindings--define-key menu [adventure] | |
1321 | '(menu-item "Adventure" dunnet | |
1322 | :help "Dunnet, a text Adventure game for Emacs")) | |
1323 | (bindings--define-key menu [5x5] | |
1324 | '(menu-item "5x5" 5x5 | |
1325 | :help "Fill in all the squares on a 5x5 board")) | |
b016851c | 1326 | menu)) |
9a3558cb | 1327 | |
bfeee9d1 | 1328 | (defvar menu-bar-encryption-decryption-menu |
b016851c | 1329 | (let ((menu (make-sparse-keymap "Encryption/Decryption"))) |
1ec4b7b2 SM |
1330 | (bindings--define-key menu [insert-keys] |
1331 | '(menu-item "Insert Keys" epa-insert-keys | |
1332 | :help "Insert public keys after the current point")) | |
b016851c | 1333 | |
1ec4b7b2 SM |
1334 | (bindings--define-key menu [export-keys] |
1335 | '(menu-item "Export Keys" epa-export-keys | |
1336 | :help "Export public keys to a file")) | |
b016851c | 1337 | |
1ec4b7b2 SM |
1338 | (bindings--define-key menu [import-keys-region] |
1339 | '(menu-item "Import Keys from Region" epa-import-keys-region | |
1340 | :help "Import public keys from the current region")) | |
b016851c | 1341 | |
1ec4b7b2 SM |
1342 | (bindings--define-key menu [import-keys] |
1343 | '(menu-item "Import Keys from File..." epa-import-keys | |
1344 | :help "Import public keys from a file")) | |
b016851c | 1345 | |
1ec4b7b2 SM |
1346 | (bindings--define-key menu [list-keys] |
1347 | '(menu-item "List Keys" epa-list-keys | |
1348 | :help "Browse your public keyring")) | |
b016851c | 1349 | |
1ec4b7b2 | 1350 | (bindings--define-key menu [separator-keys] |
b016851c SM |
1351 | menu-bar-separator) |
1352 | ||
1ec4b7b2 SM |
1353 | (bindings--define-key menu [sign-region] |
1354 | '(menu-item "Sign Region" epa-sign-region | |
1355 | :help "Create digital signature of the current region")) | |
b016851c | 1356 | |
1ec4b7b2 SM |
1357 | (bindings--define-key menu [verify-region] |
1358 | '(menu-item "Verify Region" epa-verify-region | |
1359 | :help "Verify digital signature of the current region")) | |
b016851c | 1360 | |
1ec4b7b2 SM |
1361 | (bindings--define-key menu [encrypt-region] |
1362 | '(menu-item "Encrypt Region" epa-encrypt-region | |
1363 | :help "Encrypt the current region")) | |
b016851c | 1364 | |
1ec4b7b2 SM |
1365 | (bindings--define-key menu [decrypt-region] |
1366 | '(menu-item "Decrypt Region" epa-decrypt-region | |
1367 | :help "Decrypt the current region")) | |
b016851c | 1368 | |
1ec4b7b2 | 1369 | (bindings--define-key menu [separator-file] |
b016851c SM |
1370 | menu-bar-separator) |
1371 | ||
1ec4b7b2 SM |
1372 | (bindings--define-key menu [sign-file] |
1373 | '(menu-item "Sign File..." epa-sign-file | |
1374 | :help "Create digital signature of a file")) | |
b016851c | 1375 | |
1ec4b7b2 SM |
1376 | (bindings--define-key menu [verify-file] |
1377 | '(menu-item "Verify File..." epa-verify-file | |
1378 | :help "Verify digital signature of a file")) | |
b016851c | 1379 | |
1ec4b7b2 SM |
1380 | (bindings--define-key menu [encrypt-file] |
1381 | '(menu-item "Encrypt File..." epa-encrypt-file | |
1382 | :help "Encrypt a file")) | |
b016851c | 1383 | |
1ec4b7b2 SM |
1384 | (bindings--define-key menu [decrypt-file] |
1385 | '(menu-item "Decrypt File..." epa-decrypt-file | |
1386 | :help "Decrypt a file")) | |
b016851c SM |
1387 | |
1388 | menu)) | |
277e0f9d RS |
1389 | |
1390 | (defun menu-bar-read-mail () | |
724f328c | 1391 | "Read mail using `read-mail-command'." |
277e0f9d RS |
1392 | (interactive) |
1393 | (call-interactively read-mail-command)) | |
1394 | ||
b016851c SM |
1395 | (defvar menu-bar-tools-menu |
1396 | (let ((menu (make-sparse-keymap "Tools"))) | |
1397 | ||
1ec4b7b2 SM |
1398 | (bindings--define-key menu [games] |
1399 | `(menu-item "Games" ,menu-bar-games-menu)) | |
b016851c | 1400 | |
1ec4b7b2 | 1401 | (bindings--define-key menu [separator-games] |
b016851c SM |
1402 | menu-bar-separator) |
1403 | ||
1ec4b7b2 SM |
1404 | (bindings--define-key menu [encryption-decryption] |
1405 | `(menu-item "Encryption/Decryption" | |
1406 | ,menu-bar-encryption-decryption-menu)) | |
b016851c | 1407 | |
1ec4b7b2 | 1408 | (bindings--define-key menu [separator-encryption-decryption] |
b016851c SM |
1409 | menu-bar-separator) |
1410 | ||
1ec4b7b2 SM |
1411 | (bindings--define-key menu [simple-calculator] |
1412 | '(menu-item "Simple Calculator" calculator | |
1413 | :help "Invoke the Emacs built-in quick calculator")) | |
1414 | (bindings--define-key menu [calc] | |
1415 | '(menu-item "Programmable Calculator" calc | |
1416 | :help "Invoke the Emacs built-in full scientific calculator")) | |
1417 | (bindings--define-key menu [calendar] | |
1418 | '(menu-item "Calendar" calendar | |
1419 | :help "Invoke the Emacs built-in calendar")) | |
1420 | ||
1421 | (bindings--define-key menu [separator-net] | |
b016851c SM |
1422 | menu-bar-separator) |
1423 | ||
7a409b30 JL |
1424 | (bindings--define-key menu [browse-web] |
1425 | '(menu-item "Browse the Web..." browse-web)) | |
1ec4b7b2 SM |
1426 | (bindings--define-key menu [directory-search] |
1427 | '(menu-item "Directory Search" eudc-tools-menu)) | |
1428 | (bindings--define-key menu [compose-mail] | |
57953f49 | 1429 | '(menu-item "Compose New Mail" compose-mail |
b016851c | 1430 | :visible (and mail-user-agent (not (eq mail-user-agent 'ignore))) |
57953f49 | 1431 | :help "Start writing a new mail message")) |
1ec4b7b2 | 1432 | (bindings--define-key menu [rmail] |
57953f49 | 1433 | '(menu-item "Read Mail" menu-bar-read-mail |
b016851c SM |
1434 | :visible (and read-mail-command |
1435 | (not (eq read-mail-command 'ignore))) | |
57953f49 | 1436 | :help "Read your mail")) |
b016851c | 1437 | |
1ec4b7b2 | 1438 | (bindings--define-key menu [gnus] |
57953f49 | 1439 | '(menu-item "Read Net News" gnus |
1ec4b7b2 | 1440 | :help "Read network news groups")) |
b016851c | 1441 | |
1ec4b7b2 | 1442 | (bindings--define-key menu [separator-vc] |
b016851c SM |
1443 | menu-bar-separator) |
1444 | ||
1ec4b7b2 | 1445 | (bindings--define-key menu [vc] nil) ;Create the place for the VC menu. |
b016851c | 1446 | |
1ec4b7b2 | 1447 | (bindings--define-key menu [separator-compare] |
b016851c SM |
1448 | menu-bar-separator) |
1449 | ||
1ec4b7b2 SM |
1450 | (bindings--define-key menu [epatch] |
1451 | '(menu-item "Apply Patch" menu-bar-epatch-menu)) | |
1452 | (bindings--define-key menu [ediff-merge] | |
1453 | '(menu-item "Merge" menu-bar-ediff-merge-menu)) | |
1454 | (bindings--define-key menu [compare] | |
1455 | '(menu-item "Compare (Ediff)" menu-bar-ediff-menu)) | |
b016851c | 1456 | |
1ec4b7b2 | 1457 | (bindings--define-key menu [separator-spell] |
b016851c SM |
1458 | menu-bar-separator) |
1459 | ||
1ec4b7b2 SM |
1460 | (bindings--define-key menu [spell] |
1461 | '(menu-item "Spell Checking" ispell-menu-map)) | |
b016851c | 1462 | |
1ec4b7b2 | 1463 | (bindings--define-key menu [separator-prog] |
b016851c SM |
1464 | menu-bar-separator) |
1465 | ||
1ec4b7b2 SM |
1466 | (bindings--define-key menu [semantic] |
1467 | '(menu-item "Source Code Parsers (Semantic)" | |
b016851c | 1468 | semantic-mode |
1ec4b7b2 | 1469 | :help "Toggle automatic parsing in source code buffers (Semantic mode)" |
b016851c SM |
1470 | :button (:toggle . (bound-and-true-p semantic-mode)))) |
1471 | ||
1ec4b7b2 | 1472 | (bindings--define-key menu [ede] |
1bb1e038 | 1473 | '(menu-item "Project Support (EDE)" |
b016851c | 1474 | global-ede-mode |
1ec4b7b2 | 1475 | :help "Toggle the Emacs Development Environment (Global EDE mode)" |
b016851c SM |
1476 | :button (:toggle . (bound-and-true-p global-ede-mode)))) |
1477 | ||
1ec4b7b2 SM |
1478 | (bindings--define-key menu [gdb] |
1479 | '(menu-item "Debugger (GDB)..." gdb | |
1480 | :help "Debug a program from within Emacs with GDB")) | |
1481 | (bindings--define-key menu [shell-on-region] | |
1482 | '(menu-item "Shell Command on Region..." shell-command-on-region | |
b016851c | 1483 | :enable mark-active |
1ec4b7b2 SM |
1484 | :help "Pass marked region to a shell command")) |
1485 | (bindings--define-key menu [shell] | |
1486 | '(menu-item "Shell Command..." shell-command | |
1487 | :help "Invoke a shell command and catch its output")) | |
1488 | (bindings--define-key menu [compile] | |
1489 | '(menu-item "Compile..." compile | |
1490 | :help "Invoke compiler or Make, view compilation errors")) | |
1491 | (bindings--define-key menu [grep] | |
1492 | '(menu-item "Search Files (Grep)..." grep | |
1493 | :help "Search files for strings or regexps (with Grep)")) | |
b016851c | 1494 | menu)) |
7f315c7c EZ |
1495 | \f |
1496 | ;; The "Help" menu items | |
1497 | ||
b016851c SM |
1498 | (defvar menu-bar-describe-menu |
1499 | (let ((menu (make-sparse-keymap "Describe"))) | |
1500 | ||
1ec4b7b2 SM |
1501 | (bindings--define-key menu [mule-diag] |
1502 | '(menu-item "Show All of Mule Status" mule-diag | |
b016851c | 1503 | :visible (default-value 'enable-multibyte-characters) |
1ec4b7b2 SM |
1504 | :help "Display multilingual environment settings")) |
1505 | (bindings--define-key menu [describe-coding-system-briefly] | |
1506 | '(menu-item "Describe Coding System (Briefly)" | |
b016851c SM |
1507 | describe-current-coding-system-briefly |
1508 | :visible (default-value 'enable-multibyte-characters))) | |
1ec4b7b2 SM |
1509 | (bindings--define-key menu [describe-coding-system] |
1510 | '(menu-item "Describe Coding System..." describe-coding-system | |
b016851c | 1511 | :visible (default-value 'enable-multibyte-characters))) |
1ec4b7b2 SM |
1512 | (bindings--define-key menu [describe-input-method] |
1513 | '(menu-item "Describe Input Method..." describe-input-method | |
b016851c | 1514 | :visible (default-value 'enable-multibyte-characters) |
1ec4b7b2 SM |
1515 | :help "Keyboard layout for specific input method")) |
1516 | (bindings--define-key menu [describe-language-environment] | |
1517 | `(menu-item "Describe Language Environment" | |
b016851c SM |
1518 | ,describe-language-environment-map)) |
1519 | ||
1ec4b7b2 | 1520 | (bindings--define-key menu [separator-desc-mule] |
b016851c SM |
1521 | menu-bar-separator) |
1522 | ||
1ec4b7b2 SM |
1523 | (bindings--define-key menu [list-keybindings] |
1524 | '(menu-item "List Key Bindings" describe-bindings | |
1525 | :help "Display all current key bindings (keyboard shortcuts)")) | |
1526 | (bindings--define-key menu [describe-current-display-table] | |
1527 | '(menu-item "Describe Display Table" describe-current-display-table | |
1528 | :help "Describe the current display table")) | |
1529 | (bindings--define-key menu [describe-package] | |
1530 | '(menu-item "Describe Package..." describe-package | |
1531 | :help "Display documentation of a Lisp package")) | |
1532 | (bindings--define-key menu [describe-face] | |
1533 | '(menu-item "Describe Face..." describe-face | |
1534 | :help "Display the properties of a face")) | |
1535 | (bindings--define-key menu [describe-variable] | |
1536 | '(menu-item "Describe Variable..." describe-variable | |
1537 | :help "Display documentation of variable/option")) | |
1538 | (bindings--define-key menu [describe-function] | |
1539 | '(menu-item "Describe Function..." describe-function | |
1540 | :help "Display documentation of function/command")) | |
1541 | (bindings--define-key menu [describe-key-1] | |
1542 | '(menu-item "Describe Key or Mouse Operation..." describe-key | |
b016851c | 1543 | ;; Users typically don't identify keys and menu items... |
1ec4b7b2 SM |
1544 | :help "Display documentation of command bound to a \ |
1545 | key, a click, or a menu-item")) | |
1546 | (bindings--define-key menu [describe-mode] | |
1547 | '(menu-item "Describe Buffer Modes" describe-mode | |
1548 | :help "Describe this buffer's major and minor mode")) | |
b016851c | 1549 | menu)) |
df5bde6d | 1550 | |
5275d6a8 EZ |
1551 | (defun menu-bar-read-lispref () |
1552 | "Display the Emacs Lisp Reference manual in Info mode." | |
1553 | (interactive) | |
1554 | (info "elisp")) | |
1555 | ||
1556 | (defun menu-bar-read-lispintro () | |
1557 | "Display the Introduction to Emacs Lisp Programming in Info mode." | |
1558 | (interactive) | |
1559 | (info "eintr")) | |
1560 | ||
5275d6a8 EZ |
1561 | (defun search-emacs-glossary () |
1562 | "Display the Glossary node of the Emacs manual in Info mode." | |
1563 | (interactive) | |
1564 | (info "(emacs)Glossary")) | |
1565 | ||
1566 | (defun emacs-index-search (topic) | |
1567 | "Look up TOPIC in the indices of the Emacs User Manual." | |
1568 | (interactive "sSubject to look up: ") | |
1569 | (info "emacs") | |
1570 | (Info-index topic)) | |
1571 | ||
1572 | (defun elisp-index-search (topic) | |
1573 | "Look up TOPIC in the indices of the Emacs Lisp Reference Manual." | |
1574 | (interactive "sSubject to look up: ") | |
1575 | (info "elisp") | |
1576 | (Info-index topic)) | |
df5bde6d | 1577 | |
b016851c SM |
1578 | (defvar menu-bar-search-documentation-menu |
1579 | (let ((menu (make-sparse-keymap "Search Documentation"))) | |
b8f7ff0d | 1580 | |
1ec4b7b2 SM |
1581 | (bindings--define-key menu [search-documentation-strings] |
1582 | '(menu-item "Search Documentation Strings..." apropos-documentation | |
b016851c | 1583 | :help |
1ec4b7b2 SM |
1584 | "Find functions and variables whose doc strings match a regexp")) |
1585 | (bindings--define-key menu [find-any-object-by-name] | |
1586 | '(menu-item "Find Any Object by Name..." apropos | |
1587 | :help "Find symbols of any kind whose names match a regexp")) | |
1588 | (bindings--define-key menu [find-option-by-value] | |
1589 | '(menu-item "Find Options by Value..." apropos-value | |
1590 | :help "Find variables whose values match a regexp")) | |
1591 | (bindings--define-key menu [find-options-by-name] | |
acfe10b7 BG |
1592 | '(menu-item "Find Options by Name..." apropos-user-option |
1593 | :help "Find user options whose names match a regexp")) | |
1ec4b7b2 SM |
1594 | (bindings--define-key menu [find-commands-by-name] |
1595 | '(menu-item "Find Commands by Name..." apropos-command | |
1596 | :help "Find commands whose names match a regexp")) | |
1597 | (bindings--define-key menu [sep1] | |
b016851c | 1598 | menu-bar-separator) |
1ec4b7b2 SM |
1599 | (bindings--define-key menu [lookup-command-in-manual] |
1600 | '(menu-item "Look Up Command in User Manual..." Info-goto-emacs-command-node | |
1601 | :help "Display manual section that describes a command")) | |
1602 | (bindings--define-key menu [lookup-key-in-manual] | |
1603 | '(menu-item "Look Up Key in User Manual..." Info-goto-emacs-key-command-node | |
1604 | :help "Display manual section that describes a key")) | |
1605 | (bindings--define-key menu [lookup-subject-in-elisp-manual] | |
1606 | '(menu-item "Look Up Subject in ELisp Manual..." elisp-index-search | |
1607 | :help "Find description of a subject in Emacs Lisp manual")) | |
1608 | (bindings--define-key menu [lookup-subject-in-emacs-manual] | |
1609 | '(menu-item "Look Up Subject in User Manual..." emacs-index-search | |
1610 | :help "Find description of a subject in Emacs User manual")) | |
1611 | (bindings--define-key menu [emacs-terminology] | |
1612 | '(menu-item "Emacs Terminology" search-emacs-glossary | |
1613 | :help "Display the Glossary section of the Emacs manual")) | |
b016851c SM |
1614 | menu)) |
1615 | ||
1616 | (defvar menu-bar-manuals-menu | |
1617 | (let ((menu (make-sparse-keymap "More Manuals"))) | |
1618 | ||
1ec4b7b2 SM |
1619 | (bindings--define-key menu [man] |
1620 | '(menu-item "Read Man Page..." manual-entry | |
1621 | :help "Man-page docs for external commands and libraries")) | |
1622 | (bindings--define-key menu [sep2] | |
b016851c | 1623 | menu-bar-separator) |
1ec4b7b2 SM |
1624 | (bindings--define-key menu [order-emacs-manuals] |
1625 | '(menu-item "Ordering Manuals" view-order-manuals | |
1626 | :help "How to order manuals from the Free Software Foundation")) | |
1627 | (bindings--define-key menu [lookup-subject-in-all-manuals] | |
1628 | '(menu-item "Lookup Subject in all Manuals..." info-apropos | |
1629 | :help "Find description of a subject in all installed manuals")) | |
1630 | (bindings--define-key menu [other-manuals] | |
1631 | '(menu-item "All Other Manuals (Info)" Info-directory | |
1632 | :help "Read any of the installed manuals")) | |
1633 | (bindings--define-key menu [emacs-lisp-reference] | |
1634 | '(menu-item "Emacs Lisp Reference" menu-bar-read-lispref | |
1635 | :help "Read the Emacs Lisp Reference manual")) | |
1636 | (bindings--define-key menu [emacs-lisp-intro] | |
1637 | '(menu-item "Introduction to Emacs Lisp" menu-bar-read-lispintro | |
1638 | :help "Read the Introduction to Emacs Lisp Programming")) | |
b016851c SM |
1639 | menu)) |
1640 | ||
277e0f9d RS |
1641 | (defun help-with-tutorial-spec-language () |
1642 | "Use the Emacs tutorial, specifying which language you want." | |
f1180544 | 1643 | (interactive) |
277e0f9d RS |
1644 | (help-with-tutorial t)) |
1645 | ||
b016851c SM |
1646 | (defvar menu-bar-help-menu |
1647 | (let ((menu (make-sparse-keymap "Help"))) | |
1ec4b7b2 SM |
1648 | (bindings--define-key menu [about-gnu-project] |
1649 | '(menu-item "About GNU" describe-gnu-project | |
1650 | :help "About the GNU System, GNU Project, and GNU/Linux")) | |
1651 | (bindings--define-key menu [about-emacs] | |
1652 | '(menu-item "About Emacs" about-emacs | |
1653 | :help "Display version number, copyright info, and basic help")) | |
1654 | (bindings--define-key menu [sep4] | |
b016851c | 1655 | menu-bar-separator) |
1ec4b7b2 SM |
1656 | (bindings--define-key menu [describe-no-warranty] |
1657 | '(menu-item "(Non)Warranty" describe-no-warranty | |
1658 | :help "Explain that Emacs has NO WARRANTY")) | |
1659 | (bindings--define-key menu [describe-copying] | |
1660 | '(menu-item "Copying Conditions" describe-copying | |
1661 | :help "Show the Emacs license (GPL)")) | |
1662 | (bindings--define-key menu [getting-new-versions] | |
1663 | '(menu-item "Getting New Versions" describe-distribution | |
1664 | :help "How to get the latest version of Emacs")) | |
1665 | (bindings--define-key menu [sep2] | |
b016851c | 1666 | menu-bar-separator) |
1ec4b7b2 | 1667 | (bindings--define-key menu [external-packages] |
0030ec15 GM |
1668 | '(menu-item "Finding Extra Packages" view-external-packages |
1669 | :help "How to get more Lisp packages for use in Emacs")) | |
1ec4b7b2 SM |
1670 | (bindings--define-key menu [find-emacs-packages] |
1671 | '(menu-item "Search Built-in Packages" finder-by-keyword | |
1672 | :help "Find built-in packages and features by keyword")) | |
1673 | (bindings--define-key menu [more-manuals] | |
1674 | `(menu-item "More Manuals" ,menu-bar-manuals-menu)) | |
1675 | (bindings--define-key menu [emacs-manual] | |
1676 | '(menu-item "Read the Emacs Manual" info-emacs-manual | |
1677 | :help "Full documentation of Emacs features")) | |
1678 | (bindings--define-key menu [describe] | |
1679 | `(menu-item "Describe" ,menu-bar-describe-menu)) | |
1680 | (bindings--define-key menu [search-documentation] | |
1681 | `(menu-item "Search Documentation" ,menu-bar-search-documentation-menu)) | |
1682 | (bindings--define-key menu [sep1] | |
b016851c | 1683 | menu-bar-separator) |
1ec4b7b2 SM |
1684 | (bindings--define-key menu [emacs-psychotherapist] |
1685 | '(menu-item "Emacs Psychotherapist" doctor | |
1686 | :help "Our doctor will help you feel better")) | |
1687 | (bindings--define-key menu [send-emacs-bug-report] | |
1688 | '(menu-item "Send Bug Report..." report-emacs-bug | |
1689 | :help "Send e-mail to Emacs maintainers")) | |
1690 | (bindings--define-key menu [emacs-manual-bug] | |
1691 | '(menu-item "How to Report a Bug" info-emacs-bug | |
1692 | :help "Read about how to report an Emacs bug")) | |
1693 | (bindings--define-key menu [emacs-known-problems] | |
1694 | '(menu-item "Emacs Known Problems" view-emacs-problems | |
1695 | :help "Read about known problems with Emacs")) | |
1696 | (bindings--define-key menu [emacs-news] | |
1697 | '(menu-item "Emacs News" view-emacs-news | |
1698 | :help "New features of this version")) | |
1699 | (bindings--define-key menu [emacs-faq] | |
1700 | '(menu-item "Emacs FAQ" view-emacs-FAQ | |
1701 | :help "Frequently asked (and answered) questions about Emacs")) | |
1702 | ||
1703 | (bindings--define-key menu [emacs-tutorial-language-specific] | |
1704 | '(menu-item "Emacs Tutorial (choose language)..." | |
b016851c | 1705 | help-with-tutorial-spec-language |
1ec4b7b2 SM |
1706 | :help "Learn how to use Emacs (choose a language)")) |
1707 | (bindings--define-key menu [emacs-tutorial] | |
1708 | '(menu-item "Emacs Tutorial" help-with-tutorial | |
1709 | :help "Learn how to use Emacs")) | |
b016851c SM |
1710 | |
1711 | ;; In OS X it's in the app menu already. | |
1712 | ;; FIXME? There already is an "About Emacs" (sans ...) entry in the Help menu. | |
1713 | (and (featurep 'ns) | |
1714 | (not (eq system-type 'darwin)) | |
1ec4b7b2 SM |
1715 | (bindings--define-key menu [info-panel] |
1716 | '(menu-item "About Emacs..." ns-do-emacs-info-panel))) | |
b016851c SM |
1717 | menu)) |
1718 | ||
1ec4b7b2 SM |
1719 | (bindings--define-key global-map [menu-bar tools] |
1720 | (cons "Tools" menu-bar-tools-menu)) | |
1721 | (bindings--define-key global-map [menu-bar buffer] | |
1722 | (cons "Buffers" global-buffers-menu-map)) | |
1723 | (bindings--define-key global-map [menu-bar options] | |
1724 | (cons "Options" menu-bar-options-menu)) | |
1725 | (bindings--define-key global-map [menu-bar edit] | |
1726 | (cons "Edit" menu-bar-edit-menu)) | |
1727 | (bindings--define-key global-map [menu-bar file] | |
1728 | (cons "File" menu-bar-file-menu)) | |
5f161884 JD |
1729 | (bindings--define-key global-map [menu-bar help-menu] |
1730 | (cons (purecopy "Help") menu-bar-help-menu)) | |
b3edb781 | 1731 | |
92752c3a EZ |
1732 | (defun menu-bar-menu-frame-live-and-visible-p () |
1733 | "Return non-nil if the menu frame is alive and visible. | |
1734 | The menu frame is the frame for which we are updating the menu." | |
55d42133 | 1735 | (let ((menu-frame (or menu-updating-frame (selected-frame)))) |
92752c3a EZ |
1736 | (and (frame-live-p menu-frame) |
1737 | (frame-visible-p menu-frame)))) | |
1738 | ||
1739 | (defun menu-bar-non-minibuffer-window-p () | |
1740 | "Return non-nil if selected window of the menu frame is not a minibuf window. | |
1741 | ||
1742 | See the documentation of `menu-bar-menu-frame-live-and-visible-p' | |
1743 | for the definition of the menu frame." | |
55d42133 | 1744 | (let ((menu-frame (or menu-updating-frame (selected-frame)))) |
92752c3a EZ |
1745 | (not (window-minibuffer-p (frame-selected-window menu-frame))))) |
1746 | ||
6eee5abf | 1747 | (defun kill-this-buffer () ; for the menu bar |
a86b330f JL |
1748 | "Kill the current buffer. |
1749 | When called in the minibuffer, get out of the minibuffer | |
1750 | using `abort-recursive-edit'." | |
db774a16 | 1751 | (interactive) |
96ef9ccd MR |
1752 | (cond |
1753 | ;; Don't do anything when `menu-frame' is not alive or visible | |
1754 | ;; (Bug#8184). | |
1755 | ((not (menu-bar-menu-frame-live-and-visible-p))) | |
1756 | ((menu-bar-non-minibuffer-window-p) | |
1757 | (kill-buffer (current-buffer))) | |
1758 | (t | |
1759 | (abort-recursive-edit)))) | |
db774a16 | 1760 | |
2f1139a4 | 1761 | (defun kill-this-buffer-enabled-p () |
159daf87 MR |
1762 | "Return non-nil if the `kill-this-buffer' menu item should be enabled." |
1763 | (or (not (menu-bar-non-minibuffer-window-p)) | |
1764 | (let (found-1) | |
1765 | ;; Instead of looping over entire buffer list, stop once we've | |
1766 | ;; found two "killable" buffers (Bug#8184). | |
1767 | (catch 'found-2 | |
1768 | (dolist (buffer (buffer-list)) | |
1769 | (unless (string-match-p "^ " (buffer-name buffer)) | |
1770 | (if (not found-1) | |
1771 | (setq found-1 t) | |
1772 | (throw 'found-2 t)))))))) | |
1f50590a | 1773 | |
92752c3a | 1774 | (put 'dired 'menu-enable '(menu-bar-non-minibuffer-window-p)) |
1f50590a | 1775 | |
a0213a97 | 1776 | ;; Permit deleting frame if it would leave a visible or iconified frame. |
82a74107 KH |
1777 | (defun delete-frame-enabled-p () |
1778 | "Return non-nil if `delete-frame' should be enabled in the menu bar." | |
1779 | (let ((frames (frame-list)) | |
27aa8132 RS |
1780 | (count 0)) |
1781 | (while frames | |
1782 | (if (frame-visible-p (car frames)) | |
1783 | (setq count (1+ count))) | |
1784 | (setq frames (cdr frames))) | |
1785 | (> count 1))) | |
2f1139a4 | 1786 | |
30e19aee | 1787 | (defcustom yank-menu-length 20 |
9201cc28 | 1788 | "Maximum length to display in the yank-menu." |
30e19aee | 1789 | :type 'integer |
d3434a5b | 1790 | :group 'menu) |
3dd92899 KH |
1791 | |
1792 | (defun menu-bar-update-yank-menu (string old) | |
1793 | (let ((front (car (cdr yank-menu))) | |
1794 | (menu-string (if (<= (length string) yank-menu-length) | |
1795 | string | |
c3e1d435 RS |
1796 | (concat |
1797 | (substring string 0 (/ yank-menu-length 2)) | |
1798 | "..." | |
1799 | (substring string (- (/ yank-menu-length 2))))))) | |
7c70a955 RS |
1800 | ;; Don't let the menu string be all dashes |
1801 | ;; because that has a special meaning in a menu. | |
1802 | (if (string-match "\\`-+\\'" menu-string) | |
1803 | (setq menu-string (concat menu-string " "))) | |
3dd92899 KH |
1804 | ;; If we're supposed to be extending an existing string, and that |
1805 | ;; string really is at the front of the menu, then update it in place. | |
1806 | (if (and old (or (eq old (car front)) | |
1807 | (string= old (car front)))) | |
dfabc98f | 1808 | (progn |
3dd92899 KH |
1809 | (setcar front string) |
1810 | (setcar (cdr front) menu-string)) | |
1811 | (setcdr yank-menu | |
1812 | (cons | |
1813 | (cons string (cons menu-string 'menu-bar-select-yank)) | |
1814 | (cdr yank-menu))))) | |
1815 | (if (> (length (cdr yank-menu)) kill-ring-max) | |
1816 | (setcdr (nthcdr kill-ring-max yank-menu) nil))) | |
1817 | ||
4cca6fbd | 1818 | (put 'menu-bar-select-yank 'apropos-inhibit t) |
3dd92899 | 1819 | (defun menu-bar-select-yank () |
5fb64ecc EZ |
1820 | "Insert the stretch of previously-killed text selected from menu. |
1821 | The menu shows all the killed text sequences stored in `kill-ring'." | |
3dd92899 KH |
1822 | (interactive "*") |
1823 | (push-mark (point)) | |
1824 | (insert last-command-event)) | |
68310f2a | 1825 | |
40954111 | 1826 | \f |
d3434a5b JL |
1827 | ;;; Buffers Menu |
1828 | ||
1829 | (defcustom buffers-menu-max-size 10 | |
9201cc28 | 1830 | "Maximum number of entries which may appear on the Buffers menu. |
d3434a5b JL |
1831 | If this is 10, then only the ten most-recently-selected buffers are shown. |
1832 | If this is nil, then all buffers are shown. | |
1833 | A large number or nil slows down menu responsiveness." | |
1834 | :type '(choice integer | |
1835 | (const :tag "All" nil)) | |
1836 | :group 'menu) | |
1837 | ||
1838 | (defcustom buffers-menu-buffer-name-length 30 | |
9201cc28 | 1839 | "Maximum length of the buffer name on the Buffers menu. |
d3434a5b JL |
1840 | If this is a number, then buffer names are truncated to this length. |
1841 | If this is nil, then buffer names are shown in full. | |
1842 | A large number or nil makes the menu too wide." | |
1843 | :type '(choice integer | |
1844 | (const :tag "Full length" nil)) | |
1845 | :group 'menu) | |
1846 | ||
68310f2a MB |
1847 | (defcustom buffers-menu-show-directories 'unless-uniquify |
1848 | "If non-nil, show directories in the Buffers menu for buffers that have them. | |
1849 | The special value `unless-uniquify' means that directories will be shown | |
1850 | unless `uniquify-buffer-name-style' is non-nil (in which case, buffer | |
1851 | names should include enough of a buffer's directory to distinguish it | |
1852 | from other buffers). | |
1853 | ||
1854 | Setting this variable directly does not take effect until next time the | |
1855 | Buffers menu is regenerated." | |
1856 | :set (lambda (symbol value) | |
1857 | (set symbol value) | |
1858 | (menu-bar-update-buffers t)) | |
1859 | :initialize 'custom-initialize-default | |
1860 | :type '(choice (const :tag "Never" nil) | |
1861 | (const :tag "Unless uniquify is enabled" unless-uniquify) | |
1862 | (const :tag "Always" t)) | |
1863 | :group 'menu) | |
1864 | ||
1865 | (defcustom buffers-menu-show-status t | |
1866 | "If non-nil, show modified/read-only status of buffers in the Buffers menu. | |
1867 | Setting this variable directly does not take effect until next time the | |
1868 | Buffers menu is regenerated." | |
1869 | :set (lambda (symbol value) | |
1870 | (set symbol value) | |
1871 | (menu-bar-update-buffers t)) | |
1872 | :initialize 'custom-initialize-default | |
1873 | :type 'boolean | |
1874 | :group 'menu) | |
1875 | ||
11ee8d90 | 1876 | (defvar list-buffers-directory nil |
8f75f2da | 1877 | "String to display in buffer listings for buffers not visiting a file.") |
11ee8d90 | 1878 | (make-variable-buffer-local 'list-buffers-directory) |
d0690d12 | 1879 | |
fb75de8f VJL |
1880 | (defun menu-bar-select-buffer () |
1881 | (interactive) | |
1882 | (switch-to-buffer last-command-event)) | |
1883 | ||
ed10603b SM |
1884 | (defun menu-bar-select-frame (frame) |
1885 | (make-frame-visible frame) | |
1886 | (raise-frame frame) | |
1887 | (select-frame frame)) | |
09642d97 | 1888 | |
c171b42f | 1889 | (defun menu-bar-update-buffers-1 (elt) |
68703c11 MB |
1890 | (let* ((buf (car elt)) |
1891 | (file | |
68310f2a MB |
1892 | (and (if (eq buffers-menu-show-directories 'unless-uniquify) |
1893 | (or (not (boundp 'uniquify-buffer-name-style)) | |
1894 | (null uniquify-buffer-name-style)) | |
1895 | buffers-menu-show-directories) | |
68703c11 | 1896 | (or (buffer-file-name buf) |
68310f2a | 1897 | (buffer-local-value 'list-buffers-directory buf))))) |
68703c11 MB |
1898 | (when file |
1899 | (setq file (file-name-directory file))) | |
1900 | (when (and file (> (length file) 20)) | |
1901 | (setq file (concat "..." (substring file -17)))) | |
68310f2a MB |
1902 | (cons (if buffers-menu-show-status |
1903 | (let ((mod (if (buffer-modified-p buf) "*" "")) | |
1904 | (ro (if (buffer-local-value 'buffer-read-only buf) "%" ""))) | |
1905 | (if file | |
1906 | (format "%s %s%s -- %s" (cdr elt) mod ro file) | |
1907 | (format "%s %s%s" (cdr elt) mod ro))) | |
1908 | (if file | |
1909 | (format "%s -- %s" (cdr elt) file) | |
1910 | (cdr elt))) | |
68703c11 MB |
1911 | buf))) |
1912 | ||
887d3c94 MB |
1913 | ;; Used to cache the menu entries for commands in the Buffers menu |
1914 | (defvar menu-bar-buffers-menu-command-entries nil) | |
1915 | ||
5d907d6c DA |
1916 | (defvar menu-bar-select-buffer-function 'switch-to-buffer |
1917 | "Function to select the buffer chosen from the `Buffers' menu-bar menu. | |
1918 | It must accept a buffer as its only required argument.") | |
1919 | ||
ee1dbceb | 1920 | (defun menu-bar-update-buffers (&optional force) |
29397c58 | 1921 | ;; If user discards the Buffers item, play along. |
4d587a6c | 1922 | (and (lookup-key (current-global-map) [menu-bar buffer]) |
ee1dbceb | 1923 | (or force (frame-or-buffer-changed-p)) |
29397c58 RS |
1924 | (let ((buffers (buffer-list)) |
1925 | (frames (frame-list)) | |
bf902855 | 1926 | buffers-menu) |
29397c58 RS |
1927 | ;; If requested, list only the N most recently selected buffers. |
1928 | (if (and (integerp buffers-menu-max-size) | |
1929 | (> buffers-menu-max-size 1)) | |
1930 | (if (> (length buffers) buffers-menu-max-size) | |
1931 | (setcdr (nthcdr buffers-menu-max-size buffers) nil))) | |
1932 | ||
1933 | ;; Make the menu of buffers proper. | |
1934 | (setq buffers-menu | |
ed10603b | 1935 | (let (alist) |
8b621d39 MB |
1936 | ;; Put into each element of buffer-list |
1937 | ;; the name for actual display, | |
1938 | ;; perhaps truncated in the middle. | |
ed10603b SM |
1939 | (dolist (buf buffers) |
1940 | (let ((name (buffer-name buf))) | |
1941 | (unless (eq ?\s (aref name 0)) | |
1942 | (push (menu-bar-update-buffers-1 | |
1943 | (cons buf | |
d3434a5b JL |
1944 | (if (and (integerp buffers-menu-buffer-name-length) |
1945 | (> (length name) buffers-menu-buffer-name-length)) | |
1946 | (concat | |
1947 | (substring | |
1948 | name 0 (/ buffers-menu-buffer-name-length 2)) | |
1949 | "..." | |
1950 | (substring | |
1951 | name (- (/ buffers-menu-buffer-name-length 2)))) | |
1952 | name) | |
1953 | )) | |
ed10603b SM |
1954 | alist)))) |
1955 | ;; Now make the actual list of items. | |
1956 | (let ((buffers-vec (make-vector (length alist) nil)) | |
1957 | (i (length alist))) | |
1958 | (dolist (pair alist) | |
1959 | (setq i (1- i)) | |
1960 | (aset buffers-vec i | |
1961 | (nconc (list (car pair) | |
8b621d39 | 1962 | (cons nil nil)) |
ed10603b SM |
1963 | `(lambda () |
1964 | (interactive) | |
5d907d6c | 1965 | (funcall menu-bar-select-buffer-function ,(cdr pair)))))) |
ed10603b | 1966 | (list buffers-vec)))) |
29397c58 RS |
1967 | |
1968 | ;; Make a Frames menu if we have more than one frame. | |
8b621d39 | 1969 | (when (cdr frames) |
ed10603b SM |
1970 | (let* ((frames-vec (make-vector (length frames) nil)) |
1971 | (frames-menu | |
1972 | (cons 'keymap | |
1973 | (list "Select Frame" frames-vec))) | |
1974 | (i 0)) | |
1975 | (dolist (frame frames) | |
1976 | (aset frames-vec i | |
1977 | (nconc | |
1978 | (list | |
1979 | (frame-parameter frame 'name) | |
1980 | (cons nil nil)) | |
1981 | `(lambda () | |
1982 | (interactive) (menu-bar-select-frame ,frame)))) | |
1983 | (setq i (1+ i))) | |
8b621d39 MB |
1984 | ;; Put it after the normal buffers |
1985 | (setq buffers-menu | |
1986 | (nconc buffers-menu | |
1987 | `((frames-separator "--") | |
1988 | (frames menu-item "Frames" ,frames-menu)))))) | |
1989 | ||
887d3c94 MB |
1990 | ;; Add in some normal commands at the end of the menu. We use |
1991 | ;; the copy cached in `menu-bar-buffers-menu-command-entries' | |
1992 | ;; if it's been set already. Note that we can't use constant | |
1993 | ;; lists for the menu-entries, because the low-level menu-code | |
1994 | ;; modifies them. | |
1995 | (unless menu-bar-buffers-menu-command-entries | |
1996 | (setq menu-bar-buffers-menu-command-entries | |
1997 | (list '(command-separator "--") | |
332b907c RS |
1998 | (list 'next-buffer |
1999 | 'menu-item | |
2000 | "Next Buffer" | |
2001 | 'next-buffer | |
2002 | :help "Switch to the \"next\" buffer in a cyclic order") | |
a74f9094 | 2003 | (list 'previous-buffer |
332b907c RS |
2004 | 'menu-item |
2005 | "Previous Buffer" | |
a74f9094 | 2006 | 'previous-buffer |
332b907c | 2007 | :help "Switch to the \"previous\" buffer in a cyclic order") |
887d3c94 MB |
2008 | (list 'select-named-buffer |
2009 | 'menu-item | |
2010 | "Select Named Buffer..." | |
2011 | 'switch-to-buffer | |
2012 | :help "Prompt for a buffer name, and select that buffer in the current window") | |
2013 | (list 'list-all-buffers | |
2014 | 'menu-item | |
2015 | "List All Buffers" | |
2016 | 'list-buffers | |
4f00f90f | 2017 | :help "Pop up a window listing all Emacs buffers" |
887d3c94 | 2018 | )))) |
8b621d39 | 2019 | (setq buffers-menu |
887d3c94 | 2020 | (nconc buffers-menu menu-bar-buffers-menu-command-entries)) |
8b621d39 | 2021 | |
bf902855 SM |
2022 | ;; We used to "(define-key (current-global-map) [menu-bar buffer]" |
2023 | ;; but that did not do the right thing when the [menu-bar buffer] | |
2024 | ;; entry above had been moved (e.g. to a parent keymap). | |
feab892d | 2025 | (setcdr global-buffers-menu-map (cons "Buffers" buffers-menu))))) |
09642d97 RS |
2026 | |
2027 | (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers) | |
2f1139a4 | 2028 | |
3f557298 RS |
2029 | (menu-bar-update-buffers) |
2030 | ||
40954111 | 2031 | ;; this version is too slow |
a9d96061 SM |
2032 | ;;(defun format-buffers-menu-line (buffer) |
2033 | ;; "Returns a string to represent the given buffer in the Buffer menu. | |
2034 | ;;nil means the buffer shouldn't be listed. You can redefine this." | |
2035 | ;; (if (string-match "\\` " (buffer-name buffer)) | |
2036 | ;; nil | |
7fdbcd83 | 2037 | ;; (with-current-buffer buffer |
a9d96061 SM |
2038 | ;; (let ((size (buffer-size))) |
2039 | ;; (format "%s%s %-19s %6s %-15s %s" | |
2040 | ;; (if (buffer-modified-p) "*" " ") | |
2041 | ;; (if buffer-read-only "%" " ") | |
2042 | ;; (buffer-name) | |
2043 | ;; size | |
2044 | ;; mode-name | |
2045 | ;; (or (buffer-file-name) "")))))) | |
40954111 | 2046 | \f |
25b048ee RS |
2047 | ;;; Set up a menu bar menu for the minibuffer. |
2048 | ||
32993295 SM |
2049 | (dolist (map (list minibuffer-local-map |
2050 | ;; This shouldn't be necessary, but there's a funny | |
2051 | ;; bug in keymap.c that I don't understand yet. -stef | |
d918e2dc | 2052 | minibuffer-local-completion-map)) |
1ec4b7b2 SM |
2053 | (bindings--define-key map [menu-bar minibuf] |
2054 | (cons "Minibuf" (make-sparse-keymap "Minibuf")))) | |
d918e2dc | 2055 | |
32993295 | 2056 | (let ((map minibuffer-local-completion-map)) |
1ec4b7b2 SM |
2057 | (bindings--define-key map [menu-bar minibuf ?\?] |
2058 | '(menu-item "List Completions" minibuffer-completion-help | |
2059 | :help "Display all possible completions")) | |
2060 | (bindings--define-key map [menu-bar minibuf space] | |
2061 | '(menu-item "Complete Word" minibuffer-complete-word | |
2062 | :help "Complete at most one word")) | |
2063 | (bindings--define-key map [menu-bar minibuf tab] | |
2064 | '(menu-item "Complete" minibuffer-complete | |
2065 | :help "Complete as far as possible"))) | |
d918e2dc | 2066 | |
32993295 | 2067 | (let ((map minibuffer-local-map)) |
1ec4b7b2 SM |
2068 | (bindings--define-key map [menu-bar minibuf quit] |
2069 | '(menu-item "Quit" abort-recursive-edit | |
2070 | :help "Abort input and exit minibuffer")) | |
2071 | (bindings--define-key map [menu-bar minibuf return] | |
2072 | '(menu-item "Enter" exit-minibuffer | |
2073 | :key-sequence "\r" | |
2074 | :help "Terminate input and exit minibuffer")) | |
2075 | (bindings--define-key map [menu-bar minibuf isearch-forward] | |
2076 | '(menu-item "Isearch History Forward" isearch-forward | |
2077 | :help "Incrementally search minibuffer history forward")) | |
2078 | (bindings--define-key map [menu-bar minibuf isearch-backward] | |
2079 | '(menu-item "Isearch History Backward" isearch-backward | |
2080 | :help "Incrementally search minibuffer history backward")) | |
2081 | (bindings--define-key map [menu-bar minibuf next] | |
2082 | '(menu-item "Next History Item" next-history-element | |
2083 | :help "Put next minibuffer history element in the minibuffer")) | |
2084 | (bindings--define-key map [menu-bar minibuf previous] | |
2085 | '(menu-item "Previous History Item" previous-history-element | |
2086 | :help "Put previous minibuffer history element in the minibuffer"))) | |
25b048ee | 2087 | \f |
8ab9589d | 2088 | (define-minor-mode menu-bar-mode |
06e21633 CY |
2089 | "Toggle display of a menu bar on each frame (Menu Bar mode). |
2090 | With a prefix argument ARG, enable Menu Bar mode if ARG is | |
2091 | positive, and disable it otherwise. If called from Lisp, enable | |
2092 | Menu Bar mode if ARG is omitted or nil. | |
2093 | ||
057d49d1 | 2094 | This command applies to all frames that exist and frames to be |
06e21633 | 2095 | created in the future." |
6431f2e6 | 2096 | :init-value t |
8ab9589d | 2097 | :global t |
9d794026 GM |
2098 | ;; It's defined in C/cus-start, this stops the d-m-m macro defining it again. |
2099 | :variable menu-bar-mode | |
095fe281 | 2100 | |
6431f2e6 CY |
2101 | ;; Turn the menu-bars on all frames on or off. |
2102 | (let ((val (if menu-bar-mode 1 0))) | |
2103 | (dolist (frame (frame-list)) | |
4ad11f8c CY |
2104 | (set-frame-parameter frame 'menu-bar-lines val)) |
2105 | ;; If the user has given `default-frame-alist' a `menu-bar-lines' | |
2106 | ;; parameter, replace it. | |
2107 | (if (assq 'menu-bar-lines default-frame-alist) | |
2108 | (setq default-frame-alist | |
2109 | (cons (cons 'menu-bar-lines val) | |
2110 | (assq-delete-all 'menu-bar-lines | |
2111 | default-frame-alist))))) | |
8ab9589d JD |
2112 | ;; Make the message appear when Emacs is idle. We can not call message |
2113 | ;; directly. The minor-mode message "Menu-bar mode disabled" comes | |
2114 | ;; after this function returns, overwriting any message we do here. | |
32226619 | 2115 | (when (and (called-interactively-p 'interactive) (not menu-bar-mode)) |
8ab9589d | 2116 | (run-with-idle-timer 0 nil 'message |
4ad11f8c | 2117 | "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear."))) |
1db87953 | 2118 | |
639b9d87 GM |
2119 | ;;;###autoload |
2120 | ;; (This does not work right unless it comes after the above definition.) | |
2121 | ;; This comment is taken from tool-bar.el near | |
2122 | ;; (put 'tool-bar-mode ...) | |
2123 | ;; We want to pretend the menu bar by standard is on, as this will make | |
2124 | ;; customize consider disabling the menu bar a customization, and save | |
2125 | ;; that. We could do this for real by setting :init-value above, but | |
2126 | ;; that would overwrite disabling the menu bar from X resources. | |
2127 | (put 'menu-bar-mode 'standard-value '(t)) | |
2128 | ||
6a5af08f KL |
2129 | (defun toggle-menu-bar-mode-from-frame (&optional arg) |
2130 | "Toggle menu bar on or off, based on the status of the current frame. | |
2131 | See `menu-bar-mode' for more information." | |
2132 | (interactive (list (or current-prefix-arg 'toggle))) | |
2133 | (if (eq arg 'toggle) | |
f68ab99b EZ |
2134 | (menu-bar-mode |
2135 | (if (menu-bar-positive-p | |
2136 | (frame-parameter (menu-bar-frame-for-menubar) 'menu-bar-lines)) | |
2137 | 0 1)) | |
6a5af08f KL |
2138 | (menu-bar-mode arg))) |
2139 | ||
f464330b | 2140 | (declare-function x-menu-bar-open "term/x-win" (&optional frame)) |
1ad31f1b | 2141 | (declare-function w32-menu-bar-open "term/w32-win" (&optional frame)) |
f464330b | 2142 | |
cf3c1e23 SS |
2143 | (defun lookup-key-ignore-too-long (map key) |
2144 | "Call `lookup-key' and convert numeric values to nil." | |
2145 | (let ((binding (lookup-key map key))) | |
2146 | (if (numberp binding) ; `too long' | |
2147 | nil | |
2148 | binding))) | |
2149 | ||
ca343356 | 2150 | (defun popup-menu (menu &optional position prefix from-menu-bar) |
e11a3bd1 EZ |
2151 | "Popup the given menu and call the selected option. |
2152 | MENU can be a keymap, an easymenu-style menu or a list of keymaps as for | |
2153 | `x-popup-menu'. | |
2154 | The menu is shown at the place where POSITION specifies. About | |
2155 | the form of POSITION, see `popup-menu-normalize-position'. | |
ca343356 EZ |
2156 | PREFIX is the prefix argument (if any) to pass to the command. |
2157 | FROM-MENU-BAR, if non-nil, means we are dropping one of menu-bar's menus." | |
e11a3bd1 EZ |
2158 | (let* ((map (cond |
2159 | ((keymapp menu) menu) | |
2160 | ((and (listp menu) (keymapp (car menu))) menu) | |
2161 | (t (let* ((map (easy-menu-create-menu (car menu) (cdr menu))) | |
2162 | (filter (when (symbolp map) | |
2163 | (plist-get (get map 'menu-prop) :filter)))) | |
2164 | (if filter (funcall filter (symbol-function map)) map))))) | |
4a48e94d EZ |
2165 | (frame (selected-frame)) |
2166 | event cmd) | |
2167 | (if from-menu-bar | |
2168 | (let* ((xy (posn-x-y position)) | |
2169 | (menu-symbol (menu-bar-menu-at-x-y (car xy) (cdr xy)))) | |
2170 | (setq position (list menu-symbol (list frame '(menu-bar) | |
2171 | xy 0)))) | |
2172 | (setq position (popup-menu-normalize-position position))) | |
e11a3bd1 EZ |
2173 | ;; The looping behavior was taken from lmenu's popup-menu-popup |
2174 | (while (and map (setq event | |
2175 | ;; map could be a prefix key, in which case | |
2176 | ;; we need to get its function cell | |
2177 | ;; definition. | |
2178 | (x-popup-menu position (indirect-function map)))) | |
2179 | ;; Strangely x-popup-menu returns a list. | |
2180 | ;; mouse-major-mode-menu was using a weird: | |
2181 | ;; (key-binding (apply 'vector (append '(menu-bar) menu-prefix events))) | |
2182 | (setq cmd | |
4a48e94d EZ |
2183 | (cond |
2184 | ((and from-menu-bar | |
2185 | (consp event) | |
2186 | (numberp (car event)) | |
2187 | (numberp (cdr event))) | |
2188 | (let ((x (car event)) | |
2189 | (y (cdr event)) | |
2190 | menu-symbol) | |
2191 | (setq menu-symbol (menu-bar-menu-at-x-y x y)) | |
2192 | (setq position (list menu-symbol (list frame '(menu-bar) | |
2193 | event 0))) | |
2194 | (setq map | |
5ca114d1 | 2195 | (key-binding (vector 'menu-bar menu-symbol))))) |
4a48e94d EZ |
2196 | ((and (not (keymapp map)) (listp map)) |
2197 | ;; We were given a list of keymaps. Search them all | |
2198 | ;; in sequence until a first binding is found. | |
2199 | (let ((mouse-click (apply 'vector event)) | |
2200 | binding) | |
2201 | (while (and map (null binding)) | |
cf3c1e23 | 2202 | (setq binding (lookup-key-ignore-too-long (car map) mouse-click)) |
4a48e94d | 2203 | (setq map (cdr map))) |
cf3c1e23 | 2204 | binding)) |
4a48e94d | 2205 | (t |
e11a3bd1 | 2206 | ;; We were given a single keymap. |
4a48e94d | 2207 | (lookup-key map (apply 'vector event))))) |
e11a3bd1 EZ |
2208 | ;; Clear out echoing, which perhaps shows a prefix arg. |
2209 | (message "") | |
2210 | ;; Maybe try again but with the submap. | |
2211 | (setq map (if (keymapp cmd) cmd))) | |
2212 | ;; If the user did not cancel by refusing to select, | |
2213 | ;; and if the result is a command, run it. | |
2214 | (when (and (null map) (commandp cmd)) | |
2215 | (setq prefix-arg prefix) | |
2216 | ;; `setup-specified-language-environment', for instance, | |
2217 | ;; expects this to be set from a menu keymap. | |
2218 | (setq last-command-event (car (last event))) | |
2219 | ;; mouse-major-mode-menu was using `command-execute' instead. | |
2220 | (call-interactively cmd)))) | |
2221 | ||
2222 | (defun popup-menu-normalize-position (position) | |
2223 | "Convert the POSITION to the form which `popup-menu' expects internally. | |
2224 | POSITION can an event, a posn- value, a value having | |
2225 | form ((XOFFSET YOFFSET) WINDOW), or nil. | |
2226 | If nil, the current mouse position is used." | |
2227 | (pcase position | |
2228 | ;; nil -> mouse cursor position | |
2229 | (`nil | |
2230 | (let ((mp (mouse-pixel-position))) | |
2231 | (list (list (cadr mp) (cddr mp)) (car mp)))) | |
2232 | ;; Value returned from `event-end' or `posn-at-point'. | |
2233 | ((pred posnp) | |
2234 | (let ((xy (posn-x-y position))) | |
2235 | (list (list (car xy) (cdr xy)) | |
2236 | (posn-window position)))) | |
2237 | ;; Event. | |
2238 | ((pred eventp) | |
2239 | (popup-menu-normalize-position (event-end position))) | |
2240 | (t position))) | |
2241 | ||
029619c8 EZ |
2242 | (defcustom tty-menu-open-use-tmm nil |
2243 | "If non-nil, \\[menu-bar-open] on a TTY will invoke `tmm-menubar'. | |
2244 | ||
2245 | If nil, \\[menu-bar-open] will drop down the menu corresponding to the | |
2246 | first (leftmost) menu-bar item; you can select other items by typing | |
2247 | \\[forward-char], \\[backward-char], \\[right-char] and \\[left-char]." | |
2248 | :type '(choice (const :tag "F10 drops down TTY menus" nil) | |
2249 | (const :tag "F10 invokes tmm-menubar" t)) | |
2250 | :group 'display | |
2251 | :version "24.4") | |
2252 | ||
2253 | (defvar tty-menu--initial-menu-x 1 | |
2254 | "X coordinate of the first menu-bar menu dropped by F10. | |
2255 | ||
2256 | This is meant to be used only for debugging TTY menus.") | |
2257 | ||
2258 | (defun menu-bar-open (&optional frame) | |
2259 | "Start key navigation of the menu bar in FRAME. | |
2260 | ||
2261 | This function decides which method to use to access the menu | |
2262 | depending on FRAME's terminal device. On X displays, it calls | |
2263 | `x-menu-bar-open'; on Windows, `w32-menu-bar-open'; otherwise it | |
2264 | calls either `popup-menu' or `tmm-menubar' depending on whether | |
2265 | \`tty-menu-open-use-tmm' is nil or not. | |
2266 | ||
2267 | If FRAME is nil or not given, use the selected frame." | |
2268 | (interactive) | |
2269 | (let ((type (framep (or frame (selected-frame))))) | |
2270 | (cond | |
2271 | ((eq type 'x) (x-menu-bar-open frame)) | |
2272 | ((eq type 'w32) (w32-menu-bar-open frame)) | |
2273 | ((and (null tty-menu-open-use-tmm) | |
2274 | (not (zerop (or (frame-parameter nil 'menu-bar-lines) 0)))) | |
33590869 EZ |
2275 | ;; Make sure the menu bar is up to date. One situation where |
2276 | ;; this is important is when this function is invoked by name | |
2277 | ;; via M-x, in which case the menu bar includes the "Minibuf" | |
2278 | ;; menu item that should be removed when we exit the minibuffer. | |
2279 | (force-mode-line-update) | |
0016fa11 | 2280 | (redisplay) |
029619c8 EZ |
2281 | (let* ((x tty-menu--initial-menu-x) |
2282 | (menu (menu-bar-menu-at-x-y x 0 frame))) | |
2283 | (popup-menu (or | |
cf3c1e23 SS |
2284 | (lookup-key-ignore-too-long |
2285 | global-map (vector 'menu-bar menu)) | |
2286 | (lookup-key-ignore-too-long | |
2287 | (current-local-map) (vector 'menu-bar menu)) | |
f72552bd | 2288 | (cdar (minor-mode-key-binding (vector 'menu-bar menu)))) |
029619c8 EZ |
2289 | (posn-at-x-y x 0 nil t) nil t))) |
2290 | (t (with-selected-frame (or frame (selected-frame)) | |
2291 | (tmm-menubar)))))) | |
2292 | ||
2293 | (global-set-key [f10] 'menu-bar-open) | |
2294 | ||
df782309 EZ |
2295 | (defvar tty-menu-navigation-map |
2296 | (let ((map (make-sparse-keymap))) | |
cee18f1f EZ |
2297 | ;; The next line is disabled because it breaks interpretation of |
2298 | ;; escape sequences, produced by TTY arrow keys, as tty-menu-* | |
2299 | ;; commands. Instead, we explicitly bind some keys to | |
2300 | ;; tty-menu-exit. | |
2301 | ;;(define-key map [t] 'tty-menu-exit) | |
2302 | ||
df782309 EZ |
2303 | ;; The tty-menu-* are just symbols interpreted by term.c, they are |
2304 | ;; not real commands. | |
20832de0 SM |
2305 | (dolist (bind '((keyboard-quit . tty-menu-exit) |
2306 | (keyboard-escape-quit . tty-menu-exit) | |
2307 | ;; The following two will need to be revised if we ever | |
2308 | ;; support a right-to-left menu bar. | |
2309 | (forward-char . tty-menu-next-menu) | |
2310 | (backward-char . tty-menu-prev-menu) | |
2311 | (right-char . tty-menu-next-menu) | |
2312 | (left-char . tty-menu-prev-menu) | |
2313 | (next-line . tty-menu-next-item) | |
2314 | (previous-line . tty-menu-prev-item) | |
2315 | (newline . tty-menu-select) | |
029619c8 EZ |
2316 | (newline-and-indent . tty-menu-select) |
2317 | (menu-bar-open . tty-menu-exit))) | |
20832de0 SM |
2318 | (substitute-key-definition (car bind) (cdr bind) |
2319 | map (current-global-map))) | |
2320 | ||
72b70f6a EZ |
2321 | ;; The bindings of menu-bar items are so that clicking on the menu |
2322 | ;; bar when a menu is already shown pops down that menu. | |
f747170f | 2323 | (define-key map [menu-bar t] 'tty-menu-exit) |
20832de0 | 2324 | |
df782309 EZ |
2325 | (define-key map [?\C-r] 'tty-menu-select) |
2326 | (define-key map [?\C-j] 'tty-menu-select) | |
2327 | (define-key map [return] 'tty-menu-select) | |
2328 | (define-key map [linefeed] 'tty-menu-select) | |
58ce0cfc | 2329 | (define-key map [mouse-1] 'tty-menu-select) |
df782309 | 2330 | (define-key map [drag-mouse-1] 'tty-menu-select) |
58ce0cfc EZ |
2331 | (define-key map [mouse-2] 'tty-menu-select) |
2332 | (define-key map [drag-mouse-2] 'tty-menu-select) | |
2333 | (define-key map [mouse-3] 'tty-menu-select) | |
2334 | (define-key map [drag-mouse-3] 'tty-menu-select) | |
6456c0ea EZ |
2335 | (define-key map [wheel-down] 'tty-menu-next-item) |
2336 | (define-key map [wheel-up] 'tty-menu-prev-item) | |
2337 | (define-key map [wheel-left] 'tty-menu-prev-menu) | |
2338 | (define-key map [wheel-right] 'tty-menu-next-menu) | |
ccd4a783 EZ |
2339 | ;; The following 4 bindings are for those whose text-mode mouse |
2340 | ;; lack the wheel. | |
58ce0cfc | 2341 | (define-key map [S-mouse-1] 'tty-menu-next-item) |
ccd4a783 | 2342 | (define-key map [S-drag-mouse-1] 'tty-menu-next-item) |
58ce0cfc | 2343 | (define-key map [S-mouse-2] 'tty-menu-prev-item) |
ccd4a783 | 2344 | (define-key map [S-drag-mouse-2] 'tty-menu-prev-item) |
58ce0cfc EZ |
2345 | (define-key map [S-mouse-3] 'tty-menu-prev-item) |
2346 | (define-key map [S-drag-mouse-3] 'tty-menu-prev-item) | |
df782309 EZ |
2347 | (define-key map [header-line mouse-1] 'tty-menu-select) |
2348 | (define-key map [header-line drag-mouse-1] 'tty-menu-select) | |
58ce0cfc EZ |
2349 | ;; The down-mouse events must be bound to tty-menu-ignore, so that |
2350 | ;; only releasing the mouse button pops up the menu. | |
2351 | (define-key map [mode-line down-mouse-1] 'tty-menu-ignore) | |
2352 | (define-key map [mode-line down-mouse-2] 'tty-menu-ignore) | |
2353 | (define-key map [mode-line down-mouse-3] 'tty-menu-ignore) | |
2354 | (define-key map [mode-line C-down-mouse-1] 'tty-menu-ignore) | |
2355 | (define-key map [mode-line C-down-mouse-2] 'tty-menu-ignore) | |
2356 | (define-key map [mode-line C-down-mouse-3] 'tty-menu-ignore) | |
2357 | (define-key map [down-mouse-1] 'tty-menu-ignore) | |
2358 | (define-key map [C-down-mouse-1] 'tty-menu-ignore) | |
2359 | (define-key map [C-down-mouse-2] 'tty-menu-ignore) | |
2360 | (define-key map [C-down-mouse-3] 'tty-menu-ignore) | |
e648f699 | 2361 | (define-key map [mouse-movement] 'tty-menu-mouse-movement) |
df782309 EZ |
2362 | map) |
2363 | "Keymap used while processing TTY menus.") | |
2364 | ||
bffa5d4d RS |
2365 | (provide 'menu-bar) |
2366 | ||
235aa29b | 2367 | ;;; menu-bar.el ends here |