summaryrefslogtreecommitdiff
path: root/lisp/imenu.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2014-10-20 21:33:44 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2014-10-20 21:33:44 -0400
commite538605e4cbc504a0481b2aad0eaf7b9529294d3 (patch)
tree65765fa6b8847c3040bd98e632dfbb8298449462 /lisp/imenu.el
parenteed18bf1fd1162872e196091ab795a773f277e8e (diff)
downloademacs-e538605e4cbc504a0481b2aad0eaf7b9529294d3.tar.gz
* lisp/imenu.el (imenu--menubar-keymap): New var.
(imenu-add-to-menubar): Set it to remember the keymap we used. (imenu-update-menubar): Use it instead of asking lookup-key.
Diffstat (limited to 'lisp/imenu.el')
-rw-r--r--lisp/imenu.el26
1 files changed, 12 insertions, 14 deletions
diff --git a/lisp/imenu.el b/lisp/imenu.el
index 5bad4c09c44..bad3dd11734 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -936,6 +936,8 @@ The returned value is of the form (INDEX-NAME . INDEX-POSITION)."
(setq result t imenu--index-alist nil)))
result))
+(defvar-local imenu--menubar-keymap nil)
+
;;;###autoload
(defun imenu-add-to-menubar (name)
"Add an `imenu' entry to the menu bar for the current buffer.
@@ -952,8 +954,9 @@ See the command `imenu' for more information."
(let ((newmap (make-sparse-keymap)))
(set-keymap-parent newmap (current-local-map))
(setq imenu--last-menubar-index-alist nil)
+ (setq imenu--menubar-keymap (make-sparse-keymap "Imenu"))
(define-key newmap [menu-bar index]
- `(menu-item ,name ,(make-sparse-keymap "Imenu")))
+ `(menu-item ,name ,imenu--menubar-keymap))
(use-local-map newmap)
(add-hook 'menu-bar-update-hook 'imenu-update-menubar)))
(user-error "The mode `%s' does not support Imenu"
@@ -975,28 +978,23 @@ to `imenu-update-menubar'.")
(defun imenu-update-menubar ()
(when (and (current-local-map)
- (keymapp (lookup-key (current-local-map) [menu-bar index]))
+ imenu--menubar-keymap
(/= (buffer-chars-modified-tick) imenu-menubar-modified-tick))
(setq imenu-menubar-modified-tick (buffer-chars-modified-tick))
(let ((index-alist (imenu--make-index-alist t)))
;; Don't bother updating if the index-alist has not changed
;; since the last time we did it.
(unless (equal index-alist imenu--last-menubar-index-alist)
- (let (menu menu1 old)
- (setq imenu--last-menubar-index-alist index-alist)
- (setq index-alist (imenu--split-submenus index-alist))
- (setq menu (imenu--split-menu index-alist
- (buffer-name)))
- (setq menu1 (imenu--create-keymap (car menu)
+ (setq imenu--last-menubar-index-alist index-alist)
+ (setq index-alist (imenu--split-submenus index-alist))
+ (let* ((menu (imenu--split-menu index-alist
+ (buffer-name)))
+ (menu1 (imenu--create-keymap (car menu)
(cdr (if (< 1 (length (cdr menu)))
menu
(car (cdr menu))))
- 'imenu--menubar-select))
- (setq old (lookup-key (current-local-map) [menu-bar index]))
- ;; This should never happen, but in some odd cases, potentially,
- ;; lookup-key may return a dynamically composed keymap.
- (if (keymapp (cadr old)) (setq old (cadr old)))
- (setcdr old (cdr menu1)))))))
+ 'imenu--menubar-select)))
+ (setcdr imenu--menubar-keymap (cdr menu1)))))))
(defun imenu--menubar-select (item)
"Use Imenu to select the function or variable named in this menu ITEM."