;;; Code:
-(require 'newcomment)
-
(eval-when-compile (require 'cl))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(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
"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.
(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
;;;###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.
(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)
(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.