aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2014-10-20 21:33:44 -0400
committerStefan Monnier2014-10-20 21:33:44 -0400
commite538605e4cbc504a0481b2aad0eaf7b9529294d3 (patch)
tree65765fa6b8847c3040bd98e632dfbb8298449462
parenteed18bf1fd1162872e196091ab795a773f277e8e (diff)
downloademacs-e538605e4cbc504a0481b2aad0eaf7b9529294d3.tar.gz
emacs-e538605e4cbc504a0481b2aad0eaf7b9529294d3.zip
* 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.
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/imenu.el26
2 files changed, 23 insertions, 14 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 448a2e2a752..6e40eab2c18 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,9 @@
12014-10-21 Stefan Monnier <monnier@iro.umontreal.ca> 12014-10-21 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * imenu.el (imenu--menubar-keymap): New var.
4 (imenu-add-to-menubar): Set it to remember the keymap we used.
5 (imenu-update-menubar): Use it instead of asking lookup-key.
6
3 * obsolete/cc-compat.el: Make obsolete (bug#18561). 7 * obsolete/cc-compat.el: Make obsolete (bug#18561).
4 8
5 * epg-config.el (epg-gpg-program): Don't use absolute names by default. 9 * epg-config.el (epg-gpg-program): Don't use absolute names by default.
@@ -28,6 +32,13 @@
28 32
292014-10-20 Stefan Monnier <monnier@iro.umontreal.ca> 332014-10-20 Stefan Monnier <monnier@iro.umontreal.ca>
30 34
35 * mouse.el (mouse--down-1-maybe-follows-link): Remove unused var
36 `this-event'.
37 (mouse-drag-line): Use there's no actual mouse, use the event's
38 position info.
39
402014-10-20 Stefan Monnier <monnier@iro.umontreal.ca>
41
31 * textmodes/css-mode.el (scss-mode): New major-mode. 42 * textmodes/css-mode.el (scss-mode): New major-mode.
32 (css-mode-syntax-table): Use d style comment, to ease the scss case. 43 (css-mode-syntax-table): Use d style comment, to ease the scss case.
33 (css-ident-re): Allow things like @-moz-keyframes. 44 (css-ident-re): Allow things like @-moz-keyframes.
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)."
936 (setq result t imenu--index-alist nil))) 936 (setq result t imenu--index-alist nil)))
937 result)) 937 result))
938 938
939(defvar-local imenu--menubar-keymap nil)
940
939;;;###autoload 941;;;###autoload
940(defun imenu-add-to-menubar (name) 942(defun imenu-add-to-menubar (name)
941 "Add an `imenu' entry to the menu bar for the current buffer. 943 "Add an `imenu' entry to the menu bar for the current buffer.
@@ -952,8 +954,9 @@ See the command `imenu' for more information."
952 (let ((newmap (make-sparse-keymap))) 954 (let ((newmap (make-sparse-keymap)))
953 (set-keymap-parent newmap (current-local-map)) 955 (set-keymap-parent newmap (current-local-map))
954 (setq imenu--last-menubar-index-alist nil) 956 (setq imenu--last-menubar-index-alist nil)
957 (setq imenu--menubar-keymap (make-sparse-keymap "Imenu"))
955 (define-key newmap [menu-bar index] 958 (define-key newmap [menu-bar index]
956 `(menu-item ,name ,(make-sparse-keymap "Imenu"))) 959 `(menu-item ,name ,imenu--menubar-keymap))
957 (use-local-map newmap) 960 (use-local-map newmap)
958 (add-hook 'menu-bar-update-hook 'imenu-update-menubar))) 961 (add-hook 'menu-bar-update-hook 'imenu-update-menubar)))
959 (user-error "The mode `%s' does not support Imenu" 962 (user-error "The mode `%s' does not support Imenu"
@@ -975,28 +978,23 @@ to `imenu-update-menubar'.")
975 978
976(defun imenu-update-menubar () 979(defun imenu-update-menubar ()
977 (when (and (current-local-map) 980 (when (and (current-local-map)
978 (keymapp (lookup-key (current-local-map) [menu-bar index])) 981 imenu--menubar-keymap
979 (/= (buffer-chars-modified-tick) imenu-menubar-modified-tick)) 982 (/= (buffer-chars-modified-tick) imenu-menubar-modified-tick))
980 (setq imenu-menubar-modified-tick (buffer-chars-modified-tick)) 983 (setq imenu-menubar-modified-tick (buffer-chars-modified-tick))
981 (let ((index-alist (imenu--make-index-alist t))) 984 (let ((index-alist (imenu--make-index-alist t)))
982 ;; Don't bother updating if the index-alist has not changed 985 ;; Don't bother updating if the index-alist has not changed
983 ;; since the last time we did it. 986 ;; since the last time we did it.
984 (unless (equal index-alist imenu--last-menubar-index-alist) 987 (unless (equal index-alist imenu--last-menubar-index-alist)
985 (let (menu menu1 old) 988 (setq imenu--last-menubar-index-alist index-alist)
986 (setq imenu--last-menubar-index-alist index-alist) 989 (setq index-alist (imenu--split-submenus index-alist))
987 (setq index-alist (imenu--split-submenus index-alist)) 990 (let* ((menu (imenu--split-menu index-alist
988 (setq menu (imenu--split-menu index-alist 991 (buffer-name)))
989 (buffer-name))) 992 (menu1 (imenu--create-keymap (car menu)
990 (setq menu1 (imenu--create-keymap (car menu)
991 (cdr (if (< 1 (length (cdr menu))) 993 (cdr (if (< 1 (length (cdr menu)))
992 menu 994 menu
993 (car (cdr menu)))) 995 (car (cdr menu))))
994 'imenu--menubar-select)) 996 'imenu--menubar-select)))
995 (setq old (lookup-key (current-local-map) [menu-bar index])) 997 (setcdr imenu--menubar-keymap (cdr menu1)))))))
996 ;; This should never happen, but in some odd cases, potentially,
997 ;; lookup-key may return a dynamically composed keymap.
998 (if (keymapp (cadr old)) (setq old (cadr old)))
999 (setcdr old (cdr menu1)))))))
1000 998
1001(defun imenu--menubar-select (item) 999(defun imenu--menubar-select (item)
1002 "Use Imenu to select the function or variable named in this menu ITEM." 1000 "Use Imenu to select the function or variable named in this menu ITEM."