diff options
| author | Stefan Monnier | 2007-07-10 16:35:24 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2007-07-10 16:35:24 +0000 |
| commit | d3883360012de25fbf4654deb0a37a0919ab830a (patch) | |
| tree | b56142f0c4668b444caaac1f6285a3c7dca71bf8 | |
| parent | 813fb3fe82c53a5586bcf4566da7bd3d15a87486 (diff) | |
| download | emacs-d3883360012de25fbf4654deb0a37a0919ab830a.tar.gz emacs-d3883360012de25fbf4654deb0a37a0919ab830a.zip | |
(easy-menu-binding): New function.
(easy-menu-do-define): Use it.
(easy-menu-do-add-item): Inline into easy-menu-add-item and then remove.
| -rw-r--r-- | lisp/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/emacs-lisp/easymenu.el | 40 |
2 files changed, 28 insertions, 16 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ae0f9fe2247..0c85aa3bfcb 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,9 @@ | |||
| 1 | 2007-07-10 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2007-07-10 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * emacs-lisp/easymenu.el (easy-menu-binding): New function. | ||
| 4 | (easy-menu-do-define): Use it. | ||
| 5 | (easy-menu-do-add-item): Inline into easy-menu-add-item and then remove. | ||
| 6 | |||
| 3 | * progmodes/compile.el (compilation-auto-jump-to-first-error) | 7 | * progmodes/compile.el (compilation-auto-jump-to-first-error) |
| 4 | (compilation-auto-jump-to-next): New vars. | 8 | (compilation-auto-jump-to-next): New vars. |
| 5 | (compilation-auto-jump): New function. | 9 | (compilation-auto-jump): New function. |
diff --git a/lisp/emacs-lisp/easymenu.el b/lisp/emacs-lisp/easymenu.el index d1ec5a1fe39..19df1a16a11 100644 --- a/lisp/emacs-lisp/easymenu.el +++ b/lisp/emacs-lisp/easymenu.el | |||
| @@ -152,6 +152,21 @@ A menu item can be a list with the same format as MENU. This is a submenu." | |||
| 152 | ,(if symbol `(defvar ,symbol nil ,doc)) | 152 | ,(if symbol `(defvar ,symbol nil ,doc)) |
| 153 | (easy-menu-do-define (quote ,symbol) ,maps ,doc ,menu))) | 153 | (easy-menu-do-define (quote ,symbol) ,maps ,doc ,menu))) |
| 154 | 154 | ||
| 155 | (defun easy-menu-binding (menu &optional item-name) | ||
| 156 | "Return a binding suitable to pass to `define-key'. | ||
| 157 | This is expected to be bound to a mouse event." | ||
| 158 | ;; Under Emacs this is almost trivial, whereas under XEmacs this may | ||
| 159 | ;; involve defining a function that calls popup-menu. | ||
| 160 | (let ((props (if (symbolp menu) | ||
| 161 | (prog1 (get menu 'menu-prop) | ||
| 162 | (setq menu (symbol-function menu)))))) | ||
| 163 | (cons 'menu-item | ||
| 164 | (cons (or item-name | ||
| 165 | (if (keymapp menu) | ||
| 166 | (keymap-prompt menu)) | ||
| 167 | "") | ||
| 168 | (cons menu props))))) | ||
| 169 | |||
| 155 | ;;;###autoload | 170 | ;;;###autoload |
| 156 | (defun easy-menu-do-define (symbol maps doc menu) | 171 | (defun easy-menu-do-define (symbol maps doc menu) |
| 157 | ;; We can't do anything that might differ between Emacs dialects in | 172 | ;; We can't do anything that might differ between Emacs dialects in |
| @@ -173,15 +188,10 @@ A menu item can be a list with the same format as MENU. This is a submenu." | |||
| 173 | 'identity) | 188 | 'identity) |
| 174 | (symbol-function ,symbol))) | 189 | (symbol-function ,symbol))) |
| 175 | ,symbol))))) | 190 | ,symbol))))) |
| 176 | (mapcar (lambda (map) | 191 | (dolist (map (if (keymapp maps) (list maps) maps)) |
| 177 | (define-key map (vector 'menu-bar (easy-menu-intern (car menu))) | 192 | (define-key map |
| 178 | (cons 'menu-item | 193 | (vector 'menu-bar (easy-menu-intern (car menu))) |
| 179 | (cons (car menu) | 194 | (easy-menu-binding keymap (car menu)))))) |
| 180 | (if (not (symbolp keymap)) | ||
| 181 | (list keymap) | ||
| 182 | (cons (symbol-function keymap) | ||
| 183 | (get keymap 'menu-prop))))))) | ||
| 184 | (if (keymapp maps) (list maps) maps)))) | ||
| 185 | 195 | ||
| 186 | (defun easy-menu-filter-return (menu &optional name) | 196 | (defun easy-menu-filter-return (menu &optional name) |
| 187 | "Convert MENU to the right thing to return from a menu filter. | 197 | "Convert MENU to the right thing to return from a menu filter. |
| @@ -249,10 +259,6 @@ possibly preceded by keyword pairs as described in `easy-menu-define'." | |||
| 249 | (defvar easy-menu-button-prefix | 259 | (defvar easy-menu-button-prefix |
| 250 | '((radio . :radio) (toggle . :toggle))) | 260 | '((radio . :radio) (toggle . :toggle))) |
| 251 | 261 | ||
| 252 | (defun easy-menu-do-add-item (menu item &optional before) | ||
| 253 | (setq item (easy-menu-convert-item item)) | ||
| 254 | (easy-menu-define-key menu (easy-menu-intern (car item)) (cdr item) before)) | ||
| 255 | |||
| 256 | (defvar easy-menu-converted-items-table (make-hash-table :test 'equal)) | 262 | (defvar easy-menu-converted-items-table (make-hash-table :test 'equal)) |
| 257 | 263 | ||
| 258 | (defun easy-menu-convert-item (item) | 264 | (defun easy-menu-convert-item (item) |
| @@ -269,7 +275,7 @@ would always fail because the key is `equal' but not `eq'." | |||
| 269 | (defun easy-menu-convert-item-1 (item) | 275 | (defun easy-menu-convert-item-1 (item) |
| 270 | "Parse an item description and convert it to a menu keymap element. | 276 | "Parse an item description and convert it to a menu keymap element. |
| 271 | ITEM defines an item as in `easy-menu-define'." | 277 | ITEM defines an item as in `easy-menu-define'." |
| 272 | (let (name command label prop remove help) | 278 | (let (name command label prop remove) |
| 273 | (cond | 279 | (cond |
| 274 | ((stringp item) ; An item or separator. | 280 | ((stringp item) ; An item or separator. |
| 275 | (setq label item)) | 281 | (setq label item)) |
| @@ -536,7 +542,8 @@ earlier by `easy-menu-define' or `easy-menu-create-menu'." | |||
| 536 | (setq item (symbol-value item)))) | 542 | (setq item (symbol-value item)))) |
| 537 | ;; Item is a keymap, find the prompt string and use as item name. | 543 | ;; Item is a keymap, find the prompt string and use as item name. |
| 538 | (setq item (cons (keymap-prompt item) item))) | 544 | (setq item (cons (keymap-prompt item) item))) |
| 539 | (easy-menu-do-add-item map item before))) | 545 | (setq item (easy-menu-convert-item item)) |
| 546 | (easy-menu-define-key map (easy-menu-intern (car item)) (cdr item) before))) | ||
| 540 | 547 | ||
| 541 | (defun easy-menu-item-present-p (map path name) | 548 | (defun easy-menu-item-present-p (map path name) |
| 542 | "In submenu of MAP with path PATH, return non-nil iff item NAME is present. | 549 | "In submenu of MAP with path PATH, return non-nil iff item NAME is present. |
| @@ -615,7 +622,8 @@ In some cases we use that to select between the local and global maps." | |||
| 615 | (catch 'found | 622 | (catch 'found |
| 616 | (if (and map (symbolp map) (not (keymapp map))) | 623 | (if (and map (symbolp map) (not (keymapp map))) |
| 617 | (setq map (symbol-value map))) | 624 | (setq map (symbol-value map))) |
| 618 | (let ((maps (if map (list map) (current-active-maps)))) | 625 | (let ((maps (if map (if (keymapp map) (list map) map) |
| 626 | (current-active-maps)))) | ||
| 619 | ;; Look for PATH in each map. | 627 | ;; Look for PATH in each map. |
| 620 | (unless map (push 'menu-bar path)) | 628 | (unless map (push 'menu-bar path)) |
| 621 | (dolist (name path) | 629 | (dolist (name path) |