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