comparison lisp/imenu.el @ 14657:4bedd113757f

(imenu-add-to-menubar): Add menu item for current buf only. (imenu-update-menubar): Never add menu item here.
author Richard M. Stallman <rms@gnu.org>
date Sat, 24 Feb 1996 01:42:31 +0000
parents 4e78b18f1f4f
children eeffb8e882b4
comparison
equal deleted inserted replaced
14656:4e78b18f1f4f 14657:4bedd113757f
783 (setq imenu--index-alist nil))) 783 (setq imenu--index-alist nil)))
784 result)) 784 result))
785 785
786 ;;;###autoload 786 ;;;###autoload
787 (defun imenu-add-to-menubar (name) 787 (defun imenu-add-to-menubar (name)
788 "Adds an \"imenu\" entry to the menu bar for the current major mode. 788 "Adds an `imenu' entry to the menu bar for the current buffer.
789 NAME is a string used to name the menu bar item. 789 NAME is a string used to name the menu bar item.
790 See `imenu' for more information." 790 See the command `imenu' for more information."
791 (interactive "sImenu menu item name: ") 791 (interactive "sImenu menu item name: ")
792 (define-key (current-local-map) [menu-bar index] 792 (let ((newmap (make-sparse-keymap))
793 (cons name (nconc (make-sparse-keymap "Imenu") 793 (menu-bar (lookup-key (current-local-map) [menu-bar])))
794 (make-sparse-keymap)))) 794 (define-key newmap [menu-bar]
795 (append (make-sparse-keymap) menu-bar))
796 (define-key newmap [menu-bar index]
797 (cons name (nconc (make-sparse-keymap "Imenu")
798 (make-sparse-keymap))))
799 (use-local-map (append newmap (current-local-map))))
795 (add-hook 'menu-bar-update-hook 'imenu-update-menubar)) 800 (add-hook 'menu-bar-update-hook 'imenu-update-menubar))
796 801
797 (defvar imenu-buffer-menubar nil) 802 (defvar imenu-buffer-menubar nil)
798 803
799 (defun imenu-update-menubar () 804 (defun imenu-update-menubar ()
800 (and (current-local-map) 805 (and (current-local-map)
801 (keymapp (lookup-key (current-local-map) [menu-bar index])) 806 (keymapp (lookup-key (current-local-map) [menu-bar index]))
802 (progn
803 (or (local-variable-p 'imenu-buffer-menubar)
804 ;; Make a buffer-specific copy of the local map
805 ;; so that we don't affect other buffers with the same major mode.
806 (let ((newmap (make-sparse-keymap)))
807 (define-key (current-local-map) [menu-bar index]
808 (cons name (nconc (make-sparse-keymap "Imenu")
809 (make-sparse-keymap))))
810 (use-local-map (append newmap (current-local-map)))))
811 (make-local-variable 'imenu-buffer-menubar)
812 t)
813 (let ((index-alist (imenu--make-index-alist t))) 807 (let ((index-alist (imenu--make-index-alist t)))
814 ;; Don't bother updating if the index-alist has not changed 808 ;; Don't bother updating if the index-alist has not changed
815 ;; since the last time we did it. 809 ;; since the last time we did it.
816 (or (equal index-alist imenu--last-menubar-index-alist) 810 (or (equal index-alist imenu--last-menubar-index-alist)
817 (let (menu menu1 old) 811 (let (menu menu1 old)