Mercurial > hg > xemacs-beta
comparison lisp/utils/easymenu.el @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | ac2d302a0011 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
1 ;;; easymenu.el - Easy menu support for Emacs 19 and XEmacs. | |
2 ;; | |
3 ;; $Id: easymenu.el,v 1.1.1.1 1996/12/18 03:32:46 steve Exp $ | |
4 ;; | |
5 ;; LCD Archive Entry: | |
6 ;; easymenu|Per Abrahamsen|abraham@iesd.auc.dk| | |
7 ;; Easy menu support for XEmacs| | |
8 ;; $Date: 1996/12/18 03:32:46 $|$Revision: 1.1.1.1 $|~/misc/easymenu.el.gz| | |
9 | |
10 ;; Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc. | |
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 | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
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 ;; | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with this program; if not, write to the Free Software | |
24 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
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. | |
57 ;; The menu must already exist an be visible on the menu bar. | |
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) | |
147 (set symbol menu) | |
148 (fset symbol (list 'lambda '(e) | |
149 doc | |
150 '(interactive "@e") | |
151 '(run-hooks 'activate-menubar-hook) | |
152 '(setq zmacs-region-stays 't) | |
153 (list 'popup-menu symbol)))) | |
154 | |
155 (fset 'easy-menu-change (symbol-function 'add-menu)) | |
156 | |
157 (defvar easy-menu-all-popups nil) | |
158 ;; This variable hold the easy-menu mode menus of all major and | |
159 ;; minor modes currently in effect. | |
160 (make-variable-buffer-local 'easy-menu-all-popups) | |
161 | |
162 (defun easy-menu-add (menu &optional map) | |
163 "Add MENU to the current menu bar." | |
164 (if easy-menu-all-popups | |
165 (setq easy-menu-all-popups (cons menu easy-menu-all-popups)) | |
166 (setq easy-menu-all-popups (list menu mode-popup-menu))) | |
167 (setq mode-popup-menu menu) | |
168 | |
169 (cond ((null current-menubar) | |
170 ;; Don't add it to a non-existing menubar. | |
171 nil) | |
172 ((assoc (car menu) current-menubar) | |
173 ;; Already present. | |
174 nil) | |
175 ((equal current-menubar '(nil)) | |
176 ;; Set at left if only contains right marker. | |
177 (set-buffer-menubar (list menu nil))) | |
178 (t | |
179 ;; Add at right. | |
180 (set-buffer-menubar (copy-sequence current-menubar)) | |
181 (add-menu nil (car menu) (cdr menu))))) | |
182 | |
183 (defun easy-menu-remove (menu) | |
184 "Remove MENU from the current menu bar." | |
185 (setq easy-menu-all-popups (delq menu easy-menu-all-popups) | |
186 mode-popup-menu (car easy-menu-all-popups)) | |
187 (and current-menubar | |
188 (assoc (car menu) current-menubar) | |
189 (delete-menu-item (list (car menu))))) | |
190 | |
191 (provide 'easymenu) | |
192 | |
193 ;;; easymenu.el ends here |