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