aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-10-28 04:31:05 +0000
committerRichard M. Stallman1994-10-28 04:31:05 +0000
commit1ba15fe60c8e49c427e338e2f9b986bbb5d531cc (patch)
tree21fea273e71221e997b7a0e5dcf36cefbd408484
parenta9ee7a599213ff0d19986c3003cbccfd360a88a0 (diff)
downloademacs-1ba15fe60c8e49c427e338e2f9b986bbb5d531cc.tar.gz
emacs-1ba15fe60c8e49c427e338e2f9b986bbb5d531cc.zip
(easy-menu-define): Call `easy-menu-do-define' to do
the real work. Document XEmacs keyword arguments. (easy-menu-do-define): New function. (easy-menu-create-keymaps): Support XEmacs keyword arguments in menu definition.
-rw-r--r--lisp/emacs-lisp/easymenu.el100
1 files changed, 88 insertions, 12 deletions
diff --git a/lisp/emacs-lisp/easymenu.el b/lisp/emacs-lisp/easymenu.el
index 000fe289153..5f8e3340a2e 100644
--- a/lisp/emacs-lisp/easymenu.el
+++ b/lisp/emacs-lisp/easymenu.el
@@ -48,6 +48,43 @@ or a list to evaluate when the item is chosen.
48ENABLE is an expression; the item is enabled for selection 48ENABLE is an expression; the item is enabled for selection
49whenever this expression's value is non-nil. 49whenever this expression's value is non-nil.
50 50
51Alternatively, a menu item may have the form:
52
53 [ NAME CALLBACK [ KEYWORD ARG ] ... ]
54
55Where KEYWORD is one of the symbol defined below.
56
57 :keys KEYS
58
59KEYS is a string; a complex keyboard equivalent to this menu item.
60This is normally not needed because keyboard equivalents are usually
61computed automatically.
62
63 :active ENABLE
64
65ENABLE is an expression; the item is enabled for selection
66whenever this expression's value is non-nil.
67
68 :suffix NAME
69
70NAME is a string; the name of an argument to CALLBACK.
71
72 :style
73
74STYLE is a symbol describing the type of menu item. The following are
75defined:
76
77toggle: A checkbox.
78 Currently just prepend the name with the string \"Toggle \".
79radio: A radio button.
80nil: An ordinary menu item.
81
82 :selected SELECTED
83
84SELECTED is an expression; the checkbox or radio button is selected
85whenever this expression's value is non-nil.
86Currently just disable radio buttons, no effect on checkboxes.
87
51A menu item can be a string. Then that string appears in the menu as 88A menu item can be a string. Then that string appears in the menu as
52unselectable text. A string consisting solely of hyphens is displayed 89unselectable text. A string consisting solely of hyphens is displayed
53as a solid horizontal line. 90as a solid horizontal line.
@@ -56,14 +93,22 @@ A menu item can be a list. It is treated as a submenu.
56The first element should be the submenu name. That's used as the 93The first element should be the submenu name. That's used as the
57menu item in the top-level menu. The cdr of the submenu list 94menu item in the top-level menu. The cdr of the submenu list
58is a list of menu items, as above." 95is a list of menu items, as above."
59 (` (let* ((maps (, maps)) 96 (` (progn
60 (menu (, menu)) 97 (defvar (, symbol) nil (, doc))
61 (keymap (easy-menu-create-keymaps (car menu) (cdr menu)))) 98 (easy-menu-do-define (quote (, symbol)) (, maps) (, doc) (, menu)))))
62 (and (keymapp maps) (setq maps (list maps))) 99
63 (while maps 100(defun easy-menu-do-define (symbol maps doc menu)
64 (define-key (car maps) (vector 'menu-bar (intern (car menu))) 101 ;; We can't do anything that might differ between Emacs dialects in
65 (cons (car menu) keymap)) 102 ;; `easy-menu-define' in order to make byte compiled files
66 (setq maps (cdr maps)))))) 103 ;; compatible. Therefore everything interesting is done in this
104 ;; function.
105 (set symbol (easy-menu-create-keymaps (car menu) (cdr menu)))
106 (fset symbol (` (lambda (event) (, doc) (interactive "@e")
107 (easy-popup-menu event (, symbol)))))
108 (mapcar (function (lambda (map)
109 (define-key map (vector 'menu-bar (intern (car menu)))
110 (cons (car menu) (symbol-value symbol)))))
111 (if (keymapp maps) (list maps) maps)))
67 112
68(defvar easy-menu-item-count 0) 113(defvar easy-menu-item-count 0)
69 114
@@ -89,8 +134,39 @@ is a list of menu items, as above."
89 (setq command (make-symbol (format "menu-function-%d" 134 (setq command (make-symbol (format "menu-function-%d"
90 easy-menu-item-count))) 135 easy-menu-item-count)))
91 (setq easy-menu-item-count (1+ easy-menu-item-count)) 136 (setq easy-menu-item-count (1+ easy-menu-item-count))
92 (put command 'menu-enable (aref item 2)) 137 (setq name (aref item 0))
93 (setq name (aref item 0)) 138 (let ((keyword (aref item 2)))
139 (if (and (symbolp keyword)
140 (= ?: (aref (symbol-name keyword) 0)))
141 (let ((count 2)
142 style selected active keys
143 arg)
144 (while (> (length item) count)
145 (setq keyword (aref item count))
146 (setq arg (aref item (1+ count)))
147 (setq count (+ 2 count))
148 (cond ((eq keyword ':keys)
149 (setq keys arg))
150 ((eq keyword ':active)
151 (setq active arg))
152 ((eq keyword ':suffix)
153 (setq name (concat name " " arg)))
154 ((eq keyword ':style)
155 (setq style arg))
156 ((eq keyword ':selected)
157 (setq selected arg))))
158 (if keys
159 (setq name (concat name " (" keys ")")))
160 (if (eq style 'toggle)
161 ;; Simulate checkboxes.
162 (setq name (concat "Toggle " name)))
163 (if active
164 (put command 'menu-enable active)
165 (and (eq style 'radio)
166 selected
167 ;; Simulate radio buttons with menu-enable.
168 (put command 'menu-enable
169 (list 'not selected)))))))
94 (if (keymapp callback) 170 (if (keymapp callback)
95 (setq name (concat name " ..."))) 171 (setq name (concat name " ...")))
96 (if (symbolp callback) 172 (if (symbolp callback)
@@ -119,9 +195,9 @@ Call this from `activate-menubar-hook' to implement dynamic menus."
119 (setcdr map (cdr (easy-menu-create-keymaps name items))) 195 (setcdr map (cdr (easy-menu-create-keymaps name items)))
120 (error "Malformed menu in `easy-menu-change'")))) 196 (error "Malformed menu in `easy-menu-change'"))))
121 197
122(defmacro easy-menu-remove (menu)) 198(defun easy-menu-remove (menu))
123 199
124(defmacro easy-menu-add (menu &optional map)) 200(defun easy-menu-add (menu &optional map))
125 201
126(provide 'easymenu) 202(provide 'easymenu)
127 203