]> code.delx.au - gnu-emacs/blobdiff - lisp/imenu.el
* doc/emacs/dired.texi (Shell Commands in Dired): Fix typo.
[gnu-emacs] / lisp / imenu.el
index 6be6b85af8aa3a536ae63389b8df60a40be44b9a..8363956355b863396470b39803309730f5e61946 100644 (file)
@@ -1,6 +1,6 @@
 ;;; imenu.el --- framework for mode-specific buffer indexes
 
-;; Copyright (C) 1994-1998, 2001-2011 Free Software Foundation, Inc.
+;; Copyright (C) 1994-1998, 2001-2012 Free Software Foundation, Inc.
 
 ;; Author: Ake Stenhoff <etxaksf@aom.ericsson.se>
 ;;         Lars Lindberg <lli@sypro.cap.se>
@@ -963,13 +963,14 @@ See the command `imenu' for more information."
          imenu-generic-expression
          (not (eq imenu-create-index-function
                   'imenu-default-create-index-function)))
-      (let ((newmap (make-sparse-keymap)))
-       (set-keymap-parent newmap (current-local-map))
-       (setq imenu--last-menubar-index-alist nil)
-       (define-key newmap [menu-bar index]
-         `(menu-item ,name ,(make-sparse-keymap "Imenu")))
-       (use-local-map newmap)
-       (add-hook 'menu-bar-update-hook 'imenu-update-menubar))
+      (unless (keymapp (lookup-key (current-local-map) [menu-bar index]))
+       (let ((newmap (make-sparse-keymap)))
+         (set-keymap-parent newmap (current-local-map))
+         (setq imenu--last-menubar-index-alist nil)
+         (define-key newmap [menu-bar index]
+           `(menu-item ,name ,(make-sparse-keymap "Imenu")))
+         (use-local-map newmap)
+         (add-hook 'menu-bar-update-hook 'imenu-update-menubar)))
     (error "The mode `%s' does not support Imenu"
            (format-mode-line mode-name))))
 
@@ -1008,6 +1009,9 @@ to `imenu-update-menubar'.")
                                                   (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)))))))
 
 (defun imenu--menubar-select (item)