0
|
1 ;;; easymenu.el - Easy menu support for Emacs 19 and XEmacs.
|
|
2 ;;
|
78
|
3 ;; $Id: easymenu.el,v 1.2 1997/01/03 03:10:33 steve Exp $
|
0
|
4 ;;
|
|
5 ;; LCD Archive Entry:
|
|
6 ;; easymenu|Per Abrahamsen|abraham@iesd.auc.dk|
|
|
7 ;; Easy menu support for XEmacs|
|
78
|
8 ;; $Date: 1997/01/03 03:10:33 $|$Revision: 1.2 $|~/misc/easymenu.el.gz|
|
0
|
9
|
|
10 ;; Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
|
78
|
11
|
|
12 ;; This file is part of XEmacs.
|
|
13
|
|
14 ;; XEmacs is free software; you can redistribute it and/or modify
|
70
|
15 ;; it under the terms of the GNU General Public License as published by
|
0
|
16 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
17 ;; any later version.
|
78
|
18
|
|
19 ;; XEmacs is distributed in the hope that it will be useful,
|
70
|
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22 ;; GNU General Public License for more details.
|
78
|
23
|
0
|
24 ;; You should have received a copy of the GNU General Public License
|
78
|
25 ;; along with XEmacs; if not, write to the Free Software
|
|
26 ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
27 ;; 02111-1307, USA.
|
0
|
28
|
|
29 ;;; Synched up with: Not synched with FSF.
|
|
30 ;;; In RMS's typical lame-ass way, he removed all support for
|
|
31 ;;; what he calls "other Emacs versions" from the version of
|
|
32 ;;; easymenu.el included in FSF. He also incorrectly claims
|
|
33 ;;; himself as the author rather than Per Abrahamsen.
|
|
34
|
|
35 ;; Commentary:
|
|
36 ;;
|
|
37 ;; Easymenu allows you to define menus for both Emacs 19 and XEmacs.
|
|
38 ;;
|
|
39 ;; This file
|
|
40 ;; The advantages of using easymenu are:
|
|
41 ;;
|
|
42 ;; - Easier to use than either the Emacs 19 and XEmacs menu syntax.
|
|
43 ;;
|
|
44 ;; - Common interface for Emacs 18, Emacs 19, and XEmacs.
|
|
45 ;; (The code does nothing when run under Emacs 18).
|
|
46 ;;
|
|
47 ;; The public functions are:
|
|
48 ;;
|
|
49 ;; - Function: easy-menu-define SYMBOL MAPS DOC MENU
|
|
50 ;; SYMBOL is both the name of the variable that holds the menu and
|
|
51 ;; the name of a function that will present a the menu.
|
|
52 ;; MAPS is a list of keymaps where the menu should appear in the menubar.
|
|
53 ;; DOC is the documentation string for the variable.
|
|
54 ;; MENU is an XEmacs style menu description.
|
|
55 ;;
|
|
56 ;; See the documentation for easy-menu-define for details.
|
|
57 ;;
|
|
58 ;; - Function: easy-menu-change PATH NAME ITEMS
|
|
59 ;; Change an existing menu.
|
70
|
60 ;; The menu must already exist and be visible on the menu bar.
|
0
|
61 ;; PATH is a list of strings used for locating the menu on the menu bar.
|
|
62 ;; NAME is the name of the menu.
|
|
63 ;; ITEMS is a list of menu items, as defined in `easy-menu-define'.
|
|
64 ;;
|
|
65 ;; - Function: easy-menu-add MENU [ MAP ]
|
|
66 ;; Add MENU to the current menubar in MAP.
|
|
67 ;;
|
|
68 ;; - Function: easy-menu-remove MENU
|
|
69 ;; Remove MENU from the current menubar.
|
|
70 ;;
|
|
71 ;; Emacs 19 never uses `easy-menu-add' or `easy-menu-remove', menus
|
|
72 ;; automatically appear and disappear when the keymaps specified by
|
|
73 ;; the MAPS argument to `easy-menu-define' are activated.
|
|
74 ;;
|
|
75 ;; XEmacs will bind the map to button3 in each MAPS, but you must
|
|
76 ;; explicitly call `easy-menu-add' and `easy-menu-remove' to add and
|
|
77 ;; remove menus from the menu bar.
|
|
78
|
|
79 ;;; Code:
|
|
80
|
|
81 ;;;###autoload
|
|
82 (defmacro easy-menu-define (symbol maps doc menu)
|
|
83 "Define a menu bar submenu in maps MAPS, according to MENU.
|
|
84 The arguments SYMBOL and DOC are ignored; they are present for
|
|
85 compatibility only. SYMBOL is not evaluated. In other Emacs versions
|
|
86 these arguments may be used as a variable to hold the menu data, and a
|
|
87 doc string for that variable.
|
|
88
|
|
89 The first element of MENU must be a string. It is the menu bar item name.
|
|
90 The rest of the elements are menu items.
|
|
91
|
|
92 A menu item is usually a vector of three elements: [NAME CALLBACK ENABLE]
|
|
93
|
|
94 NAME is a string--the menu item name.
|
|
95
|
|
96 CALLBACK is a command to run when the item is chosen,
|
|
97 or a list to evaluate when the item is chosen.
|
|
98
|
|
99 ENABLE is an expression; the item is enabled for selection
|
|
100 whenever this expression's value is non-nil.
|
|
101
|
|
102 Alternatively, a menu item may have the form:
|
|
103
|
|
104 [ NAME CALLBACK [ KEYWORD ARG ] ... ]
|
|
105
|
|
106 Where KEYWORD is one of the symbol defined below.
|
|
107
|
|
108 :keys KEYS
|
|
109
|
|
110 KEYS is a string; a complex keyboard equivalent to this menu item.
|
|
111
|
|
112 :active ENABLE
|
|
113
|
|
114 ENABLE is an expression; the item is enabled for selection
|
|
115 whenever this expression's value is non-nil.
|
|
116
|
|
117 :suffix NAME
|
|
118
|
|
119 NAME is a string; the name of an argument to CALLBACK.
|
|
120
|
|
121 :style STYLE
|
|
122
|
|
123 STYLE is a symbol describing the type of menu item. The following are
|
|
124 defined:
|
|
125
|
|
126 toggle: A checkbox.
|
|
127 Currently just prepend the name with the string \"Toggle \".
|
|
128 radio: A radio button.
|
|
129 nil: An ordinary menu item.
|
|
130
|
|
131 :selected SELECTED
|
|
132
|
|
133 SELECTED is an expression; the checkbox or radio button is selected
|
|
134 whenever this expression's value is non-nil.
|
|
135 Currently just disable radio buttons, no effect on checkboxes.
|
|
136
|
|
137 A menu item can be a string. Then that string appears in the menu as
|
|
138 unselectable text. A string consisting solely of hyphens is displayed
|
|
139 as a solid horizontal line.
|
|
140
|
|
141 A menu item can be a list. It is treated as a submenu.
|
|
142 The first element should be the submenu name. That's used as the
|
|
143 menu item in the top-level menu. The cdr of the submenu list
|
|
144 is a list of menu items, as above."
|
|
145 (` (progn
|
|
146 (defvar (, symbol) nil (, doc))
|
|
147 (easy-menu-do-define (quote (, symbol)) (, maps) (, doc) (, menu)))))
|
|
148
|
|
149 (defun easy-menu-do-define (symbol maps doc menu)
|
2
|
150 (if (featurep 'menubar)
|
|
151 (progn
|
|
152 (set symbol menu)
|
|
153 (fset symbol (list 'lambda '(e)
|
|
154 doc
|
|
155 '(interactive "@e")
|
|
156 '(run-hooks 'activate-menubar-hook)
|
|
157 '(setq zmacs-region-stays 't)
|
|
158 (list 'popup-menu symbol))))))
|
0
|
159
|
|
160 (fset 'easy-menu-change (symbol-function 'add-menu))
|
|
161
|
2
|
162 ;; This variable hold the easy-menu mode menus of all major and
|
|
163 ;; minor modes currently in effect.
|
0
|
164 (defvar easy-menu-all-popups nil)
|
2
|
165 (make-variable-buffer-local 'easy-menu-all-popups)
|
0
|
166
|
|
167 (defun easy-menu-add (menu &optional map)
|
|
168 "Add MENU to the current menu bar."
|
2
|
169 (if (featurep 'menubar)
|
|
170 (progn
|
|
171 (if easy-menu-all-popups
|
|
172 (setq easy-menu-all-popups (cons menu easy-menu-all-popups))
|
|
173 (setq easy-menu-all-popups (list menu mode-popup-menu)))
|
|
174 (setq mode-popup-menu menu)
|
0
|
175
|
2
|
176 (cond ((null current-menubar)
|
|
177 ;; Don't add it to a non-existing menubar.
|
|
178 nil)
|
|
179 ((assoc (car menu) current-menubar)
|
|
180 ;; Already present.
|
|
181 nil)
|
|
182 ((equal current-menubar '(nil))
|
|
183 ;; Set at left if only contains right marker.
|
|
184 (set-buffer-menubar (list menu nil)))
|
|
185 (t
|
|
186 ;; Add at right.
|
|
187 (set-buffer-menubar (copy-sequence current-menubar))
|
|
188 (add-menu nil (car menu) (cdr menu)))))))
|
0
|
189
|
|
190 (defun easy-menu-remove (menu)
|
|
191 "Remove MENU from the current menu bar."
|
2
|
192 (if (featurep 'menubar)
|
|
193 (progn
|
|
194 (setq easy-menu-all-popups (delq menu easy-menu-all-popups)
|
|
195 mode-popup-menu (car easy-menu-all-popups))
|
|
196 (and current-menubar
|
|
197 (assoc (car menu) current-menubar)
|
|
198 (delete-menu-item (list (car menu)))))))
|
0
|
199
|
|
200 (provide 'easymenu)
|
|
201
|
|
202 ;;; easymenu.el ends here
|