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