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