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