798 |
(unwind-protect ; for syntax table |
(unwind-protect ; for syntax table |
799 |
(save-match-data |
(save-match-data |
800 |
(set-syntax-table table) |
(set-syntax-table table) |
|
(if (or comment-start comment-start-skip) |
|
|
(comment-normalize-vars)) |
|
801 |
|
|
802 |
;; map over the elements of imenu-generic-expression |
;; map over the elements of imenu-generic-expression |
803 |
;; (typically functions, variables ...) |
;; (typically functions, variables ...) |
807 |
(index (nth 2 pat)) |
(index (nth 2 pat)) |
808 |
(function (nth 3 pat)) |
(function (nth 3 pat)) |
809 |
(rest (nthcdr 4 pat)) |
(rest (nthcdr 4 pat)) |
810 |
start |
start) |
|
cs) |
|
811 |
;; Go backwards for convenience of adding items in order. |
;; Go backwards for convenience of adding items in order. |
812 |
(goto-char (point-max)) |
(goto-char (point-max)) |
813 |
(while (and (re-search-backward regexp nil t) |
(while (and (re-search-backward regexp nil t) |
817 |
(setq start (point)) |
(setq start (point)) |
818 |
(goto-char (match-end index)) |
(goto-char (match-end index)) |
819 |
(setq beg (match-beginning index)) |
(setq beg (match-beginning index)) |
820 |
(setq cs (and (or comment-start comment-start-skip) |
(goto-char beg) |
821 |
(save-match-data |
(imenu-progress-message prev-pos nil t) |
822 |
(comment-beginning)))) |
;; Add this sort of submenu only when we've found an |
823 |
(if cs |
;; item for it, avoiding empty, duff menus. |
824 |
(goto-char (min cs beg)) ; skip this one, it's in a comment |
(unless (assoc menu-title index-alist) |
825 |
(goto-char beg) |
(push (list menu-title) index-alist)) |
826 |
(imenu-progress-message prev-pos nil t) |
(if imenu-use-markers |
827 |
;; Add this sort of submenu only when we've found an |
(setq beg (copy-marker beg))) |
828 |
;; item for it, avoiding empty, duff menus. |
(let ((item |
829 |
(unless (assoc menu-title index-alist) |
(if function |
830 |
(push (list menu-title) index-alist)) |
(nconc (list (match-string-no-properties index) |
831 |
(if imenu-use-markers |
beg function) |
832 |
(setq beg (copy-marker beg))) |
rest) |
833 |
(let ((item |
(cons (match-string-no-properties index) |
834 |
(if function |
beg))) |
835 |
(nconc (list (match-string-no-properties index) |
;; This is the desired submenu, |
836 |
beg function) |
;; starting with its title (or nil). |
837 |
rest) |
(menu (assoc menu-title index-alist))) |
838 |
(cons (match-string-no-properties index) |
;; Insert the item unless it is already present. |
839 |
beg))) |
(unless (member item (cdr menu)) |
840 |
;; This is the desired submenu, |
(setcdr menu |
841 |
;; starting with its title (or nil). |
(cons item (cdr menu))))) |
842 |
(menu (assoc menu-title index-alist))) |
;; Move to the start of the entire match, |
843 |
;; Insert the item unless it is already present. |
;; to ensure we keep moving backwards |
844 |
(unless (member item (cdr menu)) |
;; as long as the match is nonempty. |
845 |
(setcdr menu |
(goto-char start)))) |
|
(cons item (cdr menu))))) |
|
|
;; Move to the start of the entire match, |
|
|
;; to ensure we keep moving backwards |
|
|
;; as long as the match is nonempty. |
|
|
(goto-char start))))) |
|
846 |
(set-syntax-table old-table))) |
(set-syntax-table old-table))) |
847 |
(imenu-progress-message prev-pos 100 t) |
(imenu-progress-message prev-pos 100 t) |
848 |
;; Sort each submenu by position. |
;; Sort each submenu by position. |