Mercurial > emacs
comparison lisp/imenu.el @ 58489:5df4ac03694d
Don't always require newcomment.
(imenu--generic-function): Call comment-normalize-vars
if we have a comment syntax.
Exit the loop if REGEXP matches the null string.
Test comment-start as well as comment-start-skip
when deciding whether to check for comments.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 25 Nov 2004 02:57:47 +0000 |
parents | c8e69a3cb57f |
children | 6abce81016a6 |
comparison
equal
deleted
inserted
replaced
58488:02e7f3437fea | 58489:5df4ac03694d |
---|---|
59 ;; [david] - David M. Smith dsmith@stats.adelaide.edu.au | 59 ;; [david] - David M. Smith dsmith@stats.adelaide.edu.au |
60 ;; [christian] - Christian Egli Christian.Egli@hcsd.hac.com | 60 ;; [christian] - Christian Egli Christian.Egli@hcsd.hac.com |
61 ;; [karl] - Karl Fogel kfogel@floss.life.uiuc.edu | 61 ;; [karl] - Karl Fogel kfogel@floss.life.uiuc.edu |
62 | 62 |
63 ;;; Code: | 63 ;;; Code: |
64 | |
65 (require 'newcomment) | |
66 | 64 |
67 (eval-when-compile (require 'cl)) | 65 (eval-when-compile (require 'cl)) |
68 | 66 |
69 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 67 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
70 ;;; | 68 ;;; |
743 for modes which use `imenu--generic-function'. If it is not set, but | 741 for modes which use `imenu--generic-function'. If it is not set, but |
744 `font-lock-defaults' is set, then font-lock's setting is used.") | 742 `font-lock-defaults' is set, then font-lock's setting is used.") |
745 ;;;###autoload | 743 ;;;###autoload |
746 (make-variable-buffer-local 'imenu-case-fold-search) | 744 (make-variable-buffer-local 'imenu-case-fold-search) |
747 | 745 |
748 ;; Originally "Built on some ideas that Erik Naggum <erik@naggum.no> | 746 ;; This function can be called with quitting disabled, |
749 ;; once posted to comp.emacs" but since substantially re-written. | 747 ;; so it needs to be careful never to loop! |
750 (defun imenu--generic-function (patterns) | 748 (defun imenu--generic-function (patterns) |
751 "Return an index of the current buffer as an alist. | 749 "Return an index of the current buffer as an alist. |
752 | 750 |
753 PATTERNS is an alist with elements that look like this: | 751 PATTERNS is an alist with elements that look like this: |
754 (MENU-TITLE REGEXP INDEX). | 752 (MENU-TITLE REGEXP INDEX). |
798 (goto-char (point-max)) | 796 (goto-char (point-max)) |
799 (imenu-progress-message prev-pos 0 t) | 797 (imenu-progress-message prev-pos 0 t) |
800 (unwind-protect ; for syntax table | 798 (unwind-protect ; for syntax table |
801 (save-match-data | 799 (save-match-data |
802 (set-syntax-table table) | 800 (set-syntax-table table) |
801 (if (or comment-start comment-start-skip) | |
802 (comment-normalize-vars)) | |
803 | |
803 ;; map over the elements of imenu-generic-expression | 804 ;; map over the elements of imenu-generic-expression |
804 ;; (typically functions, variables ...) | 805 ;; (typically functions, variables ...) |
805 (dolist (pat patterns) | 806 (dolist (pat patterns) |
806 (let ((menu-title (car pat)) | 807 (let ((menu-title (car pat)) |
807 (regexp (nth 1 pat)) | 808 (regexp (nth 1 pat)) |
810 (rest (nthcdr 4 pat)) | 811 (rest (nthcdr 4 pat)) |
811 start | 812 start |
812 cs) | 813 cs) |
813 ;; Go backwards for convenience of adding items in order. | 814 ;; Go backwards for convenience of adding items in order. |
814 (goto-char (point-max)) | 815 (goto-char (point-max)) |
815 (while (re-search-backward regexp nil t) | 816 (while (and (re-search-backward regexp nil t) |
817 ;; Exit the loop if we get an empty match, | |
818 ;; because it means a bad regexp was specified. | |
819 (not (= (match-beginning 0) (match-end 0)))) | |
816 (setq start (point)) | 820 (setq start (point)) |
817 (goto-char (match-end index)) | 821 (goto-char (match-end index)) |
818 (setq beg (match-beginning index)) | 822 (setq beg (match-beginning index)) |
819 (setq cs (and comment-start-skip | 823 (setq cs (and (or comment-start comment-start-skip) |
820 (save-match-data (comment-beginning)))) | 824 (save-match-data |
825 (comment-beginning)))) | |
821 (if cs | 826 (if cs |
822 (goto-char (min cs beg)) ; skip this one, it's in a comment | 827 (goto-char (min cs beg)) ; skip this one, it's in a comment |
823 (goto-char beg) | 828 (goto-char beg) |
824 (imenu-progress-message prev-pos nil t) | 829 (imenu-progress-message prev-pos nil t) |
825 ;; Add this sort of submenu only when we've found an | 830 ;; Add this sort of submenu only when we've found an |