diff options
| author | Karl Heuer | 1994-10-13 23:34:38 +0000 |
|---|---|---|
| committer | Karl Heuer | 1994-10-13 23:34:38 +0000 |
| commit | 67893ba3c11551b867cae34f563fc50cb7d18f83 (patch) | |
| tree | faba736a9bef9f673bc5300f59bf70a3da6e3e4e | |
| parent | 9ee4654da85aa56a896bdcb55acff3e11a508fe8 (diff) | |
| download | emacs-67893ba3c11551b867cae34f563fc50cb7d18f83.tar.gz emacs-67893ba3c11551b867cae34f563fc50cb7d18f83.zip | |
(make-lucid-menu-keymap): Allow Lucid-style keyword-based menu items.
(popup-menu): Update documentation string to describe the new syntax.
| -rw-r--r-- | lisp/emacs-lisp/lmenu.el | 112 |
1 files changed, 81 insertions, 31 deletions
diff --git a/lisp/emacs-lisp/lmenu.el b/lisp/emacs-lisp/lmenu.el index 8c152399a05..eed3fbb662e 100644 --- a/lisp/emacs-lisp/lmenu.el +++ b/lisp/emacs-lisp/lmenu.el | |||
| @@ -63,9 +63,8 @@ | |||
| 63 | ;; since the define-key loop reverses them again. | 63 | ;; since the define-key loop reverses them again. |
| 64 | (setq menu-items (reverse menu-items)) | 64 | (setq menu-items (reverse menu-items)) |
| 65 | (while menu-items | 65 | (while menu-items |
| 66 | (let* ((item (car menu-items)) | 66 | (let ((item (car menu-items)) |
| 67 | (callback (if (vectorp item) (aref item 1))) | 67 | command name callback) |
| 68 | command name) | ||
| 69 | (cond ((stringp item) | 68 | (cond ((stringp item) |
| 70 | (setq command nil) | 69 | (setq command nil) |
| 71 | (setq name (if (string-match "^-+$" item) "" item))) | 70 | (setq name (if (string-match "^-+$" item) "" item))) |
| @@ -74,20 +73,51 @@ | |||
| 74 | (setq name (car item))) | 73 | (setq name (car item))) |
| 75 | ((vectorp item) | 74 | ((vectorp item) |
| 76 | (setq command (make-symbol (format "menu-function-%d" | 75 | (setq command (make-symbol (format "menu-function-%d" |
| 77 | add-menu-item-count))) | 76 | add-menu-item-count)) |
| 78 | (setq add-menu-item-count (1+ add-menu-item-count)) | 77 | add-menu-item-count (1+ add-menu-item-count) |
| 79 | (if (aref item 2) | 78 | name (aref item 0) |
| 80 | (put command 'menu-enable (aref item 2)) | 79 | callback (aref item 1)) |
| 81 | (put command 'menu-enable 'make-lucid-menu-keymap-disable)) | ||
| 82 | (setq name (aref item 0)) | ||
| 83 | (if (symbolp callback) | 80 | (if (symbolp callback) |
| 84 | (fset command callback) | 81 | (fset command callback) |
| 85 | (fset command (list 'lambda () '(interactive) callback))))) | 82 | (fset command (list 'lambda () '(interactive) callback))) |
| 83 | (let ((i 2)) | ||
| 84 | (while (< i (length item)) | ||
| 85 | (cond | ||
| 86 | ((eq (aref item i) ':active) | ||
| 87 | (put command 'menu-enable | ||
| 88 | (or (aref item (1+ i)) | ||
| 89 | 'make-lucid-menu-keymap-disable)) | ||
| 90 | (setq i (+ 2 i))) | ||
| 91 | ((eq (aref item i) ':suffix) | ||
| 92 | ;; unimplemented | ||
| 93 | (setq i (+ 2 i))) | ||
| 94 | ((eq (aref item i) ':keys) | ||
| 95 | ;; unimplemented | ||
| 96 | (setq i (+ 2 i))) | ||
| 97 | ((eq (aref item i) ':style) | ||
| 98 | ;; unimplemented | ||
| 99 | (setq i (+ 2 i))) | ||
| 100 | ((eq (aref item i) ':selected) | ||
| 101 | ;; unimplemented | ||
| 102 | (setq i (+ 2 i))) | ||
| 103 | ((and (symbolp (aref item i)) | ||
| 104 | (= ?: (string-to-char (symbol-name (aref item i))))) | ||
| 105 | (error "Unrecognized menu item keyword: %S" | ||
| 106 | (aref item i))) | ||
| 107 | ((= i 2) | ||
| 108 | ;; old-style format: active-p &optional suffix | ||
| 109 | (put command 'menu-enable | ||
| 110 | (or (aref item i) 'make-lucid-menu-keymap-disable)) | ||
| 111 | ;; suffix is unimplemented | ||
| 112 | (setq i (length item))) | ||
| 113 | (t | ||
| 114 | (error "Unexpected menu item value: %S" | ||
| 115 | (aref item i)))))))) | ||
| 86 | (if (null command) | 116 | (if (null command) |
| 87 | ;; Handle inactive strings specially--allow any number | 117 | ;; Handle inactive strings specially--allow any number |
| 88 | ;; of identical ones. | 118 | ;; of identical ones. |
| 89 | (setcdr menu (cons (list nil name) (cdr menu))) | 119 | (setcdr menu (cons (list nil name) (cdr menu))) |
| 90 | (if name | 120 | (if name |
| 91 | (define-key menu (vector (intern name)) (cons name command))))) | 121 | (define-key menu (vector (intern name)) (cons name command))))) |
| 92 | (setq menu-items (cdr menu-items))) | 122 | (setq menu-items (cdr menu-items))) |
| 93 | menu)) | 123 | menu)) |
| @@ -101,20 +131,33 @@ menu. This is the string that will be displayed in the parent menu, if | |||
| 101 | any. For toplevel menus, it is ignored. This string is not displayed | 131 | any. For toplevel menus, it is ignored. This string is not displayed |
| 102 | in the menu itself. | 132 | in the menu itself. |
| 103 | 133 | ||
| 104 | A menu item is a vector of three or four elements: | 134 | A menu item is a vector containing: |
| 105 | 135 | ||
| 106 | - the name of the menu item (a string); | 136 | - the name of the menu item (a string); |
| 107 | - the `callback' of that item; | 137 | - the `callback' of that item; |
| 108 | - whether this item is active (selectable); | 138 | - a list of keywords with associated values: |
| 109 | - and an optional string to append to the name. | 139 | - :active active-p a form specifying whether this item is selectable; |
| 140 | - :suffix suffix a string to be appended to the name as an `argument' | ||
| 141 | to the command, like `Kill Buffer NAME'; | ||
| 142 | - :keys command-keys a string, suitable for `substitute-command-keys', | ||
| 143 | to specify the keyboard equivalent of a command | ||
| 144 | when the callback is a form (this is not necessary | ||
| 145 | when the callback is a symbol, as the keyboard | ||
| 146 | equivalent is computed automatically in that case); | ||
| 147 | - :style style a symbol: nil for a normal menu item, `toggle' for | ||
| 148 | a toggle button (a single option that can be turned | ||
| 149 | on or off), or `radio' for a radio button (one of a | ||
| 150 | group of mutually exclusive options); | ||
| 151 | - :selected form for `toggle' or `radio' style, a form that specifies | ||
| 152 | whether the button will be in the selected state. | ||
| 153 | |||
| 154 | Alternately, the vector may contain exactly 3 or 4 elements, with the third | ||
| 155 | element specifying `active-p' and the fourth specifying `suffix'. | ||
| 110 | 156 | ||
| 111 | If the `callback' of a menu item is a symbol, then it must name a command. | 157 | If the `callback' of a menu item is a symbol, then it must name a command. |
| 112 | It will be invoked with `call-interactively'. If it is a list, then it is | 158 | It will be invoked with `call-interactively'. If it is a list, then it is |
| 113 | evaluated with `eval'. | 159 | evaluated with `eval'. |
| 114 | 160 | ||
| 115 | The fourth element of a menu item is a convenient way of adding the name | ||
| 116 | of a command's ``argument'' to the menu, like ``Kill Buffer NAME''. | ||
| 117 | |||
| 118 | If an element of a menu is a string, then that string will be presented in | 161 | If an element of a menu is a string, then that string will be presented in |
| 119 | the menu as unselectable text. | 162 | the menu as unselectable text. |
| 120 | 163 | ||
| @@ -133,10 +176,17 @@ The syntax, more precisely: | |||
| 133 | active-p := <t or nil, whether this thing is selectable> | 176 | active-p := <t or nil, whether this thing is selectable> |
| 134 | text := <string, non selectable> | 177 | text := <string, non selectable> |
| 135 | name := <string> | 178 | name := <string> |
| 136 | argument := <string> | 179 | suffix := <string> |
| 137 | menu-item := '[' name callback active-p [ argument ] ']' | 180 | command-keys := <string> |
| 138 | menu := '(' name [ menu-item | menu | text ]+ ')' | 181 | object-style := 'nil' | 'toggle' | 'radio' |
| 139 | " | 182 | keyword := ':active' active-p |
| 183 | | ':suffix' suffix | ||
| 184 | | ':keys' command-keys | ||
| 185 | | ':style' object-style | ||
| 186 | | ':selected' form | ||
| 187 | menu-item := '[' name callback active-p [ suffix ] ']' | ||
| 188 | | '[' name callback [ keyword ]+ ']' | ||
| 189 | menu := '(' name [ menu-item | menu | text ]+ ')'" | ||
| 140 | (let ((menu (make-lucid-menu-keymap (car menu-desc) (cdr menu-desc))) | 190 | (let ((menu (make-lucid-menu-keymap (car menu-desc) (cdr menu-desc))) |
| 141 | (pos (mouse-pixel-position)) | 191 | (pos (mouse-pixel-position)) |
| 142 | answer cmd) | 192 | answer cmd) |
| @@ -202,7 +252,7 @@ The syntax, more precisely: | |||
| 202 | (call-interactively (cdr meaning)) | 252 | (call-interactively (cdr meaning)) |
| 203 | (eval (cdr meaning)))))) | 253 | (eval (cdr meaning)))))) |
| 204 | 254 | ||
| 205 | ;; This is empty because the usual elements of the menu bar | 255 | ;; This is empty because the usual elements of the menu bar |
| 206 | ;; are provided by menu-bar.el instead. | 256 | ;; are provided by menu-bar.el instead. |
| 207 | ;; It would not make sense to duplicate them here. | 257 | ;; It would not make sense to duplicate them here. |
| 208 | (defconst default-menubar nil) | 258 | (defconst default-menubar nil) |
| @@ -252,9 +302,9 @@ Signals an error if the item is not found." | |||
| 252 | 302 | ||
| 253 | (defun disable-menu-item (path) | 303 | (defun disable-menu-item (path) |
| 254 | "Make the named menu item be unselectable. | 304 | "Make the named menu item be unselectable. |
| 255 | PATH is a list of strings which identify the position of the menu item in | 305 | PATH is a list of strings which identify the position of the menu item in |
| 256 | the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\" | 306 | the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\" |
| 257 | under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the | 307 | under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the |
| 258 | menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"." | 308 | menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"." |
| 259 | (let* ((menubar current-menubar) | 309 | (let* ((menubar current-menubar) |
| 260 | (pair (find-menu-item menubar path)) | 310 | (pair (find-menu-item menubar path)) |
| @@ -271,9 +321,9 @@ menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"." | |||
| 271 | 321 | ||
| 272 | (defun enable-menu-item (path) | 322 | (defun enable-menu-item (path) |
| 273 | "Make the named menu item be selectable. | 323 | "Make the named menu item be selectable. |
| 274 | PATH is a list of strings which identify the position of the menu item in | 324 | PATH is a list of strings which identify the position of the menu item in |
| 275 | the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\" | 325 | the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\" |
| 276 | under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the | 326 | under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the |
| 277 | menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"." | 327 | menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"." |
| 278 | (let* ((menubar current-menubar) | 328 | (let* ((menubar current-menubar) |
| 279 | (pair (find-menu-item menubar path)) | 329 | (pair (find-menu-item menubar path)) |
| @@ -357,7 +407,7 @@ MENU-PATH identifies the menu under which the new menu item should be inserted. | |||
| 357 | ITEM-NAME is the string naming the menu item to be added. | 407 | ITEM-NAME is the string naming the menu item to be added. |
| 358 | FUNCTION is the command to invoke when this menu item is selected. | 408 | FUNCTION is the command to invoke when this menu item is selected. |
| 359 | If it is a symbol, then it is invoked with `call-interactively', in the same | 409 | If it is a symbol, then it is invoked with `call-interactively', in the same |
| 360 | way that functions bound to keys are invoked. If it is a list, then the | 410 | way that functions bound to keys are invoked. If it is a list, then the |
| 361 | list is simply evaluated. | 411 | list is simply evaluated. |
| 362 | ENABLED-P controls whether the item is selectable or not. | 412 | ENABLED-P controls whether the item is selectable or not. |
| 363 | BEFORE, if provided, is the name of a menu item before which this item should | 413 | BEFORE, if provided, is the name of a menu item before which this item should |
| @@ -370,9 +420,9 @@ BEFORE, if provided, is the name of a menu item before which this item should | |||
| 370 | 420 | ||
| 371 | (defun delete-menu-item (path) | 421 | (defun delete-menu-item (path) |
| 372 | "Remove the named menu item from the menu hierarchy. | 422 | "Remove the named menu item from the menu hierarchy. |
| 373 | PATH is a list of strings which identify the position of the menu item in | 423 | PATH is a list of strings which identify the position of the menu item in |
| 374 | the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\" | 424 | the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\" |
| 375 | under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the | 425 | under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the |
| 376 | menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"." | 426 | menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"." |
| 377 | (let* ((menubar current-menubar) | 427 | (let* ((menubar current-menubar) |
| 378 | (pair (find-menu-item menubar path)) | 428 | (pair (find-menu-item menubar path)) |
| @@ -391,9 +441,9 @@ menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"." | |||
| 391 | 441 | ||
| 392 | (defun relabel-menu-item (path new-name) | 442 | (defun relabel-menu-item (path new-name) |
| 393 | "Change the string of the specified menu item. | 443 | "Change the string of the specified menu item. |
| 394 | PATH is a list of strings which identify the position of the menu item in | 444 | PATH is a list of strings which identify the position of the menu item in |
| 395 | the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\" | 445 | the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\" |
| 396 | under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the | 446 | under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the |
| 397 | menu item called \"Item\" under the \"Foo\" submenu of \"Menu\". | 447 | menu item called \"Item\" under the \"Foo\" submenu of \"Menu\". |
| 398 | NEW-NAME is the string that the menu item will be printed as from now on." | 448 | NEW-NAME is the string that the menu item will be printed as from now on." |
| 399 | (or (stringp new-name) | 449 | (or (stringp new-name) |