Mercurial > emacs
annotate lisp/imenu.el @ 10198:aa59550d809f
Include program name in error messages.
author | David J. MacKenzie <djm@gnu.org> |
---|---|
date | Wed, 21 Dec 1994 15:58:28 +0000 |
parents | caafb376e619 |
children | 34b66bff7aec |
rev | line source |
---|---|
6230 | 1 ;;; imenu.el --- Framework for mode-specific buffer indexes. |
2 | |
3 ;; Copyright (C) 1994 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Ake Stenhoff <etxaksf@aom.ericsson.se> | |
6 ;; Lars Lindberg <lli@sypro.cap.se> | |
7 ;; Created: 8 Feb 1994 | |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
8 ;; Version: 1.14 |
6230 | 9 ;; Keywords: tools |
10 ;; | |
11 ;; This program is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 ;; | |
16 ;; This program is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 ;; | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with this program; if not, write to the Free Software | |
23 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 | |
25 ;;; Commentary: | |
26 ;; | |
27 ;; Purpose of this package: | |
28 ;; To present a framework for mode-specific buffer indexes. | |
29 ;; A buffer index is an alist of names and buffer positions. | |
30 ;; For instance all functions in a C-file and their positions. | |
31 ;; | |
32 ;; How it works: | |
33 | |
34 ;; A mode-specific function is called to generate the index. It is | |
35 ;; then presented to the user, who can choose from this index. | |
36 ;; | |
37 ;; The package comes with a set of example functions for how to | |
38 ;; utilize this package. | |
39 | |
40 ;; There are *examples* for index gathering functions for C/C++ and | |
41 ;; Lisp/Emacs Lisp but it is easy to customize for other modes. A | |
42 ;; function for jumping to the chosen index position is also | |
43 ;; supplied. | |
44 | |
6241 | 45 ;;; Thanks goes to |
46 ;; [simon] - Simon Leinen simon@lia.di.epfl.ch | |
47 ;; [dean] - Dean Andrews ada@unison.com | |
8408
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
48 ;; [alon] - Alon Albert al@mercury.co.il |
9176
5646f9ac8ec3
(imenu--cleanup): Changed 'mapc' to 'mapcar'.
Richard M. Stallman <rms@gnu.org>
parents:
8408
diff
changeset
|
49 ;; [greg] - Greg Thompson gregt@porsche.visix.COM |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
50 ;; [wolfgang] - Wolfgang Bangerth zcg51122@rpool1.rus.uni-stuttgart.de |
10072
a7b70665c937
(imenu): Widen temporary before scan the file.
Richard M. Stallman <rms@gnu.org>
parents:
9176
diff
changeset
|
51 ;; [kai] - Kai Grossjohann grossjoh@linus.informatik.uni-dortmund.de |
6241 | 52 |
6230 | 53 ;;; Code |
6909
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
54 (eval-when-compile (require 'cl)) |
6230 | 55 |
56 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
57 ;;; | |
58 ;;; Customizable variables | |
59 ;;; | |
60 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
61 | |
62 (defvar imenu-always-use-completion-buffer-p nil | |
63 "*Set this to non-nil for displaying the index in a completion buffer. | |
64 | |
65 Non-nil means always display the index in a completion buffer. | |
66 Nil means display the index as a mouse menu when the mouse was | |
7319
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
67 used to invoke `imenu'.") |
6230 | 68 |
69 (defvar imenu-sort-function nil | |
70 "*The function to use for sorting the index mouse-menu. | |
71 | |
72 Affects only the mouse index menu. | |
73 | |
74 Set this to nil if you don't want any sorting (faster). | |
75 The items in the menu are then presented in the order they were found | |
76 in the buffer. | |
77 | |
6909
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
78 Set it to `imenu--sort-by-name' if you want alphabetic sorting. |
6230 | 79 |
80 The function should take two arguments and return T if the first | |
81 element should come before the second. The arguments are cons cells; | |
7639 | 82 \(NAME . POSITION). Look at `imenu--sort-by-name' for an example.") |
6230 | 83 |
84 (defvar imenu-max-items 25 | |
85 "*Maximum number of elements in an index mouse-menu.") | |
86 | |
87 (defvar imenu-scanning-message "Scanning buffer for index. (%3d%%)" | |
88 "*Progress message during the index scanning of the buffer. | |
8296
b2b493c007ff
(imenu-choose-buffer-index): Use last-nonmenu-event
Richard M. Stallman <rms@gnu.org>
parents:
8256
diff
changeset
|
89 If non-nil, user gets a message during the scanning of the buffer |
6230 | 90 |
91 Relevant only if the mode-specific function that creates the buffer | |
6909
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
92 index use `imenu-progress-message'.") |
6230 | 93 |
94 (defvar imenu-space-replacement "^" | |
95 "*The replacement string for spaces in index names. | |
96 Used when presenting the index in a completion-buffer to make the | |
97 names work as tokens.") | |
98 | |
99 (defvar imenu-level-separator ":" | |
100 "*The separator between index names of different levels. | |
101 Used for making mouse-menu titles and for flattening nested indexes | |
102 with name concatenation.") | |
103 | |
104 (defvar imenu-submenu-name-format "%s..." | |
105 "*The format for making a submenu name.") | |
106 | |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
107 (defvar imenu-generic-expression nil |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
108 "Generic regular expression for index gathering. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
109 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
110 Can be either an regular expression or an alist in the form |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
111 \(REGEXP PAREN).") |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
112 (make-variable-buffer-local 'imenu-generic-expression) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
113 |
6230 | 114 ;;;; Hooks |
115 | |
116 (defvar imenu-create-index-function 'imenu-default-create-index-function | |
117 "The function to use for creating a buffer index. | |
118 | |
119 It should be a function that takes no arguments and returns an index | |
120 of the current buffer as an alist. The elements in the alist look | |
121 like: (INDEX-NAME . INDEX-POSITION). You may also nest index list like | |
7639 | 122 \(INDEX-NAME . INDEX-ALIST). |
6230 | 123 |
6909
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
124 This function is called within a `save-excursion'. |
6230 | 125 |
126 The variable is buffer-local.") | |
127 (make-variable-buffer-local 'imenu-create-index-function) | |
128 | |
7319
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
129 (defvar imenu-prev-index-position-function 'beginning-of-defun |
6230 | 130 "Function for finding the next index position. |
131 | |
6909
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
132 If `imenu-create-index-function' is set to |
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
133 `imenu-default-create-index-function', then you must set this variable |
6230 | 134 to a function that will find the next index, looking backwards in the |
135 file. | |
136 | |
137 The function should leave point at the place to be connected to the | |
138 index and it should return nil when it doesn't find another index. ") | |
7319
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
139 (make-variable-buffer-local 'imenu-prev-index-position-function) |
6230 | 140 |
7319
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
141 (defvar imenu-extract-index-name-function nil |
6230 | 142 "Function for extracting the index name. |
143 | |
144 This function is called after the function pointed out by | |
7319
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
145 `imenu-prev-index-position-function'.") |
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
146 (make-variable-buffer-local 'imenu-extract-index-name-function) |
6230 | 147 |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
148 ;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
149 ;;; Macro to display a progress message. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
150 ;;; RELPOS is the relative position to display. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
151 ;;; If RELPOS is nil, then the relative position in the buffer |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
152 ;;; is calculated. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
153 ;;; PREVPOS is the variable in which we store the last position displayed. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
154 (defmacro imenu-progress-message (prevpos &optional relpos reverse) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
155 (` (and |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
156 imenu-scanning-message |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
157 (let ((pos (, (if relpos |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
158 relpos |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
159 (` (imenu--relative-position (, reverse))))))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
160 (if (, (if relpos t |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
161 (` (> pos (+ 5 (, prevpos)))))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
162 (progn |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
163 (message imenu-scanning-message pos) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
164 (setq (, prevpos) pos))))))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
165 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
166 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
167 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
168 ;;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
169 ;;;; Some examples of functions utilizing the framework of this |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
170 ;;;; package. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
171 ;;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
172 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
173 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
174 ;; Return the current/previous sexp and the location of the sexp (it's |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
175 ;; beginning) without moving the point. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
176 (defun imenu-example--name-and-position () |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
177 (save-excursion |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
178 (forward-sexp -1) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
179 (let ((beg (point)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
180 (end (progn (forward-sexp) (point))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
181 (marker (make-marker))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
182 (set-marker marker beg) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
183 (cons (buffer-substring beg end) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
184 marker)))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
185 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
186 ;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
187 ;;; Lisp |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
188 ;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
189 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
190 (defun imenu-example--lisp-extract-index-name () |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
191 ;; Example of a candidate for `imenu-extract-index-name-function'. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
192 ;; This will generate a flat index of definitions in a lisp file. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
193 (save-match-data |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
194 (and (looking-at "(def") |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
195 (condition-case nil |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
196 (progn |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
197 (down-list 1) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
198 (forward-sexp 2) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
199 (let ((beg (point)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
200 (end (progn (forward-sexp -1) (point)))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
201 (buffer-substring beg end))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
202 (error nil))))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
203 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
204 (defun imenu-example--create-lisp-index () |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
205 ;; Example of a candidate for `imenu-create-index-function'. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
206 ;; It will generate a nested index of definitions. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
207 (let ((index-alist '()) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
208 (index-var-alist '()) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
209 (index-type-alist '()) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
210 (index-unknown-alist '()) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
211 prev-pos) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
212 (goto-char (point-max)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
213 (imenu-progress-message prev-pos 0) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
214 ;; Search for the function |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
215 (while (beginning-of-defun) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
216 (imenu-progress-message prev-pos nil t) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
217 (save-match-data |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
218 (and (looking-at "(def") |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
219 (save-excursion |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
220 (down-list 1) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
221 (cond |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
222 ((looking-at "def\\(var\\|const\\)") |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
223 (forward-sexp 2) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
224 (push (imenu-example--name-and-position) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
225 index-var-alist)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
226 ((looking-at "def\\(un\\|subst\\|macro\\|advice\\)") |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
227 (forward-sexp 2) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
228 (push (imenu-example--name-and-position) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
229 index-alist)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
230 ((looking-at "def\\(type\\|struct\\|class\\|ine-condition\\)") |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
231 (forward-sexp 2) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
232 (if (= (char-after (1- (point))) ?\)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
233 (progn |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
234 (forward-sexp -1) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
235 (down-list 1) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
236 (forward-sexp 1))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
237 (push (imenu-example--name-and-position) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
238 index-type-alist)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
239 (t |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
240 (forward-sexp 2) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
241 (push (imenu-example--name-and-position) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
242 index-unknown-alist))))))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
243 (imenu-progress-message prev-pos 100) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
244 (and index-var-alist |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
245 (push (cons (imenu-create-submenu-name "Variables") index-var-alist) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
246 index-alist)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
247 (and index-type-alist |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
248 (push (cons (imenu-create-submenu-name "Types") index-type-alist) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
249 index-alist)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
250 (and index-unknown-alist |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
251 (push (cons (imenu-create-submenu-name "Syntax-unknown") index-unknown-alist) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
252 index-alist)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
253 index-alist)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
254 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
255 ;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
256 ;;; C |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
257 ;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
258 ;; Regular expression to find C functions |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
259 (defvar imenu-example--function-name-regexp-c |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
260 (concat |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
261 "^[a-zA-Z0-9]+[ \t]?" ; type specs; there can be no |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
262 "\\([a-zA-Z0-9_*]+[ \t]+\\)?" ; more than 3 tokens, right? |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
263 "\\([a-zA-Z0-9_*]+[ \t]+\\)?" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
264 "\\([*&]+[ \t]*\\)?" ; pointer |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
265 "\\([a-zA-Z0-9_*]+\\)[ \t]*(" ; name |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
266 )) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
267 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
268 (defun imenu-example--create-c-index (&optional regexp) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
269 (let ((index-alist '()) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
270 prev-pos char) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
271 (goto-char (point-min)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
272 (imenu-progress-message prev-pos 0) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
273 ;; Search for the function |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
274 (save-match-data |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
275 (while (re-search-forward |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
276 (or regexp imenu-example--function-name-regexp-c) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
277 nil t) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
278 (imenu-progress-message prev-pos) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
279 (backward-up-list 1) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
280 (save-excursion |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
281 (goto-char (scan-sexps (point) 1)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
282 (setq char (following-char))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
283 ;; Skip this function name if it is a prototype declaration. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
284 (if (not (eq char ?\;)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
285 (push (imenu-example--name-and-position) index-alist)))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
286 (imenu-progress-message prev-pos 100) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
287 (nreverse index-alist))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
288 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
289 ;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
290 ;;; C++ |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
291 ;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
292 ;; Example of an imenu-generic-expression |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
293 ;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
294 (defvar imenu-example--generic-c++-expression |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
295 (cons |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
296 ;; regular expression |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
297 (concat |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
298 "^" ; beginning of line is required |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
299 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
300 "\\(" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
301 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
302 "\\(" ; >>looking for a function definition<< |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
303 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
304 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right? |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
305 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
306 "\\(" ; last type spec including */& |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
307 "[a-zA-Z0-9_:]+" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
308 "\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either pointer/ref sign or whitespace |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
309 "\\)?" ; if there is a last type spec |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
310 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
311 "\\(" ; name; take that into the imenu entry |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
312 "[a-zA-Z0-9_:~]+" ; member function, ctor or dtor... |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
313 ; (may not contain * because then |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
314 ; "a::operator char*" would become "char*"!) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
315 "\\|" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
316 "\\([a-zA-Z0-9_:~]*::\\)?operator" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
317 "[^a-zA-Z1-9_][^(]*" ; ...or operator |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
318 " \\)" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
319 "[ \t]*([^)]*)[ \t\n]*[^ ;]" ; require something other than a ; after |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
320 ; the (...) to avoid prototypes. Can't |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
321 ; catch cases with () inside the parentheses |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
322 ; surrounding the parameters |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
323 ; (like "int foo(int a=bar()) {...}" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
324 "\\)" ; <<looking for a function definition>> |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
325 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
326 "\\|" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
327 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
328 "\\(" ; >>class decl<< |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
329 "\\(class[ \t]+[a-zA-Z0-9_]+\\)" ; this is the string we want to get |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
330 "[ \t]*[:{]" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
331 "\\)" ; <<class decl>> |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
332 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
333 "\\)") |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
334 ;; paren |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
335 (list 8 11)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
336 "imenu generic expression for C++ mode in the form |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
337 \(REGEXP PAR).") |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
338 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
339 ;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
340 ;;; TexInfo |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
341 ;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
342 ;; Written by Wolfgang Bangerth <zcg51122@rpool1.rus.uni-stuttgart.de> |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
343 ;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
344 ;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
345 (defvar imenu-example--generic-texinfo-expression |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
346 (cons |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
347 (concat |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
348 "^@node[ \t]+" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
349 "\\([^,\n]*\\)") |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
350 (list 1)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
351 "imenu generic expression for TexInfo mode in the form |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
352 \(REGEXP PAR). |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
353 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
354 To overide this example, Either set 'imenu-generic-expression |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
355 or 'imenu-create-index-function") |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
356 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
357 ;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
358 ;;; LaTex |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
359 ;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
360 ;; Written by Wolfgang Bangerth <zcg51122@rpool1.rus.uni-stuttgart.de> |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
361 ;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
362 ;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
363 (defvar imenu-example--generic-latex-expression |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
364 (concat |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
365 "\\(" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
366 "%[ \t]*[0-9]+\\.[0-9]+[,;]?[ \t]?" ; i put numbers like 3.15 before my |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
367 ; \begin{equation}'s which tell me |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
368 ; the number the equation will get when |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
369 ; being printed. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
370 "\\|" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
371 "\\\\part{[^}]*}" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
372 "\\|" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
373 "\\\\chapter{[^}]*}" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
374 "\\|" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
375 "\\\\[a-zA-Z]*section{[^}]*}" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
376 "\\)") |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
377 "imenu generic expression for LaTex mode in the form |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
378 \"REGEXP\".") |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
379 |
6230 | 380 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
381 ;;; | |
382 ;;; Internal variables | |
383 ;;; | |
384 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
385 | |
386 ;; The item to use in the index for rescanning the buffer. | |
387 (defconst imenu--rescan-item '("*Rescan*" . -99)) | |
388 | |
389 ;; The latest buffer index. | |
390 ;; Buffer local. | |
391 (defvar imenu--index-alist nil) | |
392 (make-variable-buffer-local 'imenu--index-alist) | |
393 | |
394 ;; History list for 'jump-to-function-in-buffer'. | |
395 ;; Buffer local. | |
396 (defvar imenu--history-list nil) | |
397 (make-variable-buffer-local 'imenu--history-list) | |
398 | |
399 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
400 ;;; | |
401 ;;; Internal support functions | |
402 ;;; | |
403 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
404 | |
405 ;;; | |
406 ;;; Sort function | |
407 ;;; Sorts the items depending on their index name. | |
408 ;;; An item look like (NAME . POSITION). | |
409 ;;; | |
410 (defun imenu--sort-by-name (item1 item2) | |
411 (string-lessp (car item1) (car item2))) | |
412 | |
413 (defun imenu--relative-position (&optional reverse) | |
414 ;; Support function to calculate relative position in buffer | |
415 ;; Beginning of buffer is 0 and end of buffer is 100 | |
416 ;; If REVERSE is non-nil then the beginning is 100 and the end is 0. | |
417 (let ((pos (point)) | |
418 (total (buffer-size))) | |
419 (and reverse (setq pos (- total pos))) | |
420 (if (> total 50000) | |
421 ;; Avoid overflow from multiplying by 100! | |
422 (/ (1- pos) (max (/ total 100) 1)) | |
423 (/ (* 100 (1- pos)) (max total 1))))) | |
424 | |
425 ;;; | |
426 ;;; Function for suporting general looking submenu names. | |
6909
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
427 ;;; Uses `imenu-submenu-name-format' for creating the name. |
6230 | 428 ;;; NAME is the base of the new submenu name. |
429 ;;; | |
430 (defun imenu-create-submenu-name (name) | |
431 (format imenu-submenu-name-format name)) | |
432 | |
433 ;; Split LIST into sublists of max length N. | |
434 ;; Example (imenu--split '(1 2 3 4 5 6 7 8) 3)-> '((1 2 3) (4 5 6) (7 8)) | |
435 (defun imenu--split (list n) | |
436 (let ((remain list) | |
437 (result '()) | |
438 (sublist '()) | |
439 (i 0)) | |
440 (while remain | |
441 (push (pop remain) sublist) | |
442 (incf i) | |
443 (and (= i n) | |
444 ;; We have finished a sublist | |
445 (progn (push (nreverse sublist) result) | |
446 (setq i 0) | |
447 (setq sublist '())))) | |
448 ;; There might be a sublist (if the length of LIST mod n is != 0) | |
449 ;; that has to be added to the result list. | |
450 (and sublist | |
451 (push (nreverse sublist) result)) | |
452 (nreverse result))) | |
453 | |
454 ;;; | |
455 ;;; Split a menu in to several menus. | |
456 ;;; | |
457 (defun imenu--split-menu (menulist title) | |
458 (cons "Function menus" | |
459 (mapcar | |
460 (function | |
461 (lambda (menu) | |
462 (cons (format "(%s)" title) menu))) | |
463 (imenu--split menulist imenu-max-items)))) | |
464 | |
465 ;;; | |
466 ;;; Find all items in this buffer that should be in the index. | |
467 ;;; Returns an alist on the form | |
468 ;;; ((NAME . POSITION) (NAME . POSITION) ...) | |
469 ;;; | |
470 | |
471 (defun imenu--make-index-alist () | |
472 ;; Create a list for this buffer only when needed. | |
473 (or imenu--index-alist | |
474 ;; Get the index | |
475 (setq imenu--index-alist | |
476 (save-excursion | |
477 (funcall imenu-create-index-function)))) | |
478 (or imenu--index-alist | |
479 (error "No items suitable for an index found in this buffer.")) | |
480 ;; Add a rescan option to the index. | |
481 (cons imenu--rescan-item imenu--index-alist)) | |
8408
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
482 ;;; |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
483 ;;; Find all markers in alist and makes |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
484 ;;; them point nowhere. |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
485 ;;; |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
486 (defun imenu--cleanup (&optional alist) |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
487 ;; Sets the markers in imenu--index-alist |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
488 ;; point nowhere. |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
489 ;; if alist is provided use that list. |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
490 (and imenu--index-alist |
9176
5646f9ac8ec3
(imenu--cleanup): Changed 'mapc' to 'mapcar'.
Richard M. Stallman <rms@gnu.org>
parents:
8408
diff
changeset
|
491 (mapcar |
8408
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
492 (function |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
493 (lambda (item) |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
494 (cond |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
495 ((markerp (cdr item)) |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
496 (set-marker (cdr item) nil)) |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
497 ((listp (cdr item)) |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
498 (imenu--cleanup (cdr item)))))) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
499 (if alist alist imenu--index-alist)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
500 t)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
501 |
6230 | 502 (defun imenu-default-create-index-function () |
503 "*Wrapper for index searching functions. | |
504 | |
505 Moves point to end of buffer and then repeatedly calls | |
7319
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
506 `imenu-prev-index-position-function' and `imenu-extract-index-name-function'. |
6230 | 507 Their results are gathered into an index alist." |
7350
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
508 ;; These should really be done by setting imenu-create-index-function |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
509 ;; in these major modes. But save that change for later. |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
510 (cond ((and (fboundp imenu-prev-index-position-function) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
511 (fboundp imenu-extract-index-name-function)) |
7350
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
512 (let ((index-alist '()) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
513 prev-pos name) |
7350
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
514 (goto-char (point-max)) |
8296
b2b493c007ff
(imenu-choose-buffer-index): Use last-nonmenu-event
Richard M. Stallman <rms@gnu.org>
parents:
8256
diff
changeset
|
515 (imenu-progress-message prev-pos 0 t) |
7350
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
516 ;; Search for the function |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
517 (while (funcall imenu-prev-index-position-function) |
8296
b2b493c007ff
(imenu-choose-buffer-index): Use last-nonmenu-event
Richard M. Stallman <rms@gnu.org>
parents:
8256
diff
changeset
|
518 (imenu-progress-message prev-pos nil t) |
7350
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
519 (save-excursion |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
520 (setq name (funcall imenu-extract-index-name-function))) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
521 (and (stringp name) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
522 (push (cons name (point)) index-alist))) |
8296
b2b493c007ff
(imenu-choose-buffer-index): Use last-nonmenu-event
Richard M. Stallman <rms@gnu.org>
parents:
8256
diff
changeset
|
523 (imenu-progress-message prev-pos 100 t) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
524 index-alist)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
525 ;; Use generic expression if possible. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
526 ((and imenu-generic-expression) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
527 (imenu--generic-function imenu-generic-expression)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
528 ;; Use supplied example functions |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
529 ((eq major-mode 'emacs-lisp-mode) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
530 (imenu-example--create-lisp-index)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
531 ((eq major-mode 'lisp-mode) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
532 (imenu-example--create-lisp-index)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
533 ((eq major-mode 'c++-mode) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
534 (imenu--generic-function imenu-example--generic-c++-expression)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
535 ((eq major-mode 'c-mode) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
536 (imenu-example--create-c-index)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
537 ((eq major-mode 'latex-mode) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
538 (imenu--generic-function imenu-example--generic-latex-expression)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
539 ((eq major-mode 'texinfo-mode) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
540 (imenu--generic-function imenu-example--generic-texinfo-expression)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
541 (t |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
542 (error "The mode \"%s\" does not take full advantage of imenu.el yet." |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
543 mode-name)))) |
6230 | 544 |
545 (defun imenu--replace-spaces (name replacement) | |
546 ;; Replace all spaces in NAME with REPLACEMENT. | |
547 ;; That second argument should be a string. | |
548 (mapconcat | |
549 (function | |
550 (lambda (ch) | |
551 (if (char-equal ch ?\ ) | |
552 replacement | |
553 (char-to-string ch)))) | |
554 name | |
555 "")) | |
556 | |
557 (defun imenu--flatten-index-alist (index-alist &optional concat-names prefix) | |
558 ;; Takes a nested INDEX-ALIST and returns a flat index alist. | |
559 ;; If optional CONCAT-NAMES is non-nil, then a nested index has its | |
560 ;; name and a space concatenated to the names of the children. | |
561 ;; Third argument PREFIX is for internal use only. | |
562 (mapcan | |
563 (function | |
564 (lambda (item) | |
565 (let* ((name (car item)) | |
566 (pos (cdr item)) | |
567 (new-prefix (and concat-names | |
568 (if prefix | |
569 (concat prefix imenu-level-separator name) | |
570 name)))) | |
571 (cond | |
8408
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
572 ((or (markerp pos) (numberp pos)) |
6230 | 573 (list (cons new-prefix pos))) |
574 (t | |
575 (imenu--flatten-index-alist pos new-prefix)))))) | |
576 index-alist)) | |
577 | |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
578 ;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
579 ;;; Generic index gathering function. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
580 ;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
581 (defun imenu--generic-extract-name (paren) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
582 (let ((numofpar (1- (length paren))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
583 (parencount 0) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
584 (par) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
585 (index)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
586 ;; Try until we get a match |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
587 (beginning-of-line) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
588 (while (and (<= parencount numofpar) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
589 (setq par (nth parencount paren)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
590 (equal (match-beginning par) nil) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
591 (equal (match-end par) nil)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
592 (setq parencount (1+ parencount))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
593 (or (and |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
594 (<= parencount numofpar) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
595 (setq index (buffer-substring (match-beginning par) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
596 (match-end par)))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
597 ;; take the whole match just in case. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
598 (setq index (buffer-substring (match-beginning 0) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
599 (match-end 0)))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
600 index)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
601 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
602 (defun imenu--generic-function (exp) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
603 "Generic function for index gathering. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
604 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
605 EXP can be either an regular expression or an alist in the form |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
606 \(REGEXP PAREN). " |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
607 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
608 (let ((index-alist '()) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
609 (regexp nil) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
610 (paren nil) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
611 prev-pos name) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
612 (cond ((stringp exp) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
613 (setq regexp exp) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
614 (setq paren nil)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
615 ((listp exp) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
616 (setq regexp (car exp)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
617 (setq paren (cdr exp))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
618 (t |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
619 (error "Wrong type of argument."))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
620 (goto-char (point-max)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
621 (imenu-progress-message prev-pos 0 t) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
622 (while (re-search-backward regexp 1 t) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
623 (imenu-progress-message prev-pos nil t) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
624 (save-excursion |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
625 ;; If paren get sub expression |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
626 (or (and paren |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
627 (setq name (imenu--generic-extract-name paren))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
628 ;; get the whole expression |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
629 (beginning-of-line) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
630 (setq name (buffer-substring (match-beginning 0) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
631 (match-end 0))))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
632 (and (stringp name) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
633 (push (cons name (point)) index-alist))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
634 (imenu-progress-message prev-pos 100 t) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
635 index-alist)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
636 |
6230 | 637 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
638 ;;; | |
639 ;;; The main functions for this package! | |
640 ;;; | |
641 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
642 | |
643 (defun imenu--completion-buffer (index-alist &optional prompt) | |
644 "Let the user select from INDEX-ALIST in a completion buffer with PROMPT. | |
645 | |
646 Returns t for rescan and otherwise a position number." | |
647 ;; Create a list for this buffer only when needed. | |
648 (let (name choice | |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
649 (prepared-index-alist |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
650 (mapcar |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
651 (function |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
652 (lambda (item) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
653 (cons (imenu--replace-spaces (car item) imenu-space-replacement) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
654 (cdr item)))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
655 index-alist))) |
6230 | 656 (save-window-excursion |
657 ;; Display the completion buffer | |
658 (with-output-to-temp-buffer "*Completions*" | |
659 (display-completion-list | |
660 (all-completions "" prepared-index-alist ))) | |
7350
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
661 (let ((minibuffer-setup-hook |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
662 (function (lambda () |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
663 (let ((buffer (current-buffer))) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
664 (save-excursion |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
665 (set-buffer "*Completions*") |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
666 (setq completion-reference-buffer buffer))))))) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
667 ;; Make a completion question |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
668 (setq name (completing-read (or prompt "Index item: ") |
6230 | 669 prepared-index-alist |
7350
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
670 nil t nil 'imenu--history-list)))) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
671 (cond ((not (stringp name)) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
672 nil) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
673 ((string= name (car imenu--rescan-item)) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
674 t) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
675 (t |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
676 (setq choice (assoc name prepared-index-alist)) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
677 (if (listp (cdr choice)) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
678 (imenu--completion-buffer (cdr choice) prompt) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
679 choice))))) |
7319
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
680 |
6230 | 681 (defun imenu--mouse-menu (index-alist event &optional title) |
682 "Let the user select from a buffer index from a mouse menu. | |
683 | |
684 INDEX-ALIST is the buffer index and EVENT is a mouse event. | |
685 | |
686 Returns t for rescan and otherwise a position number." | |
687 (let* ((menu (imenu--split-menu | |
688 (if imenu-sort-function | |
6909
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
689 (sort |
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
690 (let ((res nil) |
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
691 (oldlist index-alist)) |
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
692 ;; Copy list method from the cl package `copy-list' |
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
693 (while (consp oldlist) (push (pop oldlist) res)) |
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
694 (prog1 (nreverse res) (setcdr res oldlist))) |
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
695 imenu-sort-function) |
6230 | 696 index-alist) |
697 (or title (buffer-name)))) | |
698 position) | |
699 (setq position (x-popup-menu event menu)) | |
700 (cond | |
701 ((eq position nil) | |
702 position) | |
6241 | 703 ((listp position) |
6230 | 704 (imenu--mouse-menu position event |
705 (if title | |
706 (concat title imenu-level-separator | |
707 (car (rassq position index-alist))) | |
708 (car (rassq position index-alist))))) | |
709 ((= position (cdr imenu--rescan-item)) | |
710 t) | |
711 (t | |
712 (rassq position index-alist))))) | |
713 | |
6241 | 714 (defun imenu-choose-buffer-index (&optional prompt alist) |
6230 | 715 "Let the user select from a buffer index and return the chosen index. |
716 | |
717 If the user originally activated this function with the mouse, a mouse | |
718 menu is used. Otherwise a completion buffer is used and the user is | |
719 prompted with PROMPT. | |
720 | |
6241 | 721 If you call this function with index alist ALIST, then it lets the user |
722 select from ALIST. | |
723 | |
6909
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
724 With no index alist ALIST, it calls `imenu--make-index-alist' to |
6241 | 725 create the index alist. |
726 | |
6909
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
727 If `imenu-always-use-completion-buffer-p' is non-nil, then the |
6230 | 728 completion buffer is always used, no matter if the mouse was used or |
729 not. | |
730 | |
731 The returned value is on the form (INDEX-NAME . INDEX-POSITION)." | |
732 (let (index-alist | |
8296
b2b493c007ff
(imenu-choose-buffer-index): Use last-nonmenu-event
Richard M. Stallman <rms@gnu.org>
parents:
8256
diff
changeset
|
733 (mouse-triggered (listp last-nonmenu-event)) |
6230 | 734 (result t) ) |
735 ;; If selected by mouse, see to that the window where the mouse is | |
736 ;; really is selected. | |
737 (and mouse-triggered | |
8296
b2b493c007ff
(imenu-choose-buffer-index): Use last-nonmenu-event
Richard M. Stallman <rms@gnu.org>
parents:
8256
diff
changeset
|
738 (let ((window (posn-window (event-start last-nonmenu-event)))) |
6230 | 739 (or (framep window) (select-window window)))) |
740 ;; Create a list for this buffer only when needed. | |
741 (while (eq result t) | |
6241 | 742 (setq index-alist (if alist alist (imenu--make-index-alist))) |
6230 | 743 (setq result |
744 (if (and mouse-triggered | |
745 (not imenu-always-use-completion-buffer-p)) | |
8296
b2b493c007ff
(imenu-choose-buffer-index): Use last-nonmenu-event
Richard M. Stallman <rms@gnu.org>
parents:
8256
diff
changeset
|
746 (imenu--mouse-menu index-alist last-nonmenu-event) |
6230 | 747 (imenu--completion-buffer index-alist prompt))) |
748 (and (eq result t) | |
8408
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
749 (imenu--cleanup) |
6230 | 750 (setq imenu--index-alist nil))) |
751 result)) | |
752 | |
8408
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
753 (defun imenu-add-to-menubar (name) |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
754 "Adds an \"imenu\" entry to the menubar for the |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
755 current local keymap. |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
756 NAME is the string naming the menu to be added. |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
757 See 'imenu' for more information." |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
758 (interactive "sMenu name: ") |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
759 (and window-system |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
760 (define-key (current-local-map) [menu-bar index] |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
761 (cons name 'imenu)))) |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
762 |
7319
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
763 ;;;###autoload |
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
764 (defun imenu () |
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
765 "Jump to a place in the buffer chosen using a buffer menu or mouse menu. |
6909
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
766 See `imenu-choose-buffer-index' for more information." |
6230 | 767 (interactive) |
10072
a7b70665c937
(imenu): Widen temporary before scan the file.
Richard M. Stallman <rms@gnu.org>
parents:
9176
diff
changeset
|
768 (let ((index-item (save-restriction |
a7b70665c937
(imenu): Widen temporary before scan the file.
Richard M. Stallman <rms@gnu.org>
parents:
9176
diff
changeset
|
769 (widen) |
a7b70665c937
(imenu): Widen temporary before scan the file.
Richard M. Stallman <rms@gnu.org>
parents:
9176
diff
changeset
|
770 (imenu-choose-buffer-index)))) |
6230 | 771 (and index-item |
772 (progn | |
773 (push-mark) | |
8408
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
774 (cond |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
775 ((markerp (cdr index-item)) |
10072
a7b70665c937
(imenu): Widen temporary before scan the file.
Richard M. Stallman <rms@gnu.org>
parents:
9176
diff
changeset
|
776 (if (or ( > (marker-position (cdr index-item)) (point-min)) |
a7b70665c937
(imenu): Widen temporary before scan the file.
Richard M. Stallman <rms@gnu.org>
parents:
9176
diff
changeset
|
777 ( < (marker-position (cdr index-item)) (point-max))) |
a7b70665c937
(imenu): Widen temporary before scan the file.
Richard M. Stallman <rms@gnu.org>
parents:
9176
diff
changeset
|
778 ;; widen if outside narrowing |
a7b70665c937
(imenu): Widen temporary before scan the file.
Richard M. Stallman <rms@gnu.org>
parents:
9176
diff
changeset
|
779 (widen)) |
8408
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
780 (goto-char (marker-position (cdr index-item)))) |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
781 (t |
10072
a7b70665c937
(imenu): Widen temporary before scan the file.
Richard M. Stallman <rms@gnu.org>
parents:
9176
diff
changeset
|
782 (if (or ( > (cdr index-item) (point-min)) |
a7b70665c937
(imenu): Widen temporary before scan the file.
Richard M. Stallman <rms@gnu.org>
parents:
9176
diff
changeset
|
783 ( < (cdr index-item) (point-max))) |
a7b70665c937
(imenu): Widen temporary before scan the file.
Richard M. Stallman <rms@gnu.org>
parents:
9176
diff
changeset
|
784 ;; widen if outside narrowing |
a7b70665c937
(imenu): Widen temporary before scan the file.
Richard M. Stallman <rms@gnu.org>
parents:
9176
diff
changeset
|
785 (widen)) |
8408
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
786 (goto-char (cdr index-item)))))))) |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
787 |
6230 | 788 (provide 'imenu) |
789 | |
790 ;;; imenu.el ends here |