Mercurial > emacs
annotate lisp/emacs-lisp/lmenu.el @ 95392:838b2bca5a6f
*** empty log message ***
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Thu, 29 May 2008 20:05:36 +0000 |
parents | 90a2847062be |
children | b4e36ff621b3 |
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 |
74466 | 3 ;; Copyright (C) 1992, 1993, 1994, 1997, 2001, 2002, 2003, 2004, |
79704 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
14169 | 5 |
31655
8c99980d4906
(popup-menu, popup-menu-internal, popup-menu-popup): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
21878
diff
changeset
|
6 ;; Keywords: emulations obsolete |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2232
diff
changeset
|
7 |
2231 | 8 ;; This file is part of GNU Emacs. |
9 | |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
2231 | 11 ;; it under the terms of the GNU General Public License as published by |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; the Free Software Foundation, either version 3 of the License, or |
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; (at your option) any later version. |
2231 | 14 |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
2231 | 22 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36861
diff
changeset
|
23 ;;; Commentary: |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36861
diff
changeset
|
24 |
2232
4f9d60f7de9d
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2231
diff
changeset
|
25 ;;; Code: |
4f9d60f7de9d
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2231
diff
changeset
|
26 |
2231 | 27 |
28 ;; First, emulate the Lucid menubar support in GNU Emacs 19. | |
29 | |
30 ;; Arrange to use current-menubar to set up part of the menu bar. | |
31 | |
7656
d50e5481aae2
(popup-dialog-box): Bind meaning with let.
Richard M. Stallman <rms@gnu.org>
parents:
7655
diff
changeset
|
32 (defvar current-menubar) |
64808
46d15fb04bc9
(lucid-menubar-map, lucid-failing-menubar)
Richard M. Stallman <rms@gnu.org>
parents:
64751
diff
changeset
|
33 (defvar lucid-menubar-map) |
46d15fb04bc9
(lucid-menubar-map, lucid-failing-menubar)
Richard M. Stallman <rms@gnu.org>
parents:
64751
diff
changeset
|
34 (defvar lucid-failing-menubar) |
7656
d50e5481aae2
(popup-dialog-box): Bind meaning with let.
Richard M. Stallman <rms@gnu.org>
parents:
7655
diff
changeset
|
35 |
64808
46d15fb04bc9
(lucid-menubar-map, lucid-failing-menubar)
Richard M. Stallman <rms@gnu.org>
parents:
64751
diff
changeset
|
36 (defvar recompute-lucid-menubar 'recompute-lucid-menubar) |
2231 | 37 (defun recompute-lucid-menubar () |
38 (define-key lucid-menubar-map [menu-bar] | |
39 (condition-case nil | |
40 (make-lucid-menu-keymap "menu-bar" current-menubar) | |
41 (error (message "Invalid data in current-menubar moved to lucid-failing-menubar") | |
42 (sit-for 1) | |
43 (setq lucid-failing-menubar current-menubar | |
44 current-menubar nil)))) | |
45 (setq lucid-menu-bar-dirty-flag nil)) | |
46 | |
47 (defvar lucid-menubar-map (make-sparse-keymap)) | |
48 (or (assq 'current-menubar minor-mode-map-alist) | |
49 (setq minor-mode-map-alist | |
50 (cons (cons 'current-menubar lucid-menubar-map) | |
51 minor-mode-map-alist))) | |
52 | |
31655
8c99980d4906
(popup-menu, popup-menu-internal, popup-menu-popup): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
21878
diff
changeset
|
53 ;; XEmacs compatibility |
2231 | 54 (defun set-menubar-dirty-flag () |
55 (force-mode-line-update) | |
56 (setq lucid-menu-bar-dirty-flag t)) | |
57 | |
58 (defvar add-menu-item-count 0) | |
59 | |
8868
5eff9b0c1a43
(make-lucid-menu-keymap-disable): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8051
diff
changeset
|
60 ;; 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
|
61 (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
|
62 |
2231 | 63 ;; Return a menu keymap corresponding to a Lucid-style menu list |
64 ;; MENU-ITEMS, and with name MENU-NAME. | |
65 (defun make-lucid-menu-keymap (menu-name menu-items) | |
66 (let ((menu (make-sparse-keymap menu-name))) | |
67 ;; Process items in reverse order, | |
68 ;; since the define-key loop reverses them again. | |
69 (setq menu-items (reverse menu-items)) | |
70 (while menu-items | |
9523
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
71 (let ((item (car menu-items)) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
72 command name callback) |
2231 | 73 (cond ((stringp item) |
74 (setq command nil) | |
6445
19bf0e182eda
(make-lucid-menu-keymap): Any row of dashes means blank.
Karl Heuer <kwzh@gnu.org>
parents:
6435
diff
changeset
|
75 (setq name (if (string-match "^-+$" item) "" item))) |
2231 | 76 ((consp item) |
77 (setq command (make-lucid-menu-keymap (car item) (cdr item))) | |
78 (setq name (car item))) | |
79 ((vectorp item) | |
80 (setq command (make-symbol (format "menu-function-%d" | |
9523
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
81 add-menu-item-count)) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
82 add-menu-item-count (1+ add-menu-item-count) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
83 name (aref item 0) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
84 callback (aref item 1)) |
2231 | 85 (if (symbolp callback) |
86 (fset command callback) | |
9523
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
87 (fset command (list 'lambda () '(interactive) callback))) |
15430
760c7139c19c
(make-lucid-menu-keymap): Add menu-alias property.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
88 (put command 'menu-alias t) |
9523
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
89 (let ((i 2)) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
90 (while (< i (length item)) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
91 (cond |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
92 ((eq (aref item i) ':active) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
93 (put command 'menu-enable |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
94 (or (aref item (1+ i)) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
95 'make-lucid-menu-keymap-disable)) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
96 (setq i (+ 2 i))) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
97 ((eq (aref item i) ':suffix) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
98 ;; unimplemented |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
99 (setq i (+ 2 i))) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
100 ((eq (aref item i) ':keys) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
101 ;; unimplemented |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
102 (setq i (+ 2 i))) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
103 ((eq (aref item i) ':style) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
104 ;; unimplemented |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
105 (setq i (+ 2 i))) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
106 ((eq (aref item i) ':selected) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
107 ;; unimplemented |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
108 (setq i (+ 2 i))) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
109 ((and (symbolp (aref item i)) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
110 (= ?: (string-to-char (symbol-name (aref item i))))) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
111 (error "Unrecognized menu item keyword: %S" |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
112 (aref item i))) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
113 ((= i 2) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
114 ;; old-style format: active-p &optional suffix |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
115 (put command 'menu-enable |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
116 (or (aref item i) 'make-lucid-menu-keymap-disable)) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
117 ;; suffix is unimplemented |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
118 (setq i (length item))) |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
119 (t |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
120 (error "Unexpected menu item value: %S" |
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
121 (aref item i)))))))) |
5477
2efe469a9c24
(make-lucid-menu-keymap): Allow multiple identical inactive strings.
Richard M. Stallman <rms@gnu.org>
parents:
5461
diff
changeset
|
122 (if (null command) |
2efe469a9c24
(make-lucid-menu-keymap): Allow multiple identical inactive strings.
Richard M. Stallman <rms@gnu.org>
parents:
5461
diff
changeset
|
123 ;; 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
|
124 ;; of identical ones. |
2efe469a9c24
(make-lucid-menu-keymap): Allow multiple identical inactive strings.
Richard M. Stallman <rms@gnu.org>
parents:
5461
diff
changeset
|
125 (setcdr menu (cons (list nil name) (cdr menu))) |
9523
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
126 (if name |
5477
2efe469a9c24
(make-lucid-menu-keymap): Allow multiple identical inactive strings.
Richard M. Stallman <rms@gnu.org>
parents:
5461
diff
changeset
|
127 (define-key menu (vector (intern name)) (cons name command))))) |
2231 | 128 (setq menu-items (cdr menu-items))) |
129 menu)) | |
130 | |
31655
8c99980d4906
(popup-menu, popup-menu-internal, popup-menu-popup): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
21878
diff
changeset
|
131 ;; XEmacs compatibility function |
6744
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
132 (defun popup-dialog-box (data) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
133 "Pop up a dialog box. |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
134 A dialog box description is a list. |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
135 |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
136 - 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
|
137 - 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
|
138 Each one is a vector of three elements: |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
139 - 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
|
140 - The second element is the `callback'. |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
141 - 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
|
142 |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
143 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
|
144 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
|
145 evaluated with `eval'. |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
146 |
50867
720bc3a67aa8
(popup-dialog-box): Don't quote nil and t in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
38414
diff
changeset
|
147 One (and only one) of the buttons may be nil. This marker means that all |
6744
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
148 following buttons should be flushright instead of flushleft. |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
149 |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
150 The syntax, more precisely: |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
151 |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
152 form := <something to pass to `eval'> |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
153 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
|
154 callback := command | form |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
155 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
|
156 button should be selectable> |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
157 name := <string> |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
158 partition := 'nil' |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
159 button := '[' name callback active-p ']' |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
160 dialog := '(' name [ button ]+ [ partition [ button ]+ ] ')'" |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
161 (let ((name (car data)) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
162 (tail (cdr data)) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
163 converted |
7656
d50e5481aae2
(popup-dialog-box): Bind meaning with let.
Richard M. Stallman <rms@gnu.org>
parents:
7655
diff
changeset
|
164 choice meaning) |
6744
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
165 (while tail |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
166 (if (null (car tail)) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
167 (setq converted (cons nil converted)) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
168 (let ((item (aref (car tail) 0)) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
169 (callback (aref (car tail) 1)) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
170 (enable (aref (car tail) 2))) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
171 (setq converted |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
172 (cons (if enable (cons item callback) item) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
173 converted)))) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
174 (setq tail (cdr tail))) |
67485a72803d
(popup-dialog-box): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6445
diff
changeset
|
175 (setq choice (x-popup-dialog t (cons name (nreverse converted)))) |
11765
3bc36769004f
(popup-dialog-box): x-popup-dialog returns the value, not the cons cell.
Richard M. Stallman <rms@gnu.org>
parents:
10954
diff
changeset
|
176 (if choice |
3bc36769004f
(popup-dialog-box): x-popup-dialog returns the value, not the cons cell.
Richard M. Stallman <rms@gnu.org>
parents:
10954
diff
changeset
|
177 (if (symbolp choice) |
3bc36769004f
(popup-dialog-box): x-popup-dialog returns the value, not the cons cell.
Richard M. Stallman <rms@gnu.org>
parents:
10954
diff
changeset
|
178 (call-interactively choice) |
3bc36769004f
(popup-dialog-box): x-popup-dialog returns the value, not the cons cell.
Richard M. Stallman <rms@gnu.org>
parents:
10954
diff
changeset
|
179 (eval choice))))) |
2231 | 180 |
9523
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
181 ;; This is empty because the usual elements of the menu bar |
2751
f95808ad4b95
(default-menubar): Make initial value nil.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
182 ;; are provided by menu-bar.el instead. |
f95808ad4b95
(default-menubar): Make initial value nil.
Richard M. Stallman <rms@gnu.org>
parents:
2233
diff
changeset
|
183 ;; 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
|
184 (defconst default-menubar nil) |
2231 | 185 |
31655
8c99980d4906
(popup-menu, popup-menu-internal, popup-menu-popup): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
21878
diff
changeset
|
186 ;; XEmacs compatibility |
2231 | 187 (defun set-menubar (menubar) |
188 "Set the default menubar to be menubar." | |
189 (setq-default current-menubar (copy-sequence menubar)) | |
190 (set-menubar-dirty-flag)) | |
191 | |
31655
8c99980d4906
(popup-menu, popup-menu-internal, popup-menu-popup): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
21878
diff
changeset
|
192 ;; XEmacs compatibility |
2231 | 193 (defun set-buffer-menubar (menubar) |
194 "Set the buffer-local menubar to be menubar." | |
195 (make-local-variable 'current-menubar) | |
196 (setq current-menubar (copy-sequence menubar)) | |
197 (set-menubar-dirty-flag)) | |
198 | |
199 | |
200 ;;; menu manipulation functions | |
201 | |
31655
8c99980d4906
(popup-menu, popup-menu-internal, popup-menu-popup): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
21878
diff
changeset
|
202 ;; XEmacs compatibility |
2231 | 203 (defun find-menu-item (menubar item-path-list &optional parent) |
204 "Searches MENUBAR for item given by ITEM-PATH-LIST. | |
205 Returns (ITEM . PARENT), where PARENT is the immediate parent of | |
206 the item found. | |
207 Signals an error if the item is not found." | |
208 (or parent (setq item-path-list (mapcar 'downcase item-path-list))) | |
209 (if (not (consp menubar)) | |
210 nil | |
211 (let ((rest menubar) | |
212 result) | |
213 (while rest | |
214 (if (and (car rest) | |
215 (equal (car item-path-list) | |
216 (downcase (if (vectorp (car rest)) | |
217 (aref (car rest) 0) | |
218 (if (stringp (car rest)) | |
219 (car rest) | |
220 (car (car rest))))))) | |
221 (setq result (car rest) rest nil) | |
222 (setq rest (cdr rest)))) | |
223 (if (cdr item-path-list) | |
224 (if (consp result) | |
225 (find-menu-item (cdr result) (cdr item-path-list) result) | |
226 (if result | |
227 (signal 'error (list "not a submenu" result)) | |
228 (signal 'error (list "no such submenu" (car item-path-list))))) | |
229 (cons result parent))))) | |
230 | |
231 | |
31655
8c99980d4906
(popup-menu, popup-menu-internal, popup-menu-popup): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
21878
diff
changeset
|
232 ;; XEmacs compatibility |
2231 | 233 (defun disable-menu-item (path) |
234 "Make the named menu item be unselectable. | |
9523
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
235 PATH is a list of strings which identify the position of the menu item in |
2231 | 236 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\" |
9523
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
237 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the |
2231 | 238 menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"." |
239 (let* ((menubar current-menubar) | |
240 (pair (find-menu-item menubar path)) | |
241 (item (car pair)) | |
242 (menu (cdr pair))) | |
243 (or item | |
244 (signal 'error (list (if menu "No such menu item" "No such menu") | |
245 path))) | |
246 (if (consp item) (error "can't disable menus, only menu items")) | |
247 (aset item 2 nil) | |
248 (set-menubar-dirty-flag) | |
249 item)) | |
250 | |
251 | |
31655
8c99980d4906
(popup-menu, popup-menu-internal, popup-menu-popup): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
21878
diff
changeset
|
252 ;; XEmacs compatibility |
2231 | 253 (defun enable-menu-item (path) |
254 "Make the named menu item be selectable. | |
9523
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
255 PATH is a list of strings which identify the position of the menu item in |
2231 | 256 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\" |
9523
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
257 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the |
2231 | 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 "%S is a menu, not a menu item" path)) | |
267 (aset item 2 t) | |
268 (set-menubar-dirty-flag) | |
269 item)) | |
270 | |
271 | |
272 (defun add-menu-item-1 (item-p menu-path item-name item-data enabled-p before) | |
273 (if before (setq before (downcase before))) | |
274 (let* ((menubar current-menubar) | |
275 (menu (condition-case () | |
276 (car (find-menu-item menubar menu-path)) | |
277 (error nil))) | |
278 (item (if (listp menu) | |
279 (car (find-menu-item (cdr menu) (list item-name))) | |
280 (signal 'error (list "not a submenu" menu-path))))) | |
281 (or menu | |
282 (let ((rest menu-path) | |
283 (so-far menubar)) | |
284 (while rest | |
285 ;;; (setq menu (car (find-menu-item (cdr so-far) (list (car rest))))) | |
286 (setq menu | |
287 (if (eq so-far menubar) | |
288 (car (find-menu-item so-far (list (car rest)))) | |
289 (car (find-menu-item (cdr so-far) (list (car rest)))))) | |
290 (or menu | |
291 (let ((rest2 so-far)) | |
10954
d9ab06338f6a
(add-menu-item-1): Better error message if
Richard M. Stallman <rms@gnu.org>
parents:
9523
diff
changeset
|
292 (or rest2 |
d9ab06338f6a
(add-menu-item-1): Better error message if
Richard M. Stallman <rms@gnu.org>
parents:
9523
diff
changeset
|
293 (error "Trying to modify a menu that doesn't exist")) |
2231 | 294 (while (and (cdr rest2) (car (cdr rest2))) |
295 (setq rest2 (cdr rest2))) | |
296 (setcdr rest2 | |
7699 | 297 (nconc (list (setq menu (list (car rest)))) |
298 (cdr rest2))))) | |
2231 | 299 (setq so-far menu) |
300 (setq rest (cdr rest))))) | |
301 (or menu (setq menu menubar)) | |
302 (if item | |
303 nil ; it's already there | |
304 (if item-p | |
305 (setq item (vector item-name item-data enabled-p)) | |
306 (setq item (cons item-name item-data))) | |
307 ;; if BEFORE is specified, try to add it there. | |
308 (if before | |
309 (setq before (car (find-menu-item menu (list before))))) | |
310 (let ((rest menu) | |
311 (added-before nil)) | |
312 (while rest | |
313 (if (eq before (car (cdr rest))) | |
314 (progn | |
315 (setcdr rest (cons item (cdr rest))) | |
316 (setq rest nil added-before t)) | |
317 (setq rest (cdr rest)))) | |
318 (if (not added-before) | |
319 ;; adding before the first item on the menubar itself is harder | |
320 (if (and (eq menu menubar) (eq before (car menu))) | |
321 (setq menu (cons item menu) | |
322 current-menubar menu) | |
323 ;; otherwise, add the item to the end. | |
324 (nconc menu (list item)))))) | |
325 (if item-p | |
326 (progn | |
327 (aset item 1 item-data) | |
328 (aset item 2 (not (null enabled-p)))) | |
329 (setcar item item-name) | |
330 (setcdr item item-data)) | |
331 (set-menubar-dirty-flag) | |
332 item)) | |
333 | |
31655
8c99980d4906
(popup-menu, popup-menu-internal, popup-menu-popup): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
21878
diff
changeset
|
334 ;; XEmacs compatibility |
2231 | 335 (defun add-menu-item (menu-path item-name function enabled-p &optional before) |
336 "Add a menu item to some menu, creating the menu first if necessary. | |
337 If the named item exists already, it is changed. | |
338 MENU-PATH identifies the menu under which the new menu item should be inserted. | |
339 It is a list of strings; for example, (\"File\") names the top-level \"File\" | |
340 menu. (\"File\" \"Foo\") names a hypothetical submenu of \"File\". | |
341 ITEM-NAME is the string naming the menu item to be added. | |
342 FUNCTION is the command to invoke when this menu item is selected. | |
343 If it is a symbol, then it is invoked with `call-interactively', in the same | |
9523
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
344 way that functions bound to keys are invoked. If it is a list, then the |
2231 | 345 list is simply evaluated. |
346 ENABLED-P controls whether the item is selectable or not. | |
347 BEFORE, if provided, is the name of a menu item before which this item should | |
348 be added, if this item is not on the menu already. If the item is already | |
349 present, it will not be moved." | |
350 (or menu-path (error "must specify a menu path")) | |
351 (or item-name (error "must specify an item name")) | |
352 (add-menu-item-1 t menu-path item-name function enabled-p before)) | |
353 | |
354 | |
31655
8c99980d4906
(popup-menu, popup-menu-internal, popup-menu-popup): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
21878
diff
changeset
|
355 ;; XEmacs compatibility |
2231 | 356 (defun delete-menu-item (path) |
357 "Remove the named menu item from the menu hierarchy. | |
9523
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
358 PATH is a list of strings which identify the position of the menu item in |
2231 | 359 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\" |
9523
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
360 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the |
2231 | 361 menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"." |
362 (let* ((menubar current-menubar) | |
363 (pair (find-menu-item menubar path)) | |
364 (item (car pair)) | |
365 (menu (or (cdr pair) menubar))) | |
366 (if (not item) | |
367 nil | |
368 ;; the menubar is the only special case, because other menus begin | |
369 ;; with their name. | |
370 (if (eq menu current-menubar) | |
371 (setq current-menubar (delq item menu)) | |
372 (delq item menu)) | |
373 (set-menubar-dirty-flag) | |
374 item))) | |
375 | |
376 | |
31655
8c99980d4906
(popup-menu, popup-menu-internal, popup-menu-popup): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
21878
diff
changeset
|
377 ;; XEmacs compatibility |
2231 | 378 (defun relabel-menu-item (path new-name) |
379 "Change the string of the specified menu item. | |
9523
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
380 PATH is a list of strings which identify the position of the menu item in |
2231 | 381 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\" |
9523
f9cba4810d7b
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
Karl Heuer <kwzh@gnu.org>
parents:
8868
diff
changeset
|
382 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the |
2231 | 383 menu item called \"Item\" under the \"Foo\" submenu of \"Menu\". |
384 NEW-NAME is the string that the menu item will be printed as from now on." | |
385 (or (stringp new-name) | |
386 (setq new-name (signal 'wrong-type-argument (list 'stringp new-name)))) | |
387 (let* ((menubar current-menubar) | |
388 (pair (find-menu-item menubar path)) | |
389 (item (car pair)) | |
390 (menu (cdr pair))) | |
391 (or item | |
392 (signal 'error (list (if menu "No such menu item" "No such menu") | |
393 path))) | |
394 (if (and (consp item) | |
395 (stringp (car item))) | |
396 (setcar item new-name) | |
397 (aset item 0 new-name)) | |
398 (set-menubar-dirty-flag) | |
399 item)) | |
400 | |
36861
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
401 ;; XEmacs compatibility |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
402 (defun add-menu (menu-path menu-name menu-items &optional before) |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
403 "Add a menu to the menubar or one of its submenus. |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
404 If the named menu exists already, it is changed. |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
405 MENU-PATH identifies the menu under which the new menu should be inserted. |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
406 It is a list of strings; for example, (\"File\") names the top-level \"File\" |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
407 menu. (\"File\" \"Foo\") names a hypothetical submenu of \"File\". |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
408 If MENU-PATH is nil, then the menu will be added to the menubar itself. |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
409 MENU-NAME is the string naming the menu to be added. |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
410 MENU-ITEMS is a list of menu item descriptions. |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
411 Each menu item should be a vector of three elements: |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
412 - a string, the name of the menu item; |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
413 - a symbol naming a command, or a form to evaluate; |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
414 - and a form whose value determines whether this item is selectable. |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
415 BEFORE, if provided, is the name of a menu before which this menu should |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
416 be added, if this menu is not on its parent already. If the menu is already |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
417 present, it will not be moved." |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
418 (or menu-name (error "must specify a menu name")) |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
419 (or menu-items (error "must specify some menu items")) |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
420 (add-menu-item-1 nil menu-path menu-name menu-items t before)) |
79c77eec747f
(add-menu): Re-added (was erroneously removed).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31655
diff
changeset
|
421 |
2231 | 422 |
423 | |
424 (defvar put-buffer-names-in-file-menu t) | |
425 | |
426 | |
5982
a9f7e018245b
Delete the code to enable menu bars.
Richard M. Stallman <rms@gnu.org>
parents:
5477
diff
changeset
|
427 ;; 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
|
428 ;;(let ((frames (frame-list))) |
a9f7e018245b
Delete the code to enable menu bars.
Richard M. Stallman <rms@gnu.org>
parents:
5477
diff
changeset
|
429 ;; (while frames |
a9f7e018245b
Delete the code to enable menu bars.
Richard M. Stallman <rms@gnu.org>
parents:
5477
diff
changeset
|
430 ;; (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
|
431 ;; (setq frames (cdr frames)))) |
a9f7e018245b
Delete the code to enable menu bars.
Richard M. Stallman <rms@gnu.org>
parents:
5477
diff
changeset
|
432 ;;(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
|
433 ;; (setq default-frame-alist |
a9f7e018245b
Delete the code to enable menu bars.
Richard M. Stallman <rms@gnu.org>
parents:
5477
diff
changeset
|
434 ;; (cons '(menu-bar-lines . 1) default-frame-alist))) |
2231 | 435 |
436 (set-menubar default-menubar) | |
437 | |
6435
050f711140e0
Provide lmenu, not menubar.
Richard M. Stallman <rms@gnu.org>
parents:
5982
diff
changeset
|
438 (provide 'lmenu) |
2231 | 439 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79704
diff
changeset
|
440 ;; arch-tag: 7051c396-2837-435a-ae11-b2d2e2af8fc1 |
2232
4f9d60f7de9d
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2231
diff
changeset
|
441 ;;; lmenu.el ends here |