X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/9201cc281b10650e96296eda8519403e2b508fbd..9805f81dda38cd541ba8043f44e720e06adf6492:/lisp/imenu.el diff --git a/lisp/imenu.el b/lisp/imenu.el index 65213ef1b2..8363956355 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el @@ -1,7 +1,6 @@ ;;; imenu.el --- framework for mode-specific buffer indexes -;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 2001, 2002, 2003, 2004, -;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +;; Copyright (C) 1994-1998, 2001-2012 Free Software Foundation, Inc. ;; Author: Ake Stenhoff ;; Lars Lindberg @@ -162,7 +161,7 @@ element should come before the second. The arguments are cons cells; ;; No longer used. KFS 2004-10-27 ;; (defcustom imenu-scanning-message "Scanning buffer for index (%3d%%)" -;; "*Progress message during the index scanning of the buffer. +;; "Progress message during the index scanning of the buffer. ;; If non-nil, user gets a message during the scanning of the buffer. ;; ;; Relevant only if the mode-specific function that creates the buffer @@ -198,6 +197,7 @@ For example, see the value of `fortran-imenu-generic-expression' used by `fortran-mode' with `imenu-syntax-alist' set locally to give the characters which normally have \"symbol\" syntax \"word\" syntax during matching.") +;;;###autoload(put 'imenu-generic-expression 'risky-local-variable t) ;;;###autoload (make-variable-buffer-local 'imenu-generic-expression) @@ -297,9 +297,9 @@ The function in this variable is called when selecting a normal index-item.") ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; FIXME: This is the only imenu-example-* definition that's actually used, -;; and it seems to only be used by cperl-mode.el. We should just move it to -;; cperl-mode.el and remove the rest. +;; FIXME: This was the only imenu-example-* definition actually used, +;; by cperl-mode.el. Now cperl-mode has its own copy, so these can +;; all be removed. (defun imenu-example--name-and-position () "Return the current/previous sexp and its (beginning) location. Don't move point." @@ -310,6 +310,8 @@ Don't move point." (end (progn (forward-sexp) (point)))) (cons (buffer-substring beg end) beg)))) +(make-obsolete 'imenu-example--name-and-position + "use your own function instead." "23.2") ;;; ;;; Lisp @@ -328,6 +330,7 @@ Don't move point." (end (progn (forward-sexp -1) (point)))) (buffer-substring beg end))) (error nil))))) +(make-obsolete 'imenu-example--lisp-extract-index-name "your own" "23.2") (defun imenu-example--create-lisp-index () ;; Example of a candidate for `imenu-create-index-function'. @@ -379,6 +382,7 @@ Don't move point." (push (cons "Syntax-unknown" index-unknown-alist) index-alist)) index-alist)) +(make-obsolete 'imenu-example--create-lisp-index "your own" "23.2") ;; Regular expression to find C functions (defvar imenu-example--function-name-regexp-c @@ -410,7 +414,7 @@ Don't move point." (push (imenu-example--name-and-position) index-alist)))) (imenu-progress-message prev-pos 100) (nreverse index-alist))) - +(make-obsolete 'imenu-example--create-c-index "your own" "23.2") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -440,6 +444,7 @@ if it is a sub-alist. There is one simple element with negative POSITION; selecting that element recalculates the buffer's index alist.") +;;;###autoload(put 'imenu--index-alist 'risky-local-variable t) (make-variable-buffer-local 'imenu--index-alist) @@ -590,7 +595,7 @@ See `imenu--index-alist' for the format of the index alist." ;;; Find all markers in alist and makes ;;; them point nowhere. ;;; The top-level call uses nil as the argument; -;;; non-nil arguments are in recursivecalls. +;;; non-nil arguments are in recursive calls. (defvar imenu--cleanup-seen) (defun imenu--cleanup (&optional alist) @@ -678,12 +683,15 @@ The alternate method, which is the one most often used, is to call ;; in these major modes. But save that change for later. (cond ((and imenu-prev-index-position-function imenu-extract-index-name-function) - (let ((index-alist '()) + (let ((index-alist '()) (pos (point)) prev-pos name) (goto-char (point-max)) (imenu-progress-message prev-pos 0 t) ;; Search for the function (while (funcall imenu-prev-index-position-function) + (when (= pos (point)) + (error "Infinite loop at %s:%d: imenu-prev-index-position-function does not move point" (buffer-name) pos)) + (setq pos (point)) (imenu-progress-message prev-pos nil t) (save-excursion (setq name (funcall imenu-extract-index-name-function))) @@ -955,13 +963,14 @@ See the command `imenu' for more information." imenu-generic-expression (not (eq imenu-create-index-function 'imenu-default-create-index-function))) - (let ((newmap (make-sparse-keymap))) - (set-keymap-parent newmap (current-local-map)) - (setq imenu--last-menubar-index-alist nil) - (define-key newmap [menu-bar index] - `(menu-item ,name ,(make-sparse-keymap "Imenu"))) - (use-local-map newmap) - (add-hook 'menu-bar-update-hook 'imenu-update-menubar)) + (unless (keymapp (lookup-key (current-local-map) [menu-bar index])) + (let ((newmap (make-sparse-keymap))) + (set-keymap-parent newmap (current-local-map)) + (setq imenu--last-menubar-index-alist nil) + (define-key newmap [menu-bar index] + `(menu-item ,name ,(make-sparse-keymap "Imenu"))) + (use-local-map newmap) + (add-hook 'menu-bar-update-hook 'imenu-update-menubar))) (error "The mode `%s' does not support Imenu" (format-mode-line mode-name)))) @@ -1000,6 +1009,9 @@ to `imenu-update-menubar'.") (car (cdr menu)))) 'imenu--menubar-select)) (setq old (lookup-key (current-local-map) [menu-bar index])) + ;; This should never happen, but in some odd cases, potentially, + ;; lookup-key may return a dynamically composed keymap. + (if (keymapp (cadr old)) (setq old (cadr old))) (setcdr old (cdr menu1))))))) (defun imenu--menubar-select (item) @@ -1057,5 +1069,4 @@ for more information." (provide 'imenu) -;; arch-tag: 98a2f5f5-4b91-4704-b18c-3aacf77d77a7 ;;; imenu.el ends here