X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/ddc62155d24b9a9e24177bd5f13934e0d5b23159..61addbc212a08ba146fc7baa7b3c04071f4445fb:/lisp/imenu.el diff --git a/lisp/imenu.el b/lisp/imenu.el index b72cbeb42b..c1077a49d1 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el @@ -447,6 +447,8 @@ Don't move point." Simple elements in the alist look like (INDEX-NAME . POSITION). POSITION is the buffer position of the item; to go to the item is simply to move point to that position. +POSITION is passed to `imenu-default-goto-function', so it can be a non-number +if that variable has been changed (e.g. Semantic uses overlays for POSITIONs). Special elements look like (INDEX-NAME POSITION FUNCTION ARGUMENTS...). To \"go to\" a special element means applying FUNCTION @@ -546,25 +548,21 @@ The returned alist DOES NOT share structure with MENULIST." Return a split and sorted copy of ALIST. The returned alist DOES NOT share structure with ALIST." (mapcar (lambda (elt) - (if (and (consp elt) - (stringp (car elt)) - (listp (cdr elt))) + (if (imenu--subalist-p elt) (imenu--split-menu (cdr elt) (car elt)) elt)) alist)) (defun imenu--truncate-items (menulist) "Truncate all strings in MENULIST to `imenu-max-item-length'." - (mapcar (lambda (item) - (cond - ((consp (cdr item)) - (imenu--truncate-items (cdr item))) - ;; truncate if necessary - ((and (numberp imenu-max-item-length) - (> (length (car item)) imenu-max-item-length)) - (setcar item (substring (car item) 0 imenu-max-item-length))))) - menulist)) - + (mapc (lambda (item) + ;; truncate if necessary + (when (and (numberp imenu-max-item-length) + (> (length (car item)) imenu-max-item-length)) + (setcar item (substring (car item) 0 imenu-max-item-length))) + (when (imenu--subalist-p item) + (imenu--truncate-items (cdr item)))) + menulist)) (defun imenu--make-index-alist (&optional noerror) "Create an index alist for the definitions in the current buffer. @@ -678,11 +676,13 @@ The alternate method, which is the one most often used, is to call ;; in these major modes. But save that change for later. (cond ((and imenu-prev-index-position-function imenu-extract-index-name-function) - (let ((index-alist '()) (pos (point)) + (let ((index-alist '()) (pos (point-max)) name) - (goto-char (point-max)) + (goto-char pos) ;; Search for the function (while (funcall imenu-prev-index-position-function) + (unless (< (point) pos) + (error "Infinite loop at %s:%d: imenu-prev-index-position-function does not move point" (buffer-name) pos)) (setq pos (point)) (save-excursion (setq name (funcall imenu-extract-index-name-function)))