comparison lisp/easymenu.el @ 367:a4f53d9b3154 r21-1-13

Import from CVS: tag r21-1-13
author cvs
date Mon, 13 Aug 2007 11:01:07 +0200
parents 19dcec799385
children cc15677e0335
comparison
equal deleted inserted replaced
366:83d76f480a59 367:a4f53d9b3154
22 ;; along with XEmacs; if not, write to the Free Software 22 ;; along with XEmacs; if not, write to the Free Software
23 ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 23 ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 ;; 02111-1307, USA. 24 ;; 02111-1307, USA.
25 25
26 ;;; Synched up with: Not synched with FSF but coordinated with the FSF 26 ;;; Synched up with: Not synched with FSF but coordinated with the FSF
27 ;;; easymenu maintor for compatability with FSF 20.4. 27 ;;; easymenu maintainer for compatability with FSF 20.4.
28 ;;; Please: Coordinate changes with Inge Frick <inge@nada.kth.se> 28 ;;; Please: Coordinate changes with Inge Frick <inge@nada.kth.se>
29 29
30 ;; Commentary: 30 ;; Commentary:
31 31
32 ;; This file is dumped with XEmacs. 32 ;; This file is dumped with XEmacs.
43 43
44 ;; The public functions are: 44 ;; The public functions are:
45 45
46 ;; - Function: easy-menu-define SYMBOL MAPS DOC MENU 46 ;; - Function: easy-menu-define SYMBOL MAPS DOC MENU
47 ;; SYMBOL is both the name of the variable that holds the menu and 47 ;; SYMBOL is both the name of the variable that holds the menu and
48 ;; the name of a function that will present a the menu. 48 ;; the name of a function that will present the menu.
49 ;; MAPS is a list of keymaps where the menu should appear in the menubar. 49 ;; MAPS is a list of keymaps where the menu should appear in the menubar.
50 ;; DOC is the documentation string for the variable. 50 ;; DOC is the documentation string for the variable.
51 ;; MENU is an XEmacs style menu description. 51 ;; MENU is an XEmacs style menu description.
52 52
53 ;; See the documentation for easy-menu-define for details. 53 ;; See the documentation for easy-menu-define for details.
151 (` (progn 151 (` (progn
152 (defvar (, symbol) nil (, doc)) 152 (defvar (, symbol) nil (, doc))
153 (easy-menu-do-define (quote (, symbol)) (, maps) (, doc) (, menu))))) 153 (easy-menu-do-define (quote (, symbol)) (, maps) (, doc) (, menu)))))
154 154
155 (defun easy-menu-do-define (symbol maps doc menu) 155 (defun easy-menu-do-define (symbol maps doc menu)
156 (if (featurep 'menubar) 156 (when (featurep 'menubar)
157 (progn
158 (set symbol menu) 157 (set symbol menu)
159 (fset symbol (list 'lambda '(e) 158 (fset symbol `(lambda (e)
160 doc 159 ,doc
161 '(interactive "@e") 160 (interactive "@e")
162 '(run-hooks 'activate-menubar-hook) 161 (run-hooks 'activate-menubar-hook)
163 '(setq zmacs-region-stays 't) 162 (setq zmacs-region-stays 't)
164 (list 'popup-menu symbol)))))) 163 (popup-menu ,symbol)))))
165 164
166 (defun easy-menu-change (&rest args) 165 (defun easy-menu-change (&rest args)
167 (when (featurep 'menubar) 166 (when (featurep 'menubar)
168 (apply 'add-menu args))) 167 (apply 'add-menu args)))
169 168
172 (defvar easy-menu-all-popups nil) 171 (defvar easy-menu-all-popups nil)
173 (make-variable-buffer-local 'easy-menu-all-popups) 172 (make-variable-buffer-local 'easy-menu-all-popups)
174 173
175 (defun easy-menu-add (menu &optional map) 174 (defun easy-menu-add (menu &optional map)
176 "Add MENU to the current menu bar." 175 "Add MENU to the current menu bar."
177 (if (featurep 'menubar) 176 (when (featurep 'menubar)
178 (progn
179 (unless (member menu easy-menu-all-popups) 177 (unless (member menu easy-menu-all-popups)
180 (push menu easy-menu-all-popups)) 178 (push menu easy-menu-all-popups))
181 (setq mode-popup-menu (if (> (length easy-menu-all-popups) 1) 179 (setq mode-popup-menu (if (> (length easy-menu-all-popups) 1)
182 (cons (easy-menu-title) 180 (cons (easy-menu-title)
183 (reverse easy-menu-all-popups)) 181 (reverse easy-menu-all-popups))
193 ;; Set at left if only contains right marker. 191 ;; Set at left if only contains right marker.
194 (set-buffer-menubar (list menu nil))) 192 (set-buffer-menubar (list menu nil)))
195 (t 193 (t
196 ;; Add at right. 194 ;; Add at right.
197 (set-buffer-menubar (copy-sequence current-menubar)) 195 (set-buffer-menubar (copy-sequence current-menubar))
198 (add-menu nil (car menu) (cdr menu))))))) 196 (add-menu nil (car menu) (cdr menu))))))
199 197
200 (defun easy-menu-remove (menu) 198 (defun easy-menu-remove (menu)
201 "Remove MENU from the current menu bar." 199 "Remove MENU from the current menu bar."
202 (if (featurep 'menubar) 200 (when (featurep 'menubar)
203 (progn
204 (setq easy-menu-all-popups (delq menu easy-menu-all-popups) 201 (setq easy-menu-all-popups (delq menu easy-menu-all-popups)
205 mode-popup-menu (if (< (length easy-menu-all-popups) 1) 202 mode-popup-menu (if (< (length easy-menu-all-popups) 1)
206 (cons (easy-menu-title) 203 (cons (easy-menu-title)
207 (reverse easy-menu-all-popups)) 204 (reverse easy-menu-all-popups))
208 (car easy-menu-all-popups))) 205 (car easy-menu-all-popups)))
209 206
210 (and current-menubar 207 (and current-menubar
211 (assoc (car menu) current-menubar) 208 (assoc (car menu) current-menubar)
212 (delete-menu-item (list (car menu))))))) 209 (delete-menu-item (list (car menu))))))
213 210
214 (defsubst easy-menu-normalize (menu) 211 (defsubst easy-menu-normalize (menu)
215 (if (symbolp menu) 212 (if (symbolp menu)
216 (symbol-value menu) 213 (symbol-value menu)
217 menu)) 214 menu))
218 215
219 (defun easy-menu-add-item (menu path item &optional before) 216 (defun easy-menu-add-item (menu path item &optional before)
220 "At the end of the submenu of MENU with path PATH add ITEM. 217 "At the end of the submenu of MENU with path PATH, add ITEM.
221 If ITEM is already present in this submenu, then this item will be changed. 218 If ITEM is already present in this submenu, then this item will be changed.
222 otherwise ITEM will be added at the end of the submenu, unless the optional 219 otherwise ITEM will be added at the end of the submenu, unless the optional
223 argument BEFORE is present, in which case ITEM will instead be added 220 argument BEFORE is present, in which case ITEM will instead be added
224 before the item named BEFORE. 221 before the item named BEFORE.
225 MENU is either a symbol, which have earlier been used as the first 222 MENU is either a symbol, which have earlier been used as the first
226 argument in a call to `easy-menu-define', or the value of such a symbol 223 argument in a call to `easy-menu-define', or the value of such a symbol
227 i.e. a menu, or nil which stands for the current menubar. 224 i.e. a menu, or nil, which stands for the current menubar.
228 PATH is a list of strings for locating the submenu where ITEM is to be 225 PATH is a list of strings for locating the submenu where ITEM is to be
229 added. If PATH is nil, MENU itself is used. Otherwise, the first 226 added. If PATH is nil, MENU itself is used. Otherwise, the first
230 element should be the name of a submenu directly under MENU. This 227 element should be the name of a submenu directly under MENU. This
231 submenu is then traversed recursively with the remaining elements of PATH. 228 submenu is then traversed recursively with the remaining elements of PATH.
232 ITEM is either defined as in `easy-menu-define', a menu defined earlier 229 ITEM is either defined as in `easy-menu-define', a menu defined earlier
233 by `easy-menu-define' or `easy-menu-create-menu' or an item returned 230 by `easy-menu-define' or `easy-menu-create-menu' or an item returned
234 from `easy-menu-item-present-p' or `easy-menu-remove-item'." 231 from `easy-menu-item-present-p' or `easy-menu-remove-item'."
235 (add-menu-button path item before (easy-menu-normalize menu))) 232 (when (featurep 'menubar)
233 (add-menu-button path item before (easy-menu-normalize menu))))
236 234
237 (defun easy-menu-item-present-p (menu path name) 235 (defun easy-menu-item-present-p (menu path name)
238 "In submenu of MENU with path PATH, return true iff item NAME is present. 236 "In submenu of MENU with path PATH, return true iff item NAME is present.
239 MENU and PATH are defined as in `easy-menu-add-item'. 237 MENU and PATH are defined as in `easy-menu-add-item'.
240 NAME should be a string, the name of the element to be looked for. 238 NAME should be a string, the name of the element to be looked for.
241 239
242 The return value can be used as as an argument to `easy-menu-add-item'." 240 The return value can be used as an argument to `easy-menu-add-item'."
241 (if (featurep 'menubar)
243 (car (find-menu-item (or (easy-menu-normalize menu) current-menubar) 242 (car (find-menu-item (or (easy-menu-normalize menu) current-menubar)
244 (append path (list name))))) 243 (append path (list name))))
244 nil))
245 245
246 (defun easy-menu-remove-item (menu path name) 246 (defun easy-menu-remove-item (menu path name)
247 "From submenu of MENU with path PATH remove item NAME. 247 "From submenu of MENU with path PATH, remove item NAME.
248 MENU and PATH are defined as in `easy-menu-add-item'. 248 MENU and PATH are defined as in `easy-menu-add-item'.
249 NAME should be a string, the name of the element to be removed. 249 NAME should be a string, the name of the element to be removed.
250 250
251 The return value can be used as as an argument to `easy-menu-add-item'." 251 The return value can be used as an argument to `easy-menu-add-item'."
252 (when (featurep 'menubar)
252 (delete-menu-item (append path (list name)) 253 (delete-menu-item (append path (list name))
253 (easy-menu-normalize menu))) 254 (easy-menu-normalize menu))))
254 255
255 256
256 257
257 258
258 ;; Think up a good title for the menu. Take the major-mode of the 259 ;; Think up a good title for the menu. Take the major-mode of the