aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1996-09-21 22:32:10 +0000
committerRichard M. Stallman1996-09-21 22:32:10 +0000
commit215b077e2ffb6442b0072802186f02055fe88541 (patch)
treeeef3686b0b6606e80caafd90801d54fab0327d9a
parenta321144195204a81e0eb326066852b11bf1484ce (diff)
downloademacs-215b077e2ffb6442b0072802186f02055fe88541.tar.gz
emacs-215b077e2ffb6442b0072802186f02055fe88541.zip
(imenu--generic-function): Create a special entry
if the element of imenu-generic-function asks for it. (imenu): Handle special entries. (imenu--submenu-p): New function. Use in various places.
-rw-r--r--lisp/imenu.el74
1 files changed, 50 insertions, 24 deletions
diff --git a/lisp/imenu.el b/lisp/imenu.el
index 876f6f2f061..6cefcfdfdb4 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -122,8 +122,14 @@ with name concatenation.")
122If non-nil this pattern is passed to `imenu-create-index-with-pattern' 122If non-nil this pattern is passed to `imenu-create-index-with-pattern'
123to create a buffer index. 123to create a buffer index.
124 124
125It is an alist with elements that look like this: (MENU-TITLE 125The value should be an alist with elements that look like this:
126REGEXP INDEX). 126 (MENU-TITLE REGEXP INDEX)
127or like this:
128 (MENU-TITLE REGEXP INDEX FUNCTION ARGUMENTS...)
129with zero or more ARGUMENTS. The former format creates a simple element in
130the index alist when it matches; the latter creates a special element
131of the form (NAME FUNCTION NAME POSITION-MARKER ARGUMENTS...)
132with FUNCTION and ARGUMENTS beiong copied from `imenu-generic-expression'.
127 133
128MENU-TITLE is a string used as the title for the submenu or nil if the 134MENU-TITLE is a string used as the title for the submenu or nil if the
129entries are not nested. 135entries are not nested.
@@ -153,9 +159,13 @@ The variable is buffer-local.")
153 "The function to use for creating a buffer index. 159 "The function to use for creating a buffer index.
154 160
155It should be a function that takes no arguments and returns an index 161It should be a function that takes no arguments and returns an index
156of the current buffer as an alist. The elements in the alist look 162of the current buffer as an alist.
157like: (INDEX-NAME . INDEX-POSITION). You may also nest index list like 163
158\(INDEX-NAME . INDEX-ALIST). 164Simple elements in the alist look like (INDEX-NAME . INDEX-POSITION).
165Special elements look like (INDEX-NAME FUNCTION ARGUMENTS...).
166A nested sub-alist element looks like (INDEX-NAME SUB-ALIST).
167The function `imenu--subalist-p' tests an element and returns t
168 if it is a sub-alist.
159 169
160This function is called within a `save-excursion'. 170This function is called within a `save-excursion'.
161 171
@@ -181,6 +191,10 @@ This function is called after the function pointed out by
181`imenu-prev-index-position-function'.") 191`imenu-prev-index-position-function'.")
182(make-variable-buffer-local 'imenu-extract-index-name-function) 192(make-variable-buffer-local 'imenu-extract-index-name-function)
183 193
194(defun imenu--subalist-p (item)
195 (and (consp (cdr item)) (listp (cadr item))
196 (not (eq (caadr item) 'lambda))))
197
184;;; 198;;;
185;;; Macro to display a progress message. 199;;; Macro to display a progress message.
186;;; RELPOS is the relative position to display. 200;;; RELPOS is the relative position to display.
@@ -462,7 +476,7 @@ This function is called after the function pointed out by
462 (cond 476 (cond
463 ((markerp (cdr item)) 477 ((markerp (cdr item))
464 (set-marker (cdr item) nil)) 478 (set-marker (cdr item) nil))
465 ((consp (cdr item)) 479 ((imenu--subalist-p item)
466 (imenu--cleanup (cdr item)))))) 480 (imenu--cleanup (cdr item))))))
467 alist) 481 alist)
468 t)) 482 t))
@@ -473,7 +487,7 @@ This function is called after the function pointed out by
473 (function 487 (function
474 (lambda (item) 488 (lambda (item)
475 (cond 489 (cond
476 ((listp (cdr item)) 490 ((imenu--subalist-p item)
477 (append (list (setq counter (1+ counter)) 491 (append (list (setq counter (1+ counter))
478 (car item) 'keymap (car item)) 492 (car item) 'keymap (car item))
479 (imenu--create-keymap-2 (cdr item) (+ counter 10) commands))) 493 (imenu--create-keymap-2 (cdr item) (+ counter 10) commands)))
@@ -637,20 +651,27 @@ pattern.
637 (lambda (pat) 651 (lambda (pat)
638 (let ((menu-title (car pat)) 652 (let ((menu-title (car pat))
639 (regexp (cadr pat)) 653 (regexp (cadr pat))
640 (index (caddr pat))) 654 (index (caddr pat))
641 (if (and (not found) ; Only allow one entry; 655 (function (cadddr pat))
642 (looking-at regexp)) 656 (rest (cddddr pat)))
643 (let ((beg (make-marker)) 657 (if (and (not found) ; Only allow one entry;
644 (end (match-end index))) 658 (looking-at regexp))
645 (set-marker beg (match-beginning index)) 659 (let ((beg (make-marker))
646 (setq found t) 660 (end (match-end index)))
647 (push 661 (set-marker beg (match-beginning index))
648 (cons (buffer-substring-no-properties beg end) beg) 662 (setq found t)
649 (cdr 663 (push
650 (or (assoc menu-title index-alist) 664 (let ((name
651 (car (push 665 (buffer-substring-no-properties beg end)))
652 (cons menu-title '()) 666 (if function
653 index-alist)))))))))) 667 (nconc (list name function name beg)
668 rest)
669 (cons name beg)))
670 (cdr
671 (or (assoc menu-title index-alist)
672 (car (push
673 (cons menu-title '())
674 index-alist))))))))))
654 patterns)))) 675 patterns))))
655 (imenu-progress-message prev-pos 100 t) 676 (imenu-progress-message prev-pos 100 t)
656 (let ((main-element (assq nil index-alist))) 677 (let ((main-element (assq nil index-alist)))
@@ -700,7 +721,7 @@ Returns t for rescan and otherwise a position number."
700 t) 721 t)
701 (t 722 (t
702 (setq choice (assoc name prepared-index-alist)) 723 (setq choice (assoc name prepared-index-alist))
703 (if (listp (cdr choice)) 724 (if (imenu--subalist-p choice)
704 (imenu--completion-buffer (cdr choice) prompt) 725 (imenu--completion-buffer (cdr choice) prompt)
705 choice))))) 726 choice)))))
706 727
@@ -857,12 +878,17 @@ See `imenu-choose-buffer-index' for more information."
857 ;; widen if outside narrowing 878 ;; widen if outside narrowing
858 (widen)) 879 (widen))
859 (goto-char (marker-position (cdr index-item)))) 880 (goto-char (marker-position (cdr index-item))))
860 (t 881 ((imenu--subalist-p index-item)
861 (if (or (< (cdr index-item) (point-min)) 882 (if (or (< (cdr index-item) (point-min))
862 (> (cdr index-item) (point-max))) 883 (> (cdr index-item) (point-max)))
863 ;; widen if outside narrowing 884 ;; widen if outside narrowing
864 (widen)) 885 (widen))
865 (goto-char (cdr index-item))))))) 886 (goto-char (cdr index-item)))
887 (t
888 ;; A special item with a function.
889 (let ((function (cadr index-item))
890 (rest (cddr index-item)))
891 (apply function (car index-item) rest)))))))
866 892
867(provide 'imenu) 893(provide 'imenu)
868 894