- (mapcar
- (function
- (lambda (pat)
- (let ((menu-title (car pat))
- (regexp (nth 1 pat))
- (index (nth 2 pat))
- (function (nth 3 pat))
- (rest (nthcdr 4 pat)))
- ;; Go backwards for convenience of adding items in order.
- (goto-char (point-max))
- (while (re-search-backward regexp nil t)
- (imenu-progress-message prev-pos nil t)
- (setq beg (match-beginning index))
- ;; Add this sort of submenu only when we've found an
- ;; item for it, avoiding empty, duff menus.
- (unless (assoc menu-title index-alist)
- (push (list menu-title) index-alist))
- (if imenu-use-markers
- (setq beg (set-marker (make-marker) beg)))
- (let ((item
- (if function
- (nconc (list (match-string-no-properties index)
- beg function)
- rest)
- (cons (match-string-no-properties index)
- beg)))
- ;; This is the desired submenu,
- ;; starting with its title (or nil).
- (menu (assoc menu-title index-alist)))
- ;; Insert the item unless it is already present.
- (unless (member item (cdr menu))
- (setcdr menu
- (cons item (cdr menu)))))))))
- patterns)
+ (dolist (pat patterns)
+ (let ((menu-title (car pat))
+ (regexp (nth 1 pat))
+ (index (nth 2 pat))
+ (function (nth 3 pat))
+ (rest (nthcdr 4 pat))
+ start beg)
+ ;; Go backwards for convenience of adding items in order.
+ (goto-char (point-max))
+ (while (and (if (functionp regexp)
+ (funcall regexp)
+ (re-search-backward regexp nil t))
+ ;; Exit the loop if we get an empty match,
+ ;; because it means a bad regexp was specified.
+ (not (= (match-beginning 0) (match-end 0))))
+ (setq start (point))
+ ;; Record the start of the line in which the match starts.
+ ;; That's the official position of this definition.
+ (goto-char (match-beginning index))
+ (beginning-of-line)
+ (setq beg (point))
+ (imenu-progress-message prev-pos nil t)
+ ;; Add this sort of submenu only when we've found an
+ ;; item for it, avoiding empty, duff menus.
+ (unless (assoc menu-title index-alist)
+ (push (list menu-title) index-alist))
+ (if imenu-use-markers
+ (setq beg (copy-marker beg)))
+ (let ((item
+ (if function
+ (nconc (list (match-string-no-properties index)
+ beg function)
+ rest)
+ (cons (match-string-no-properties index)
+ beg)))
+ ;; This is the desired submenu,
+ ;; starting with its title (or nil).
+ (menu (assoc menu-title index-alist)))
+ ;; Insert the item unless it is already present.
+ (unless (member item (cdr menu))
+ (setcdr menu
+ (cons item (cdr menu)))))
+ ;; Go to the start of the match, to make sure we
+ ;; keep making progress backwards.
+ (goto-char start))))