aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1996-09-10 17:57:05 +0000
committerRichard M. Stallman1996-09-10 17:57:05 +0000
commit32c1a22e20683851226911a8608f150fd4cb0532 (patch)
treeee67764027e7e5d95332f694a4a25ca63a325ded
parent2729bba00dab00f7bafb145350d6b01b50633a0d (diff)
downloademacs-32c1a22e20683851226911a8608f150fd4cb0532.tar.gz
emacs-32c1a22e20683851226911a8608f150fd4cb0532.zip
(imenu): Tests for when to widen were backwards.
(imenu--split-menu): Handle imenu-sort-function here. (imenu--mouse-menu, imenu-update-menubar): Not here. (imenu--mouse-menu): Rewrite second half--handle nested menus reliably. (imenu--create-keymap-2): Include ITEM in the leaf menu-item.
-rw-r--r--lisp/imenu.el81
1 files changed, 38 insertions, 43 deletions
diff --git a/lisp/imenu.el b/lisp/imenu.el
index b62b650e5e6..64ceb7a0cb1 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -392,6 +392,15 @@ This function is called after the function pointed out by
392;;; Split the alist MENULIST into a nested alist, if it is long enough. 392;;; Split the alist MENULIST into a nested alist, if it is long enough.
393;;; In any case, add TITLE to the front of the alist. 393;;; In any case, add TITLE to the front of the alist.
394(defun imenu--split-menu (menulist title) 394(defun imenu--split-menu (menulist title)
395 (if imenu-sort-function
396 (setq menulist
397 (sort
398 (let ((res nil)
399 (oldlist menulist))
400 ;; Copy list method from the cl package `copy-list'
401 (while (consp oldlist) (push (pop oldlist) res))
402 (prog1 (nreverse res) (setcdr res oldlist)))
403 imenu-sort-function)))
395 (if (> (length menulist) imenu-max-items) 404 (if (> (length menulist) imenu-max-items)
396 (let ((count 0)) 405 (let ((count 0))
397 (cons title 406 (cons title
@@ -471,7 +480,7 @@ This function is called after the function pointed out by
471 (t 480 (t
472 (let ((end (if commands `(lambda () (interactive) 481 (let ((end (if commands `(lambda () (interactive)
473 (imenu--menubar-select ',item)) 482 (imenu--menubar-select ',item))
474 (cons '(nil) t)))) 483 (cons '(nil) item))))
475 (cons (car item) 484 (cons (car item)
476 (cons (car item) end)))) 485 (cons (car item) end))))
477 ))) 486 )))
@@ -699,49 +708,44 @@ Returns t for rescan and otherwise a position number."
699 708
700INDEX-ALIST is the buffer index and EVENT is a mouse event. 709INDEX-ALIST is the buffer index and EVENT is a mouse event.
701 710
702Returns t for rescan and otherwise a position number." 711Returns t for rescan and otherwise an element or subelement of INDEX-ALIST."
703 (setq index-alist (imenu--split-submenus index-alist)) 712 (setq index-alist (imenu--split-submenus index-alist))
704 (let* ((menu (imenu--split-menu 713 (let* ((menu (imenu--split-menu index-alist
705 (if imenu-sort-function
706 (sort
707 (let ((res nil)
708 (oldlist index-alist))
709 ;; Copy list method from the cl package `copy-list'
710 (while (consp oldlist) (push (pop oldlist) res))
711 (prog1 (nreverse res) (setcdr res oldlist)))
712 imenu-sort-function)
713 index-alist)
714 (or title (buffer-name)))) 714 (or title (buffer-name))))
715 position) 715 position)
716 (setq menu (imenu--create-keymap-1 (car menu) 716 (setq menu (imenu--create-keymap-1 (car menu)
717 (if (< 1 (length (cdr menu))) 717 (if (< 1 (length (cdr menu)))
718 (cdr menu) 718 (cdr menu)
719 (cdr (cadr menu))))) 719 (cdr (car (cdr menu))))))
720 (setq position (x-popup-menu event menu)) 720 (setq position (x-popup-menu event menu))
721 (cond ((and (listp position) 721 (cond ((eq position nil)
722 position)
723 ;; If one call to x-popup-menu handled the nested menus,
724 ;; find the result by looking down the menus here.
725 ((and (listp position)
722 (numberp (car position)) 726 (numberp (car position))
723 (stringp (nth (1- (length position)) position))) 727 (stringp (nth (1- (length position)) position)))
724 (setq position (nth (1- (length position)) position))) 728 (let ((final menu))
725 ((and (stringp (car position)) 729 (while position
730 (setq final (assoc (car position) final))
731 (setq position (cdr position)))
732 (cdr (cdr (cdr final)))))
733 ;; If x-popup-menu went just one level and found a leaf item,
734 ;; return the INDEX-ALIST element for that.
735 ((and (consp position)
736 (stringp (car position))
726 (null (cdr position))) 737 (null (cdr position)))
727 (setq position (car position)))) 738 (or (string= (car position) (car imenu--rescan-item))
728 (cond ((eq position nil) 739 (assq (car position) index-alist)))
729 position) 740 ;; If x-popup-menu went just one level
741 ;; and found a non-leaf item (a submenu),
742 ;; recurse to handle the rest.
730 ((listp position) 743 ((listp position)
731 (imenu--mouse-menu position event 744 (imenu--mouse-menu position event
732 (if title 745 (if title
733 (concat title imenu-level-separator 746 (concat title imenu-level-separator
734 (car (rassq position index-alist))) 747 (car (rassq position index-alist)))
735 (car (rassq position index-alist))))) 748 (car (rassq position index-alist))))))))
736 ((stringp position)
737 (or (string= position (car imenu--rescan-item))
738 (imenu--in-alist position index-alist)))
739 ((or (= position (cdr imenu--rescan-item))
740 (and (stringp position)
741 (string= position (car imenu--rescan-item))))
742 t)
743 (t
744 (rassq position index-alist)))))
745 749
746(defun imenu-choose-buffer-index (&optional prompt alist) 750(defun imenu-choose-buffer-index (&optional prompt alist)
747 "Let the user select from a buffer index and return the chosen index. 751 "Let the user select from a buffer index and return the chosen index.
@@ -811,16 +815,7 @@ See the command `imenu' for more information."
811 (let (menu menu1 old) 815 (let (menu menu1 old)
812 (setq imenu--last-menubar-index-alist index-alist) 816 (setq imenu--last-menubar-index-alist index-alist)
813 (setq index-alist (imenu--split-submenus index-alist)) 817 (setq index-alist (imenu--split-submenus index-alist))
814 (setq menu (imenu--split-menu 818 (setq menu (imenu--split-menu index-alist
815 (if imenu-sort-function
816 (sort
817 (let ((res nil)
818 (oldlist index-alist))
819 ;; Copy list method from the cl package `copy-list'
820 (while (consp oldlist) (push (pop oldlist) res))
821 (prog1 (nreverse res) (setcdr res oldlist)))
822 imenu-sort-function)
823 index-alist)
824 (buffer-name))) 819 (buffer-name)))
825 (setq menu1 (imenu--create-keymap-1 (car menu) 820 (setq menu1 (imenu--create-keymap-1 (car menu)
826 (if (< 1 (length (cdr menu))) 821 (if (< 1 (length (cdr menu)))
@@ -855,14 +850,14 @@ See `imenu-choose-buffer-index' for more information."
855 (push-mark) 850 (push-mark)
856 (cond 851 (cond
857 ((markerp (cdr index-item)) 852 ((markerp (cdr index-item))
858 (if (or ( > (marker-position (cdr index-item)) (point-min)) 853 (if (or (< (marker-position (cdr index-item)) (point-min))
859 ( < (marker-position (cdr index-item)) (point-max))) 854 (> (marker-position (cdr index-item)) (point-max)))
860 ;; widen if outside narrowing 855 ;; widen if outside narrowing
861 (widen)) 856 (widen))
862 (goto-char (marker-position (cdr index-item)))) 857 (goto-char (marker-position (cdr index-item))))
863 (t 858 (t
864 (if (or ( > (cdr index-item) (point-min)) 859 (if (or (< (cdr index-item) (point-min))
865 ( < (cdr index-item) (point-max))) 860 (> (cdr index-item) (point-max)))
866 ;; widen if outside narrowing 861 ;; widen if outside narrowing
867 (widen)) 862 (widen))
868 (goto-char (cdr index-item))))))) 863 (goto-char (cdr index-item)))))))