Mercurial > emacs
annotate lisp/emacs-lisp/lmenu.el @ 8954:c910dbca1355
(paths-force): Depend on src/paths.h
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 20 Sep 1994 22:16:26 +0000 |
parents | 5eff9b0c1a43 |
children | f9cba4810d7b |
rev | line source |
---|---|
2232
4f9d60f7de9d
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2231
diff
changeset
|
1 ;;; lmenu.el --- emulate Lucid's menubar support |
4f9d60f7de9d
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2231
diff
changeset
|
2 |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
3 ;; Keywords: emulations |
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
4 |
7298 | 5 ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. |
2231 | 6 |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | |
2232
4f9d60f7de9d
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2231
diff
changeset
|
23 ;;; Code: |
4f9d60f7de9d
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2231
diff
changeset
|
24 |
2231 | 25 |
26 ;; First, emulate the Lucid menubar support in GNU Emacs 19. | |
27 | |
28 ;; Arrange to use current-menubar to set up part of the menu bar. | |
29 | |
7656
d50e5481aae2
(popup-dialog-box): Bind meaning with let.
Richard M. Stallman <rms@gnu.org>
parents:
7655
diff
changeset
|
30 (defvar current-menubar) |
d50e5481aae2
(popup-dialog-box): Bind meaning with let.
Richard M. Stallman <rms@gnu.org>
parents:
7655
diff
changeset
|
31 |
2231 | 32 (setq recompute-lucid-menubar 'recompute-lucid-menubar) |
33 (defun recompute-lucid-menubar () | |
34 (define-key lucid-menubar-map [menu-bar] | |
35 (condition-case nil | |
36 (make-lucid-menu-keymap "menu-bar" current-menubar) | |
37 (error (message "Invalid data in current-menubar moved to lucid-failing-menubar") | |
38 (sit-for 1) | |
39 (setq lucid-failing-menubar current-menubar | |
40 current-menubar nil)))) | |
41 (setq lucid-menu-bar-dirty-flag nil)) | |
42 | |
43 (defvar lucid-menubar-map (make-sparse-keymap)) | |
44 (or (assq 'current-menubar minor-mode-map-alist) | |
45 (setq minor-mode-map-alist | |
46 (cons (cons 'current-menubar lucid-menubar-map) | |
47 minor-mode-map-alist))) | |
48 | |
49 (defun set-menubar-dirty-flag () | |
50 (force-mode-line-update) | |
51 (setq lucid-menu-bar-dirty-flag t)) | |
52 | |
53 (defvar add-menu-item-count 0) | |
54 | |
8868
5eff9b0c1a43
(make-lucid-menu-keymap-disable): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8051
diff
changeset
|
55 ;; This is a variable whose value is always nil. |
5eff9b0c1a43
(make-lucid-menu-keymap-disable): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8051
diff
changeset
|
56 (defvar make-lucid-menu-keymap-disable nil) |
5eff9b0c1a43
(make-lucid-menu-keymap-disable): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8051
diff
changeset
|
57 |
2231 | 58 ;; Return a menu keymap corresponding to a Lucid-style menu list |
59 ;; MENU-ITEMS, and with name MENU-NAME. | |
60 (defun make-lucid-menu-keymap (menu-name menu-items) | |
61 (let ((menu (make-sparse-keymap menu-name))) | |
62 ;; Process items in reverse order, | |
63 ;; since the define-key loop reverses them again. | |
64 (setq menu-items (reverse menu-items)) | |
65 (while menu-items | |
66 (let* ((item (car menu-items)) | |
67 (callback (if (vectorp item) (aref item 1))) | |
7742
2b0419458768
(make-lucid-menu-keymap): Allow any form as the enabler.
Richard M. Stallman <rms@gnu.org>
parents:
7699
diff
changeset
|
68 command name) |
2231 | 69 (cond ((stringp item) |
70 (setq command nil) | |
6445
19bf0e182eda
(make-lucid-menu-keymap): Any row of dashes means blank.
Karl Heuer <kwzh@gnu.org>
parents:
6435
diff
changeset
|
71 (setq name (if (string-match "^-+$" item) "" item))) |
2231 | 72 ((consp item) |
73 (setq command (make-lucid-menu-keymap (car item) (cdr item))) | |
74 (setq name (car item))) | |
75 ((vectorp item) | |
76 (setq command (make-symbol (format "menu-function-%d" | |
77 add-menu-item-count))) | |
78 (setq add-menu-item-count (1+ add-menu-item-count)) | |
8868
5eff9b0c1a43
(make-lucid-menu-keymap-disable): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8051
diff
changeset
|
79 (if (aref item 2) |
5eff9b0c1a43
(make-lucid-menu-keymap-disable): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8051
diff
changeset
|
80 (put command 'menu-enable (aref item 2)) |
5eff9b0c1a43
(make-lucid-menu-keymap-disable): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8051
diff
changeset
|
81 (put command 'menu-enable 'make-lucid-menu-keymap-disable)) |
2231 | 82 (setq name (aref item 0)) |
83 (if (symbolp callback) | |
84 (fset command callback) | |
85 (fset command (list 'lambda () '(interactive) callback))))) | |
5477
2efe469a9c24
(make-lucid-menu-keymap): Allow multiple identical inactive strings.
Richard M. Stallman <rms@gnu.org>
parents:
5461
diff
changeset
|
86 (if (null command) |
2efe469a9c24
(make-lucid-menu-keymap): Allow multiple identical inactive strings.
Richard M. Stallman <rms@gnu.org>
parents:
5461
diff
changeset
|
87 ;; Handle inactive strings specially--allow any number |
2efe469a9c24
(make-lucid-menu-keymap): Allow multiple identical inactive strings.
Richard M. Stallman <rms@gnu.org>
parents:
5461
diff
changeset
|
88 ;; of identical ones. |
2efe469a9c24
(make-lucid-menu-keymap): Allow multiple identical inactive strings.
Richard M. Stallman <rms@gnu.org>
parents:
5461
diff
changeset
|
89 (setcdr menu (cons (list nil name) (cdr menu))) |
2efe469a9c24
(make-lucid-menu-keymap): Allow multiple identical inactive strings.
Richard M. Stallman <rms@gnu.org>
parents:
5461
diff
changeset
|
90 (if name |
2efe469a9c24
(make-lucid-menu-keymap): Allow multiple identical inactive strings.
Richard M. Stallman <rms@gnu.org>
parents:
5461
diff
changeset
|
91 (define-key menu (vector (intern name)) (cons name command))))) |
2231 | 92 (setq menu-items (cdr menu-items))) |
93 menu)) | |
94 | |
95 (defun popup-menu (menu-desc) | |
96 "Pop up the given menu. | |
97 A menu is a list of menu items, strings, and submenus. | |
98 | |
99 The first element of a menu must be a string, which is the name of the | |
100 menu. This is the string that will be displayed in the parent menu, if | |
101 any. For toplevel menus, it is ignored. This string is not displayed | |
102 in the menu itself. | |
103 | |
104 A menu item is a vector of three or four elements: | |
105 | |
106 - the name of the menu item (a string); | |
107 - the `callback' of that item; | |
108 - whether this item is active (selectable); | |
109 - and an optional string to append to the name. | |
110 | |
111 If the `callback' of a menu item is a symbol, then it must name a command. | |
112 It will be invoked with `call-interactively'. If it is a list, then it is | |
113 evaluated with `eval'. | |
114 | |
115 The fourth element of a menu item is a convenient way of adding the name | |
116 of a command's ``argument'' to the menu, like ``Kill Buffer NAME''. | |
117 | |
118 If an element of a menu is a string, then that string will be presented in | |
119 the menu as unselectable text. | |
120 | |
121 If an element of a menu is a string consisting solely of hyphens, then that | |
122 item will be presented as a solid horizontal line. | |
123 | |
124 If an element of a menu is a list, it is treated as a submenu. The name of | |
125 that submenu (the first element in the list) will be used as the name of the | |
126 item representing this menu on the parent. | |
127 | |
128 The syntax, more precisely: | |
129 | |
130 form := <something to pass to `eval'> | |
131 command := <a symbol or string, to pass to `call-interactively'> | |
132 callback := command | form | |
133 active-p := <t or nil, whether this thing is selectable> | |
134 text := <string, non selectable> | |
135 name := <string> | |
136 argument := <string> | |
137 menu-item := '[' name callback active-p [ argument ] ']' | |
138 menu := '(' name [ menu-item | menu | text ]+ ')' | |
139 " | |
140 (let ((menu (make-lucid-menu-keymap (car menu-desc) (cdr menu-desc))) | |
7641
2db2ad2025c4
(popup-menu): Use mouse-pixel-position.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
141 (pos (mouse-pixel-position)) |
7655
9134274acb76
(popup-menu): Bind cmd with let.
Richard M. Stallman <rms@gnu.org>
parents:
7641
diff
changeset
|
142 answer cmd) |
8051
a320525f4d8f
(popup-menu): Allow user to select nothing.
Karl Heuer <kwzh@gnu.org>
parents:
8038
diff
changeset
|
143 (while (and menu |
a320525f4d8f
(popup-menu): Allow user to select nothing.
Karl Heuer <kwzh@gnu.org>
parents:
8038
diff
changeset
|
144 (setq answer (x-popup-menu (list (list (nth 1 pos) |
a320525f4d8f
(popup-menu): Allow user to select nothing.
Karl Heuer <kwzh@gnu.org>
parents:
8038
diff
changeset
|
145 (nthcdr 2 pos)) |
a320525f4d8f
(popup-menu): Allow user to select nothing.
Karl Heuer <kwzh@gnu.org>
parents:
8038
diff
changeset
|
146 (car pos)) |
a320525f4d8f
(popup-menu): Allow user to select nothing.
Karl Heuer <kwzh@gnu.org>
parents:
8038
diff
changeset
|
147 menu))) |
8038
bffab6b07862
(popup-menu): Convert list to same-size vector, not singleton vector.
Karl Heuer <kwzh@gnu.org>
parents:
7742
diff
changeset
|
148 (setq cmd (lookup-key menu (apply 'vector answer))) |
5439
77798fccc85c
(popup-menu): Add loop to handle submenus.
Richard M. Stallman <rms@gnu.org>
parents:
2751
diff
changeset
|
149 (setq menu nil) |
77798fccc85c
(popup-menu): Add loop to handle submenus.
Richard M. Stallman <rms@gnu.org>
parents:
2751
diff
changeset
|
150 (and cmd |
77798fccc85c
(popup-menu): Add loop to handle submenus.
Richard M. Stallman <rms@gnu.org>
parents:
2751
diff
changeset
|
151 (if (keymapp cmd) |
77798fccc85c
(popup-menu): Add loop to handle submenus.
Richard M. Stallman <rms@gnu.org>
parents:
2751
diff
changeset
|
152 (setq menu cmd) |
77798fccc85c
(popup-menu): Add loop to handle submenus.
Richard M. Stallman <rms@gnu.org>
parents:
2751
diff
changeset
|
153 (call-interactively cmd)))))) |
6744
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
154 |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
155 (defun popup-dialog-box (data) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
156 "Pop up a dialog box. |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
157 A dialog box description is a list. |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
158 |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
159 - The first element of the list is a string to display in the dialog box. |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
160 - The rest of the elements are descriptions of the dialog box's buttons. |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
161 Each one is a vector of three elements: |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
162 - The first element is the text of the button. |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
163 - The second element is the `callback'. |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
164 - The third element is t or nil, whether this button is selectable. |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
165 |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
166 If the `callback' of a button is a symbol, then it must name a command. |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
167 It will be invoked with `call-interactively'. If it is a list, then it is |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
168 evaluated with `eval'. |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
169 |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
170 One (and only one) of the buttons may be `nil'. This marker means that all |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
171 following buttons should be flushright instead of flushleft. |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
172 |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
173 The syntax, more precisely: |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
174 |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
175 form := <something to pass to `eval'> |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
176 command := <a symbol or string, to pass to `call-interactively'> |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
177 callback := command | form |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
178 active-p := <t, nil, or a form to evaluate to decide whether this |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
179 button should be selectable> |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
180 name := <string> |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
181 partition := 'nil' |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
182 button := '[' name callback active-p ']' |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
183 dialog := '(' name [ button ]+ [ partition [ button ]+ ] ')'" |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
184 (let ((name (car data)) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
185 (tail (cdr data)) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
186 converted |
7656
d50e5481aae2
(popup-dialog-box): Bind meaning with let.
Richard M. Stallman <rms@gnu.org>
parents:
7655
diff
changeset
|
187 choice meaning) |
6744
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
188 (while tail |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
189 (if (null (car tail)) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
190 (setq converted (cons nil converted)) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
191 (let ((item (aref (car tail) 0)) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
192 (callback (aref (car tail) 1)) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
193 (enable (aref (car tail) 2))) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
194 (setq converted |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
195 (cons (if enable (cons item callback) item) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
196 converted)))) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
197 (setq tail (cdr tail))) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
198 (setq choice (x-popup-dialog t (cons name (nreverse converted)))) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
199 (setq meaning (assq choice converted)) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
200 (if meaning |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
201 (if (symbolp (cdr meaning)) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
202 (call-interactively (cdr meaning)) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
203 (eval (cdr meaning)))))) |
2231 | 204 |
2751
f95808ad4b95
(default-menubar): Make initial value nil.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
205 ;; This is empty because the usual elements of the menu bar |
f95808ad4b95
(default-menubar): Make initial value nil.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
206 ;; are provided by menu-bar.el instead. |
f95808ad4b95
(default-menubar): Make initial value nil.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
207 ;; It would not make sense to duplicate them here. |
f95808ad4b95
(default-menubar): Make initial value nil.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
208 (defconst default-menubar nil) |
2231 | 209 |
210 (defun set-menubar (menubar) | |
211 "Set the default menubar to be menubar." | |
212 (setq-default current-menubar (copy-sequence menubar)) | |
213 (set-menubar-dirty-flag)) | |
214 | |
215 (defun set-buffer-menubar (menubar) | |
216 "Set the buffer-local menubar to be menubar." | |
217 (make-local-variable 'current-menubar) | |
218 (setq current-menubar (copy-sequence menubar)) | |
219 (set-menubar-dirty-flag)) | |
220 | |
221 | |
222 ;;; menu manipulation functions | |
223 | |
224 (defun find-menu-item (menubar item-path-list &optional parent) | |
225 "Searches MENUBAR for item given by ITEM-PATH-LIST. | |
226 Returns (ITEM . PARENT), where PARENT is the immediate parent of | |
227 the item found. | |
228 Signals an error if the item is not found." | |
229 (or parent (setq item-path-list (mapcar 'downcase item-path-list))) | |
230 (if (not (consp menubar)) | |
231 nil | |
232 (let ((rest menubar) | |
233 result) | |
234 (while rest | |
235 (if (and (car rest) | |
236 (equal (car item-path-list) | |
237 (downcase (if (vectorp (car rest)) | |
238 (aref (car rest) 0) | |
239 (if (stringp (car rest)) | |
240 (car rest) | |
241 (car (car rest))))))) | |
242 (setq result (car rest) rest nil) | |
243 (setq rest (cdr rest)))) | |
244 (if (cdr item-path-list) | |
245 (if (consp result) | |
246 (find-menu-item (cdr result) (cdr item-path-list) result) | |
247 (if result | |
248 (signal 'error (list "not a submenu" result)) | |
249 (signal 'error (list "no such submenu" (car item-path-list))))) | |
250 (cons result parent))))) | |
251 | |
252 | |
253 (defun disable-menu-item (path) | |
254 "Make the named menu item be unselectable. | |
255 PATH is a list of strings which identify the position of the menu item in | |
256 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\" | |
257 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the | |
258 menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"." | |
259 (let* ((menubar current-menubar) | |
260 (pair (find-menu-item menubar path)) | |
261 (item (car pair)) | |
262 (menu (cdr pair))) | |
263 (or item | |
264 (signal 'error (list (if menu "No such menu item" "No such menu") | |
265 path))) | |
266 (if (consp item) (error "can't disable menus, only menu items")) | |
267 (aset item 2 nil) | |
268 (set-menubar-dirty-flag) | |
269 item)) | |
270 | |
271 | |
272 (defun enable-menu-item (path) | |
273 "Make the named menu item be selectable. | |
274 PATH is a list of strings which identify the position of the menu item in | |
275 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\" | |
276 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the | |
277 menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"." | |
278 (let* ((menubar current-menubar) | |
279 (pair (find-menu-item menubar path)) | |
280 (item (car pair)) | |
281 (menu (cdr pair))) | |
282 (or item | |
283 (signal 'error (list (if menu "No such menu item" "No such menu") | |
284 path))) | |
285 (if (consp item) (error "%S is a menu, not a menu item" path)) | |
286 (aset item 2 t) | |
287 (set-menubar-dirty-flag) | |
288 item)) | |
289 | |
290 | |
291 (defun add-menu-item-1 (item-p menu-path item-name item-data enabled-p before) | |
292 (if before (setq before (downcase before))) | |
293 (let* ((menubar current-menubar) | |
294 (menu (condition-case () | |
295 (car (find-menu-item menubar menu-path)) | |
296 (error nil))) | |
297 (item (if (listp menu) | |
298 (car (find-menu-item (cdr menu) (list item-name))) | |
299 (signal 'error (list "not a submenu" menu-path))))) | |
300 (or menu | |
301 (let ((rest menu-path) | |
302 (so-far menubar)) | |
303 (while rest | |
304 ;;; (setq menu (car (find-menu-item (cdr so-far) (list (car rest))))) | |
305 (setq menu | |
306 (if (eq so-far menubar) | |
307 (car (find-menu-item so-far (list (car rest)))) | |
308 (car (find-menu-item (cdr so-far) (list (car rest)))))) | |
309 (or menu | |
310 (let ((rest2 so-far)) | |
311 (while (and (cdr rest2) (car (cdr rest2))) | |
312 (setq rest2 (cdr rest2))) | |
313 (setcdr rest2 | |
7699 | 314 (nconc (list (setq menu (list (car rest)))) |
315 (cdr rest2))))) | |
2231 | 316 (setq so-far menu) |
317 (setq rest (cdr rest))))) | |
318 (or menu (setq menu menubar)) | |
319 (if item | |
320 nil ; it's already there | |
321 (if item-p | |
322 (setq item (vector item-name item-data enabled-p)) | |
323 (setq item (cons item-name item-data))) | |
324 ;; if BEFORE is specified, try to add it there. | |
325 (if before | |
326 (setq before (car (find-menu-item menu (list before))))) | |
327 (let ((rest menu) | |
328 (added-before nil)) | |
329 (while rest | |
330 (if (eq before (car (cdr rest))) | |
331 (progn | |
332 (setcdr rest (cons item (cdr rest))) | |
333 (setq rest nil added-before t)) | |
334 (setq rest (cdr rest)))) | |
335 (if (not added-before) | |
336 ;; adding before the first item on the menubar itself is harder | |
337 (if (and (eq menu menubar) (eq before (car menu))) | |
338 (setq menu (cons item menu) | |
339 current-menubar menu) | |
340 ;; otherwise, add the item to the end. | |
341 (nconc menu (list item)))))) | |
342 (if item-p | |
343 (progn | |
344 (aset item 1 item-data) | |
345 (aset item 2 (not (null enabled-p)))) | |
346 (setcar item item-name) | |
347 (setcdr item item-data)) | |
348 (set-menubar-dirty-flag) | |
349 item)) | |
350 | |
351 (defun add-menu-item (menu-path item-name function enabled-p &optional before) | |
352 "Add a menu item to some menu, creating the menu first if necessary. | |
353 If the named item exists already, it is changed. | |
354 MENU-PATH identifies the menu under which the new menu item should be inserted. | |
355 It is a list of strings; for example, (\"File\") names the top-level \"File\" | |
356 menu. (\"File\" \"Foo\") names a hypothetical submenu of \"File\". | |
357 ITEM-NAME is the string naming the menu item to be added. | |
358 FUNCTION is the command to invoke when this menu item is selected. | |
359 If it is a symbol, then it is invoked with `call-interactively', in the same | |
360 way that functions bound to keys are invoked. If it is a list, then the | |
361 list is simply evaluated. | |
362 ENABLED-P controls whether the item is selectable or not. | |
363 BEFORE, if provided, is the name of a menu item before which this item should | |
364 be added, if this item is not on the menu already. If the item is already | |
365 present, it will not be moved." | |
366 (or menu-path (error "must specify a menu path")) | |
367 (or item-name (error "must specify an item name")) | |
368 (add-menu-item-1 t menu-path item-name function enabled-p before)) | |
369 | |
370 | |
371 (defun delete-menu-item (path) | |
372 "Remove the named menu item from the menu hierarchy. | |
373 PATH is a list of strings which identify the position of the menu item in | |
374 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\" | |
375 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the | |
376 menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"." | |
377 (let* ((menubar current-menubar) | |
378 (pair (find-menu-item menubar path)) | |
379 (item (car pair)) | |
380 (menu (or (cdr pair) menubar))) | |
381 (if (not item) | |
382 nil | |
383 ;; the menubar is the only special case, because other menus begin | |
384 ;; with their name. | |
385 (if (eq menu current-menubar) | |
386 (setq current-menubar (delq item menu)) | |
387 (delq item menu)) | |
388 (set-menubar-dirty-flag) | |
389 item))) | |
390 | |
391 | |
392 (defun relabel-menu-item (path new-name) | |
393 "Change the string of the specified menu item. | |
394 PATH is a list of strings which identify the position of the menu item in | |
395 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\" | |
396 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the | |
397 menu item called \"Item\" under the \"Foo\" submenu of \"Menu\". | |
398 NEW-NAME is the string that the menu item will be printed as from now on." | |
399 (or (stringp new-name) | |
400 (setq new-name (signal 'wrong-type-argument (list 'stringp new-name)))) | |
401 (let* ((menubar current-menubar) | |
402 (pair (find-menu-item menubar path)) | |
403 (item (car pair)) | |
404 (menu (cdr pair))) | |
405 (or item | |
406 (signal 'error (list (if menu "No such menu item" "No such menu") | |
407 path))) | |
408 (if (and (consp item) | |
409 (stringp (car item))) | |
410 (setcar item new-name) | |
411 (aset item 0 new-name)) | |
412 (set-menubar-dirty-flag) | |
413 item)) | |
414 | |
415 (defun add-menu (menu-path menu-name menu-items &optional before) | |
416 "Add a menu to the menubar or one of its submenus. | |
417 If the named menu exists already, it is changed. | |
418 MENU-PATH identifies the menu under which the new menu should be inserted. | |
419 It is a list of strings; for example, (\"File\") names the top-level \"File\" | |
420 menu. (\"File\" \"Foo\") names a hypothetical submenu of \"File\". | |
421 If MENU-PATH is nil, then the menu will be added to the menubar itself. | |
422 MENU-NAME is the string naming the menu to be added. | |
423 MENU-ITEMS is a list of menu item descriptions. | |
424 Each menu item should be a vector of three elements: | |
425 - a string, the name of the menu item; | |
426 - a symbol naming a command, or a form to evaluate; | |
7742
2b0419458768
(make-lucid-menu-keymap): Allow any form as the enabler.
Richard M. Stallman <rms@gnu.org>
parents:
7699
diff
changeset
|
427 - and a form whose value determines whether this item is selectable. |
2231 | 428 BEFORE, if provided, is the name of a menu before which this menu should |
429 be added, if this menu is not on its parent already. If the menu is already | |
430 present, it will not be moved." | |
431 (or menu-name (error "must specify a menu name")) | |
432 (or menu-items (error "must specify some menu items")) | |
433 (add-menu-item-1 nil menu-path menu-name menu-items t before)) | |
434 | |
435 | |
436 | |
437 (defvar put-buffer-names-in-file-menu t) | |
438 | |
439 | |
5982
a9f7e018245b
Delete the code to enable menu bars.
Richard M. Stallman <rms@gnu.org>
parents:
5477
diff
changeset
|
440 ;; Don't unconditionally enable menu bars; leave that up to the user. |
a9f7e018245b
Delete the code to enable menu bars.
Richard M. Stallman <rms@gnu.org>
parents:
5477
diff
changeset
|
441 ;;(let ((frames (frame-list))) |
a9f7e018245b
Delete the code to enable menu bars.
Richard M. Stallman <rms@gnu.org>
parents:
5477
diff
changeset
|
442 ;; (while frames |
a9f7e018245b
Delete the code to enable menu bars.
Richard M. Stallman <rms@gnu.org>
parents:
5477
diff
changeset
|
443 ;; (modify-frame-parameters (car frames) '((menu-bar-lines . 1))) |
a9f7e018245b
Delete the code to enable menu bars.
Richard M. Stallman <rms@gnu.org>
parents:
5477
diff
changeset
|
444 ;; (setq frames (cdr frames)))) |
a9f7e018245b
Delete the code to enable menu bars.
Richard M. Stallman <rms@gnu.org>
parents:
5477
diff
changeset
|
445 ;;(or (assq 'menu-bar-lines default-frame-alist) |
a9f7e018245b
Delete the code to enable menu bars.
Richard M. Stallman <rms@gnu.org>
parents:
5477
diff
changeset
|
446 ;; (setq default-frame-alist |
a9f7e018245b
Delete the code to enable menu bars.
Richard M. Stallman <rms@gnu.org>
parents:
5477
diff
changeset
|
447 ;; (cons '(menu-bar-lines . 1) default-frame-alist))) |
2231 | 448 |
449 (set-menubar default-menubar) | |
450 | |
6435
050f711140e0
Provide lmenu, not menubar.
Richard M. Stallman <rms@gnu.org>
parents:
5982
diff
changeset
|
451 (provide 'lmenu) |
2231 | 452 |
2232
4f9d60f7de9d
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2231
diff
changeset
|
453 ;;; lmenu.el ends here |