Mercurial > emacs
comparison lisp/imenu.el @ 16271:00bece0cd6c2
(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.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 21 Sep 1996 22:32:10 +0000 |
parents | 2d2356e78b9e |
children | b64d00e44e7b |
comparison
equal
deleted
inserted
replaced
16270:4547dae187e9 | 16271:00bece0cd6c2 |
---|---|
120 "The regex pattern to use for creating a buffer index. | 120 "The regex pattern to use for creating a buffer index. |
121 | 121 |
122 If non-nil this pattern is passed to `imenu-create-index-with-pattern' | 122 If non-nil this pattern is passed to `imenu-create-index-with-pattern' |
123 to create a buffer index. | 123 to create a buffer index. |
124 | 124 |
125 It is an alist with elements that look like this: (MENU-TITLE | 125 The value should be an alist with elements that look like this: |
126 REGEXP INDEX). | 126 (MENU-TITLE REGEXP INDEX) |
127 or like this: | |
128 (MENU-TITLE REGEXP INDEX FUNCTION ARGUMENTS...) | |
129 with zero or more ARGUMENTS. The former format creates a simple element in | |
130 the index alist when it matches; the latter creates a special element | |
131 of the form (NAME FUNCTION NAME POSITION-MARKER ARGUMENTS...) | |
132 with FUNCTION and ARGUMENTS beiong copied from `imenu-generic-expression'. | |
127 | 133 |
128 MENU-TITLE is a string used as the title for the submenu or nil if the | 134 MENU-TITLE is a string used as the title for the submenu or nil if the |
129 entries are not nested. | 135 entries are not nested. |
130 | 136 |
131 REGEXP is a regexp that should match a construct in the buffer that is | 137 REGEXP is a regexp that should match a construct in the buffer that is |
151 | 157 |
152 (defvar imenu-create-index-function 'imenu-default-create-index-function | 158 (defvar imenu-create-index-function 'imenu-default-create-index-function |
153 "The function to use for creating a buffer index. | 159 "The function to use for creating a buffer index. |
154 | 160 |
155 It should be a function that takes no arguments and returns an index | 161 It should be a function that takes no arguments and returns an index |
156 of the current buffer as an alist. The elements in the alist look | 162 of the current buffer as an alist. |
157 like: (INDEX-NAME . INDEX-POSITION). You may also nest index list like | 163 |
158 \(INDEX-NAME . INDEX-ALIST). | 164 Simple elements in the alist look like (INDEX-NAME . INDEX-POSITION). |
165 Special elements look like (INDEX-NAME FUNCTION ARGUMENTS...). | |
166 A nested sub-alist element looks like (INDEX-NAME SUB-ALIST). | |
167 The function `imenu--subalist-p' tests an element and returns t | |
168 if it is a sub-alist. | |
159 | 169 |
160 This function is called within a `save-excursion'. | 170 This function is called within a `save-excursion'. |
161 | 171 |
162 The variable is buffer-local.") | 172 The variable is buffer-local.") |
163 (make-variable-buffer-local 'imenu-create-index-function) | 173 (make-variable-buffer-local 'imenu-create-index-function) |
178 "Function for extracting the index name. | 188 "Function for extracting the index name. |
179 | 189 |
180 This function is called after the function pointed out by | 190 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) |
193 | |
194 (defun imenu--subalist-p (item) | |
195 (and (consp (cdr item)) (listp (cadr item)) | |
196 (not (eq (caadr item) 'lambda)))) | |
183 | 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. |
187 ;;; If RELPOS is nil, then the relative position in the buffer | 201 ;;; If RELPOS is nil, then the relative position in the buffer |
460 (function | 474 (function |
461 (lambda (item) | 475 (lambda (item) |
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)) |
469 | 483 |
470 (defun imenu--create-keymap-2 (alist counter &optional commands) | 484 (defun imenu--create-keymap-2 (alist counter &optional commands) |
471 (let ((map nil)) | 485 (let ((map nil)) |
472 (mapcar | 486 (mapcar |
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))) |
480 (t | 494 (t |
481 (let ((end (if commands `(lambda () (interactive) | 495 (let ((end (if commands `(lambda () (interactive) |
635 (mapcar | 649 (mapcar |
636 (function | 650 (function |
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))) |
657 (nconc (delq main-element (delq 'dummy index-alist)) main-element)))) | 678 (nconc (delq main-element (delq 'dummy index-alist)) main-element)))) |
658 | 679 |
698 nil) | 719 nil) |
699 ((string= name (car imenu--rescan-item)) | 720 ((string= name (car imenu--rescan-item)) |
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 |
707 (defun imenu--mouse-menu (index-alist event &optional title) | 728 (defun imenu--mouse-menu (index-alist event &optional title) |
708 "Let the user select from a buffer index from a mouse menu. | 729 "Let the user select from a buffer index from a mouse menu. |
855 (if (or (< (marker-position (cdr index-item)) (point-min)) | 876 (if (or (< (marker-position (cdr index-item)) (point-min)) |
856 (> (marker-position (cdr index-item)) (point-max))) | 877 (> (marker-position (cdr index-item)) (point-max))) |
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 |
869 ;;; imenu.el ends here | 895 ;;; imenu.el ends here |