- (regexp (cadr pat))
- (index (caddr pat)))
- (if (and (not found) ; Only allow one entry;
- (looking-at regexp))
- (let ((beg (match-beginning index))
- (end (match-end index)))
- (setq found t)
- (push
- (cons (buffer-substring-no-properties beg end) beg)
- (cdr
- (or (assoc menu-title index-alist)
- (car (push
- (cons menu-title '())
- index-alist))))))))))
- patterns))))
+ (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)))
+ (menu (cdr (assoc menu-title index-alist))))
+ ;; avoid duplicates from, e.g. cc-mode patterns
+ (unless (member item menu)
+ ;; insert the item after the (sub-)menu title
+ (setcdr (assoc menu-title index-alist)
+ (cons item menu))))))))
+ patterns)
+ (set-syntax-table old-table)))