comparison lisp/imenu.el @ 90385:72dea2ff0142

Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-57 Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 226-238) - Update from CVS - Merge from gnus--rel--5.10 - Update from CVS: lisp/progmodes/python.el (python-mode): Fix typo. * gnus--rel--5.10 (patch 86-90) - Update from CVS - Merge from emacs--devo--0
author Miles Bader <miles@gnu.org>
date Fri, 21 Apr 2006 05:39:14 +0000
parents c5406394f567 ed33247a09d2
children 8a8e69664178
comparison
equal deleted inserted replaced
90384:c156f6a9e7b5 90385:72dea2ff0142
206 206
207 ;;;; Hooks 207 ;;;; Hooks
208 208
209 ;;;###autoload 209 ;;;###autoload
210 (defvar imenu-create-index-function 'imenu-default-create-index-function 210 (defvar imenu-create-index-function 'imenu-default-create-index-function
211 "The function to use for creating a buffer index. 211 "The function to use for creating an index alist of the current buffer.
212 212
213 It should be a function that takes no arguments and returns an index 213 It should be a function that takes no arguments and returns
214 of the current buffer as an alist. 214 an index alist of the current buffer. The function is
215 215 called within a `save-excursion'.
216 Simple elements in the alist look like (INDEX-NAME . INDEX-POSITION). 216
217 Special elements look like (INDEX-NAME INDEX-POSITION FUNCTION ARGUMENTS...). 217 See `imenu--index-alist' for the format of the buffer index alist.")
218 A nested sub-alist element looks like (INDEX-NAME SUB-ALIST).
219 The function `imenu--subalist-p' tests an element and returns t
220 if it is a sub-alist.
221
222 This function is called within a `save-excursion'.")
223 ;;;###autoload 218 ;;;###autoload
224 (make-variable-buffer-local 'imenu-create-index-function) 219 (make-variable-buffer-local 'imenu-create-index-function)
225 220
226 ;;;###autoload 221 ;;;###autoload
227 (defvar imenu-prev-index-position-function 'beginning-of-defun 222 (defvar imenu-prev-index-position-function 'beginning-of-defun
429 (defconst imenu--rescan-item '("*Rescan*" . -99)) 424 (defconst imenu--rescan-item '("*Rescan*" . -99))
430 425
431 ;; The latest buffer index. 426 ;; The latest buffer index.
432 ;; Buffer local. 427 ;; Buffer local.
433 (defvar imenu--index-alist nil 428 (defvar imenu--index-alist nil
434 "The buffer index computed for this buffer in Imenu. 429 "The buffer index alist computed for this buffer in Imenu.
435 Simple elements in the alist look like (INDEX-NAME . INDEX-POSITION). 430
436 Special elements look like (INDEX-NAME INDEX-POSITION FUNCTION ARGUMENTS...). 431 Simple elements in the alist look like (INDEX-NAME . POSITION).
437 A nested sub-alist element looks like (INDEX-NAME SUB-ALIST).") 432 POSITION is the buffer position of the item; to go to the item
433 is simply to move point to that position.
434
435 Special elements look like (INDEX-NAME POSITION FUNCTION ARGUMENTS...).
436 To \"go to\" a special element means applying FUNCTION
437 to INDEX-NAME, POSITION, and the ARGUMENTS.
438
439 A nested sub-alist element looks like (INDEX-NAME SUB-ALIST).
440 The function `imenu--subalist-p' tests an element and returns t
441 if it is a sub-alist.
442
443 There is one simple element with negative POSITION; selecting that
444 element recalculates the buffer's index alist.")
438 445
439 (make-variable-buffer-local 'imenu--index-alist) 446 (make-variable-buffer-local 'imenu--index-alist)
440 447
441 (defvar imenu--last-menubar-index-alist nil 448 (defvar imenu--last-menubar-index-alist nil
442 "The latest buffer index used to update the menu bar menu.") 449 "The latest buffer index alist used to update the menu bar menu.")
443 450
444 (make-variable-buffer-local 'imenu--last-menubar-index-alist) 451 (make-variable-buffer-local 'imenu--last-menubar-index-alist)
445 452
446 ;; History list for 'jump-to-function-in-buffer'. 453 ;; History list for 'jump-to-function-in-buffer'.
447 ;; Making this buffer local caused it not to work! 454 ;; Making this buffer local caused it not to work!
545 (setcar item (substring (car item) 0 imenu-max-item-length)))))) 552 (setcar item (substring (car item) 0 imenu-max-item-length))))))
546 menulist)) 553 menulist))
547 554
548 555
549 (defun imenu--make-index-alist (&optional noerror) 556 (defun imenu--make-index-alist (&optional noerror)
550 "Create an index-alist for the definitions in the current buffer. 557 "Create an index alist for the definitions in the current buffer.
551 558 This works by using the hook function `imenu-create-index-function'.
552 Report an error if the list is empty unless NOERROR is supplied and 559 Report an error if the list is empty unless NOERROR is supplied and
553 non-nil. 560 non-nil.
554 561
555 Simple elements in the alist look like (INDEX-NAME . INDEX-POSITION). 562 See `imenu--index-alist' for the format of the index alist."
556 Special elements look like (INDEX-NAME FUNCTION ARGUMENTS...).
557 A nested sub-alist element looks like (INDEX-NAME SUB-ALIST).
558 The function `imenu--subalist-p' tests an element and returns t
559 if it is a sub-alist.
560
561 There is one simple element with negative POSITION; that's intended
562 as a way for the user to ask to recalculate the buffer's index alist."
563 (or (and imenu--index-alist 563 (or (and imenu--index-alist
564 (or (not imenu-auto-rescan) 564 (or (not imenu-auto-rescan)
565 (and imenu-auto-rescan 565 (and imenu-auto-rescan
566 (> (buffer-size) imenu-auto-rescan-maxout)))) 566 (> (buffer-size) imenu-auto-rescan-maxout))))
567 ;; Get the index; truncate if necessary 567 ;; Get the index; truncate if necessary
655 and speed-up matching.") 655 and speed-up matching.")
656 ;;;###autoload 656 ;;;###autoload
657 (make-variable-buffer-local 'imenu-syntax-alist) 657 (make-variable-buffer-local 'imenu-syntax-alist)
658 658
659 (defun imenu-default-create-index-function () 659 (defun imenu-default-create-index-function ()
660 "*Wrapper for index searching functions. 660 "*Default function to create an index alist of the current buffer.
661 661
662 Moves point to end of buffer and then repeatedly calls 662 The most general method is to move point to end of buffer, then repeatedly call
663 `imenu-prev-index-position-function' and `imenu-extract-index-name-function'. 663 `imenu-prev-index-position-function' and `imenu-extract-index-name-function'.
664 Their results are gathered into an index alist." 664 All the results returned by the latter are gathered into an index alist.
665 This method is used if those two variables are non-nil.
666
667 The alternate method, which is the one most often used, is to call
668 `imenu--generic-function' with `imenu-generic-expression' as argument."
665 ;; These should really be done by setting imenu-create-index-function 669 ;; These should really be done by setting imenu-create-index-function
666 ;; in these major modes. But save that change for later. 670 ;; in these major modes. But save that change for later.
667 (cond ((and imenu-prev-index-position-function 671 (cond ((and imenu-prev-index-position-function
668 imenu-extract-index-name-function) 672 imenu-extract-index-name-function)
669 (let ((index-alist '()) 673 (let ((index-alist '())
685 ((and imenu-generic-expression) 689 ((and imenu-generic-expression)
686 (imenu--generic-function imenu-generic-expression)) 690 (imenu--generic-function imenu-generic-expression))
687 (t 691 (t
688 (error "This buffer cannot use `imenu-default-create-index-function'")))) 692 (error "This buffer cannot use `imenu-default-create-index-function'"))))
689 693
690 ;; Not used and would require cl at run time
691 ;; (defun imenu--flatten-index-alist (index-alist &optional concat-names prefix)
692 ;; ;; Takes a nested INDEX-ALIST and returns a flat index alist.
693 ;; ;; If optional CONCAT-NAMES is non-nil, then a nested index has its
694 ;; ;; name and a space concatenated to the names of the children.
695 ;; ;; Third argument PREFIX is for internal use only.
696 ;; (mapcan
697 ;; (lambda (item)
698 ;; (let* ((name (car item))
699 ;; (pos (cdr item))
700 ;; (new-prefix (and concat-names
701 ;; (if prefix
702 ;; (concat prefix imenu-level-separator name)
703 ;; name))))
704 ;; (cond
705 ;; ((or (markerp pos) (numberp pos))
706 ;; (list (cons new-prefix pos)))
707 ;; (t
708 ;; (imenu--flatten-index-alist pos new-prefix)))))
709 ;; index-alist))
710
711 ;;; 694 ;;;
712 ;;; Generic index gathering function. 695 ;;; Generic index gathering function.
713 ;;; 696 ;;;
714 697
715 (defvar imenu-case-fold-search t 698 (defvar imenu-case-fold-search t
722 (make-variable-buffer-local 'imenu-case-fold-search) 705 (make-variable-buffer-local 'imenu-case-fold-search)
723 706
724 ;; This function can be called with quitting disabled, 707 ;; This function can be called with quitting disabled,
725 ;; so it needs to be careful never to loop! 708 ;; so it needs to be careful never to loop!
726 (defun imenu--generic-function (patterns) 709 (defun imenu--generic-function (patterns)
727 "Return an index of the current buffer as an alist. 710 "Return an index alist of the current buffer based on PATTERNS.
728 711
729 PATTERNS is an alist with elements that look like this: 712 PATTERNS is an alist with elements that look like this:
730 (MENU-TITLE REGEXP INDEX) 713 (MENU-TITLE REGEXP INDEX)
731 or like this: 714 or like this:
732 (MENU-TITLE REGEXP INDEX FUNCTION ARGUMENTS...) 715 (MENU-TITLE REGEXP INDEX FUNCTION ARGUMENTS...)
733 with zero or more ARGUMENTS. The former format creates a simple 716 with zero or more ARGUMENTS. The former format creates a simple
734 element in the index alist when it matches; the latter creates a 717 element in the index alist when it matches; the latter creates a
735 special element of the form (NAME POSITION-MARKER FUNCTION 718 special element of the form (INDEX-NAME POSITION-MARKER FUNCTION
736 ARGUMENTS...) with FUNCTION and ARGUMENTS copied from 719 ARGUMENTS...) with FUNCTION and ARGUMENTS copied from PATTERNS.
737 `imenu-generic-expression'.
738 720
739 MENU-TITLE is a string used as the title for the submenu or nil 721 MENU-TITLE is a string used as the title for the submenu or nil
740 if the entries are not nested. 722 if the entries are not nested.
741 723
742 REGEXP is a regexp that should match a construct in the buffer 724 REGEXP is a regexp that should match a construct in the buffer