]> code.delx.au - gnu-emacs/blobdiff - lisp/imenu.el
(blink-cursor-mode): Replace `emacs-quick-startup' with `no-blinking-cursor'.
[gnu-emacs] / lisp / imenu.el
index d20dc4bccb832820c28443410e4d5477c179c790..85430bbdbfc43edb8b67c087433d78ba4622a910 100644 (file)
@@ -62,8 +62,6 @@
 
 ;;; Code:
 
-(require 'newcomment)
-
 (eval-when-compile (require 'cl))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -109,7 +107,7 @@ This variable is buffer-local."
 
 (defvar imenu-always-use-completion-buffer-p nil)
 (make-obsolete-variable 'imenu-always-use-completion-buffer-p
-                       'imenu-use-popup-menu "21.4")
+                       'imenu-use-popup-menu "22.1")
 
 (defcustom imenu-use-popup-menu
   (if imenu-always-use-completion-buffer-p
@@ -128,7 +126,7 @@ If `on-mouse' use a popup menu when `imenu' was invoked with the mouse."
   "If non-nil, eagerly popup the completion buffer."
   :type 'boolean
   :group 'imenu
-  :version "21.4")
+  :version "22.1")
 
 (defcustom imenu-after-jump-hook nil
   "*Hooks called after jumping to a place in the buffer.
@@ -534,7 +532,7 @@ A nested sub-alist element looks like (INDEX-NAME SUB-ALIST).")
        (push item keep-at-top)
        (setq menulist (delq item menulist))))
     (if imenu-sort-function
-       (setq menulist (sort menulist imenu-sort-function)))
+       (setq menulist (sort (copy-sequence menulist) imenu-sort-function)))
     (if (> (length menulist) imenu-max-items)
        (setq menulist
              (mapcar
@@ -745,8 +743,8 @@ for modes which use `imenu--generic-function'.  If it is not set, but
 ;;;###autoload
 (make-variable-buffer-local 'imenu-case-fold-search)
 
-;; Originally "Built on some ideas that Erik Naggum <erik@naggum.no>
-;; once posted to comp.emacs" but since substantially re-written.
+;; This function can be called with quitting disabled,
+;; so it needs to be careful never to loop!
 (defun imenu--generic-function (patterns)
   "Return an index of the current buffer as an alist.
 
@@ -800,6 +798,7 @@ depending on PATTERNS."
     (unwind-protect                    ; for syntax table
        (save-match-data
          (set-syntax-table table)
+
          ;; map over the elements of imenu-generic-expression
          ;; (typically functions, variables ...)
          (dolist (pat patterns)
@@ -808,44 +807,40 @@ depending on PATTERNS."
                  (index (nth 2 pat))
                  (function (nth 3 pat))
                  (rest (nthcdr 4 pat))
-                 start
-                 cs)
+                 start)
              ;; Go backwards for convenience of adding items in order.
              (goto-char (point-max))
-             (while (re-search-backward regexp nil t)
+             (while (and (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))
                (goto-char (match-end index))
                (setq beg (match-beginning index))
-               (setq cs (and comment-start-skip
-                             (save-match-data (comment-beginning))))
-               (if cs
-                   (goto-char (min cs beg)) ; skip this one, it's in a comment
-                 (goto-char beg)
-                 (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)))))
-                 ;; Move to the start of the entire match,
-                 ;; to ensure we keep moving backwards
-                 ;; as long as the match is nonempty.
-                 (goto-char start)))))
+               ;; Go to the start of the match.
+               ;; That's the official position of this definition.
+               (goto-char start)
+               (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)))
+               (let ((item
+                      (if function
+                          (nconc (list (match-string-no-properties index)
+                                       start function)
+                                 rest)
+                        (cons (match-string-no-properties index)
+                              start)))
+                     ;; 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))))))))
          (set-syntax-table old-table)))
     (imenu-progress-message prev-pos 100 t)
     ;; Sort each submenu by position.