From 1cade2b675ffb1eaac5f8c78e87b60efb84eb9f6 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Sat, 23 Apr 2005 16:43:30 +0000 Subject: [PATCH] (imenu--generic-function): The official position of a definition is the start of the line that BEG is in. --- lisp/imenu.el | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lisp/imenu.el b/lisp/imenu.el index 85430bbdbfc..831550bd7a3 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el @@ -777,7 +777,7 @@ They may also be nested index alists like: depending on PATTERNS." (let ((index-alist (list 'dummy)) - prev-pos beg + prev-pos (case-fold-search (if (or (local-variable-p 'imenu-case-fold-search) (not (local-variable-p 'font-lock-defaults))) imenu-case-fold-search @@ -807,7 +807,7 @@ depending on PATTERNS." (index (nth 2 pat)) (function (nth 3 pat)) (rest (nthcdr 4 pat)) - start) + start beg) ;; Go backwards for convenience of adding items in order. (goto-char (point-max)) (while (and (re-search-backward regexp nil t) @@ -815,32 +815,35 @@ depending on PATTERNS." ;; because it means a bad regexp was specified. (not (= (match-beginning 0) (match-end 0)))) (setq start (point)) - (goto-char (match-end index)) - (setq beg (match-beginning index)) - ;; Go to the start of the match. + ;; Record the start of the line in which the match starts. ;; That's the official position of this definition. - (goto-char start) + (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 start (copy-marker start))) + (setq beg (copy-marker beg))) (let ((item (if function (nconc (list (match-string-no-properties index) - start function) + beg function) rest) (cons (match-string-no-properties index) - start))) + 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)))))))) + (cons item (cdr menu))))) + ;; Go to the start of the match, to make sure we + ;; keep making progress backwards. + (goto-char start)))) (set-syntax-table old-table))) (imenu-progress-message prev-pos 100 t) ;; Sort each submenu by position. -- 2.39.2