Mercurial > emacs
annotate lisp/imenu.el @ 22221:239a4b800303
(shrink_regexp_cache): New function.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 24 May 1998 23:24:25 +0000 |
parents | 6ca7cc11f56a |
children | a77d473867b8 |
rev | line source |
---|---|
6230 | 1 ;;; imenu.el --- Framework for mode-specific buffer indexes. |
2 | |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
3 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. |
6230 | 4 |
5 ;; Author: Ake Stenhoff <etxaksf@aom.ericsson.se> | |
6 ;; Lars Lindberg <lli@sypro.cap.se> | |
17970 | 7 ;; Maintainer: FSF |
6230 | 8 ;; Created: 8 Feb 1994 |
9 ;; Keywords: tools | |
14169 | 10 |
11 ;; This file is part of GNU Emacs. | |
12 | |
13 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
6230 | 14 ;; it under the terms of the GNU General Public License as published by |
15 ;; the Free Software Foundation; either version 2, or (at your option) | |
16 ;; any later version. | |
14169 | 17 |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
6230 | 19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
14169 | 22 |
6230 | 23 ;; You should have received a copy of the GNU General Public License |
14169 | 24 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
26 ;; Boston, MA 02111-1307, USA. | |
6230 | 27 |
28 ;;; Commentary: | |
14169 | 29 |
6230 | 30 ;; Purpose of this package: |
31 ;; To present a framework for mode-specific buffer indexes. | |
32 ;; A buffer index is an alist of names and buffer positions. | |
33 ;; For instance all functions in a C-file and their positions. | |
34 ;; | |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
35 ;; It is documented in the Emacs Lisp manual. |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
36 ;; |
6230 | 37 ;; How it works: |
38 | |
39 ;; A mode-specific function is called to generate the index. It is | |
40 ;; then presented to the user, who can choose from this index. | |
41 ;; | |
42 ;; The package comes with a set of example functions for how to | |
43 ;; utilize this package. | |
44 | |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
45 ;; 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
|
46 ;; 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
|
47 ;; 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
|
48 ;; index position is also supplied. |
6230 | 49 |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
50 ;;; History: |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
51 ;; Thanks go to |
6241 | 52 ;; [simon] - Simon Leinen simon@lia.di.epfl.ch |
53 ;; [dean] - Dean Andrews ada@unison.com | |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
54 ;; [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
|
55 ;; [greg] - Greg Thompson gregt@porsche.visix.COM |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
56 ;; [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
|
57 ;; [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
|
58 ;; [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
|
59 ;; [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
|
60 ;; [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
|
61 |
6230 | 62 ;;; Code |
14169 | 63 |
6909
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
64 (eval-when-compile (require 'cl)) |
6230 | 65 |
66 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
67 ;;; | |
68 ;;; Customizable variables | |
69 ;;; | |
70 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
71 |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
72 (defgroup imenu nil |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
73 "Mode-specific buffer indexes." |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
74 :group 'matching |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
75 :group 'frames |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
76 :link '(custom-manual "(elisp)Imenu")) |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
77 |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
78 (defcustom imenu-use-markers t |
17307
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
79 "*Non-nil means use markers instead of integers for Imenu buffer positions. |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
80 |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
81 Setting this to nil makes Imenu work a little faster but editing the |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
82 buffer will make the generated index positions wrong. |
17307
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
83 |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
84 This might not yet be honored by all index-building functions." |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
85 :type 'boolean |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
86 :group 'imenu) |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
87 |
17307
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
88 |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
89 (defcustom imenu-max-item-length 60 |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
90 "*If a number, truncate Imenu entries to that length." |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
91 :type '(choice integer |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
92 (const :tag "Unlimited")) |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
93 :group 'imenu) |
17307
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
94 |
17677
3ab08563e855
(imenu-auto-rescan): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
17634
diff
changeset
|
95 (defcustom imenu-auto-rescan nil |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
96 "*Non-nil means Imenu should always rescan the buffers." |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
97 :type 'boolean |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
98 :group 'imenu) |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
99 |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
100 (defcustom imenu-auto-rescan-maxout 60000 |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
101 "*Imenu auto-rescan is disabled in buffers larger than this size (in bytes). |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
102 This variable is buffer-local." |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
103 :type 'integer |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
104 :group 'imenu) |
6230 | 105 |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
106 (defcustom imenu-always-use-completion-buffer-p nil |
6230 | 107 "*Set this to non-nil for displaying the index in a completion buffer. |
108 | |
17307
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
109 `never' means never automatically display a listing of any kind. |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
110 A value of nil (the default) means display the index as a mouse menu |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
111 if the mouse was used to invoke `imenu'. |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
112 Another non-nil value means always display the index in a completion buffer." |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
113 :type '(choice (const :tag "On Mouse" nil) |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
114 (const :tag "Never" never) |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
115 (sexp :tag "Always" :format "%t\n" t)) |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
116 :group 'imenu) |
6230 | 117 |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
118 (defcustom imenu-sort-function nil |
6230 | 119 "*The function to use for sorting the index mouse-menu. |
120 | |
121 Affects only the mouse index menu. | |
122 | |
123 Set this to nil if you don't want any sorting (faster). | |
124 The items in the menu are then presented in the order they were found | |
125 in the buffer. | |
126 | |
6909
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
127 Set it to `imenu--sort-by-name' if you want alphabetic sorting. |
6230 | 128 |
129 The function should take two arguments and return T if the first | |
130 element should come before the second. The arguments are cons cells; | |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
131 \(NAME . POSITION). Look at `imenu--sort-by-name' for an example." |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
132 :type '(choice (const :tag "No sorting" nil) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
133 (const :tag "Sort by name" 'imenu--sort-by-name) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
134 (function :tag "Another function")) |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
135 :group 'imenu) |
6230 | 136 |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
137 (defcustom imenu-max-items 25 |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
138 "*Maximum number of elements in a mouse menu for Imenu." |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
139 :type 'integer |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
140 :group 'imenu) |
6230 | 141 |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
142 (defcustom imenu-scanning-message "Scanning buffer for index (%3d%%)" |
6230 | 143 "*Progress message during the index scanning of the buffer. |
16460
4d7d18a39871
(imenu-scanning-message): Use ellipsis.
Karl Heuer <kwzh@gnu.org>
parents:
16382
diff
changeset
|
144 If non-nil, user gets a message during the scanning of the buffer. |
6230 | 145 |
146 Relevant only if the mode-specific function that creates the buffer | |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
147 index use `imenu-progress-message', and not useful if that is fast, in |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
148 which case you might as well set this to nil." |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
149 :type '(choice string |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
150 (const :tag "None" nil)) |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
151 :group 'imenu) |
6230 | 152 |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
153 (defcustom imenu-space-replacement "^" |
6230 | 154 "*The replacement string for spaces in index names. |
155 Used when presenting the index in a completion-buffer to make the | |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
156 names work as tokens." |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
157 :type 'string |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
158 :group 'imenu) |
6230 | 159 |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
160 (defcustom imenu-level-separator ":" |
6230 | 161 "*The separator between index names of different levels. |
162 Used for making mouse-menu titles and for flattening nested indexes | |
17634
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
163 with name concatenation." |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
164 :type 'string |
247c2a11843d
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17307
diff
changeset
|
165 :group 'imenu) |
6230 | 166 |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
167 ;;;###autoload |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
168 (defvar imenu-generic-expression nil |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
169 "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
|
170 |
16698
13920eac02e0
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
16612
diff
changeset
|
171 If non-nil this pattern is passed to `imenu--generic-function' |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
172 to create a buffer index. |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
173 |
16271
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
174 The value should be an alist with elements that look like this: |
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
175 (MENU-TITLE REGEXP INDEX) |
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
176 or like this: |
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
177 (MENU-TITLE REGEXP INDEX FUNCTION ARGUMENTS...) |
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
178 with zero or more ARGUMENTS. The former format creates a simple element in |
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
179 the index alist when it matches; the latter creates a special element |
20857
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
180 of the form (NAME FUNCTION POSITION-MARKER ARGUMENTS...) |
16271
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
181 with FUNCTION and ARGUMENTS beiong copied from `imenu-generic-expression'. |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
182 |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
183 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
|
184 entries are not nested. |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
185 |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 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
|
190 |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
191 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
|
192 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
|
193 |
20769
aa3481dd4d84
(imenu-case-fold-search): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20249
diff
changeset
|
194 The variable is buffer-local. |
aa3481dd4d84
(imenu-case-fold-search): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20249
diff
changeset
|
195 |
aa3481dd4d84
(imenu-case-fold-search): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20249
diff
changeset
|
196 The variable `imenu-case-fold-search' determines whether or not the |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
197 regexp matches are case sensitive. and `imenu-syntax-alist' can be |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
198 used to alter the syntax table for the search. |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
199 |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
200 For example, see the value of `lisp-imenu-generic-expression' used by |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
201 `lisp-mode' and `emacs-lisp-mode' with `imenu-syntax-alist' set |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
202 locally to give the characters which normally have \"punctuation\" |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
203 syntax \"word\" syntax during matching.") |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
204 |
14816
485422b900d3
(imenu-generic-expression): Autoload the make-variable-buffer-local call.
Richard M. Stallman <rms@gnu.org>
parents:
14798
diff
changeset
|
205 ;;;###autoload |
12664
ce1cae301efe
(imenu--history-list): Don't make this buffer-local.
Richard M. Stallman <rms@gnu.org>
parents:
12635
diff
changeset
|
206 (make-variable-buffer-local 'imenu-generic-expression) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
207 |
6230 | 208 ;;;; Hooks |
209 | |
210 (defvar imenu-create-index-function 'imenu-default-create-index-function | |
211 "The function to use for creating a buffer index. | |
212 | |
213 It should be a function that takes no arguments and returns an index | |
16271
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
214 of the current buffer as an alist. |
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
215 |
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
216 Simple elements in the alist look like (INDEX-NAME . INDEX-POSITION). |
20857
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
217 Special elements look like (INDEX-NAME INDEX-POSITION FUNCTION ARGUMENTS...). |
16271
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
218 A nested sub-alist element looks like (INDEX-NAME SUB-ALIST). |
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
219 The function `imenu--subalist-p' tests an element and returns t |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
220 if it is a sub-alist. |
6230 | 221 |
6909
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
222 This function is called within a `save-excursion'. |
6230 | 223 |
224 The variable is buffer-local.") | |
225 (make-variable-buffer-local 'imenu-create-index-function) | |
226 | |
7319
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
227 (defvar imenu-prev-index-position-function 'beginning-of-defun |
6230 | 228 "Function for finding the next index position. |
229 | |
6909
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
230 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
|
231 `imenu-default-create-index-function', then you must set this variable |
6230 | 232 to a function that will find the next index, looking backwards in the |
233 file. | |
234 | |
235 The function should leave point at the place to be connected to the | |
20857
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
236 index and it should return nil when it doesn't find another index. |
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
237 |
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
238 This variable is local in all buffers.") |
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
239 |
7319
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
240 (make-variable-buffer-local 'imenu-prev-index-position-function) |
6230 | 241 |
7319
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
242 (defvar imenu-extract-index-name-function nil |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
243 "Function for extracting the index item name, given a position. |
6230 | 244 |
20857
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
245 This function is called after `imenu-prev-index-position-function' |
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
246 finds a position for an index item, with point at that position. |
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
247 It should return the name for that index item. |
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
248 |
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
249 This variable is local in all buffers.") |
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
250 |
7319
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
251 (make-variable-buffer-local 'imenu-extract-index-name-function) |
6230 | 252 |
17229
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
253 (defvar imenu-default-goto-function 'imenu-default-goto-function |
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
254 "The default function called when selecting an Imenu item. |
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
255 The function in this variable is called when selecting a normal index-item.") |
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
256 (make-variable-buffer-local 'imenu-default-goto-function) |
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
257 |
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
258 |
16271
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
259 (defun imenu--subalist-p (item) |
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
260 (and (consp (cdr item)) (listp (cadr item)) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
261 (not (eq (car (cadr item)) 'lambda)))) |
16271
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
262 |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
263 ;; Macro to display a progress message. |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
264 ;; RELPOS is the relative position to display. |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
265 ;; If RELPOS is nil, then the relative position in the buffer |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
266 ;; is calculated. |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
267 ;; PREVPOS is the variable in which we store the last position displayed. |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
268 (defmacro imenu-progress-message (prevpos &optional relpos reverse) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
269 `(and |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
270 imenu-scanning-message |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
271 (let ((pos ,(if relpos |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
272 relpos |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
273 `(imenu--relative-position ,reverse)))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
274 (if ,(if relpos t |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
275 `(> pos (+ 5 ,prevpos))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
276 (progn |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
277 (message imenu-scanning-message pos) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
278 (setq ,prevpos pos)))))) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
279 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
280 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
281 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
282 ;;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
283 ;;;; Some examples of functions utilizing the framework of this |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
284 ;;;; package. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
285 ;;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
286 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
287 |
12707
06608e9272b5
(imenu-generic-lisp-expression)
Karl Heuer <kwzh@gnu.org>
parents:
12664
diff
changeset
|
288 ;; 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
|
289 ;; beginning) without moving the point. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
290 (defun imenu-example--name-and-position () |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
291 (save-excursion |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
292 (forward-sexp -1) |
17307
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
293 ;; [ydi] modified for imenu-use-markers |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
294 (let ((beg (if imenu-use-markers (point-marker) (point))) |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
295 (end (progn (forward-sexp) (point)))) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
296 (cons (buffer-substring beg end) |
17307
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
297 beg)))) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
298 |
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 ;;; Lisp |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
301 ;;; |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
302 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
303 (defun imenu-example--lisp-extract-index-name () |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
304 ;; 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
|
305 ;; 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
|
306 (save-match-data |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
307 (and (looking-at "(def") |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
308 (condition-case nil |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
309 (progn |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
310 (down-list 1) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
311 (forward-sexp 2) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
312 (let ((beg (point)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
313 (end (progn (forward-sexp -1) (point)))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
314 (buffer-substring beg end))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
315 (error nil))))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
316 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
317 (defun imenu-example--create-lisp-index () |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
318 ;; Example of a candidate for `imenu-create-index-function'. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
319 ;; It will generate a nested index of definitions. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
320 (let ((index-alist '()) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
321 (index-var-alist '()) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
322 (index-type-alist '()) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
323 (index-unknown-alist '()) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
324 prev-pos) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
325 (goto-char (point-max)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
326 (imenu-progress-message prev-pos 0) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
327 ;; Search for the function |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
328 (while (beginning-of-defun) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
329 (imenu-progress-message prev-pos nil t) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
330 (save-match-data |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
331 (and (looking-at "(def") |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
332 (save-excursion |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
333 (down-list 1) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
334 (cond |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
335 ((looking-at "def\\(var\\|const\\)") |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
336 (forward-sexp 2) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
337 (push (imenu-example--name-and-position) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
338 index-var-alist)) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
339 ((looking-at "def\\(un\\|subst\\|macro\\|advice\\)") |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
340 (forward-sexp 2) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
341 (push (imenu-example--name-and-position) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
342 index-alist)) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
343 ((looking-at "def\\(type\\|struct\\|class\\|ine-condition\\)") |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
344 (forward-sexp 2) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
345 (if (= (char-after (1- (point))) ?\)) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
346 (progn |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
347 (forward-sexp -1) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
348 (down-list 1) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
349 (forward-sexp 1))) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
350 (push (imenu-example--name-and-position) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
351 index-type-alist)) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
352 (t |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
353 (forward-sexp 2) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
354 (push (imenu-example--name-and-position) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
355 index-unknown-alist))))))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
356 (imenu-progress-message prev-pos 100) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
357 (and index-var-alist |
14726
35e1cfdd29a4
(imenu--menubar-select): No longer interactive.
Richard M. Stallman <rms@gnu.org>
parents:
14725
diff
changeset
|
358 (push (cons "Variables" index-var-alist) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
359 index-alist)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
360 (and index-type-alist |
14726
35e1cfdd29a4
(imenu--menubar-select): No longer interactive.
Richard M. Stallman <rms@gnu.org>
parents:
14725
diff
changeset
|
361 (push (cons "Types" index-type-alist) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
362 index-alist)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
363 (and index-unknown-alist |
14726
35e1cfdd29a4
(imenu--menubar-select): No longer interactive.
Richard M. Stallman <rms@gnu.org>
parents:
14725
diff
changeset
|
364 (push (cons "Syntax-unknown" index-unknown-alist) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
365 index-alist)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
366 index-alist)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
367 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
368 ;; Regular expression to find C functions |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
369 (defvar imenu-example--function-name-regexp-c |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
370 (concat |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
371 "^[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
|
372 "\\([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
|
373 "\\([a-zA-Z0-9_*]+[ \t]+\\)?" |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
374 "\\([*&]+[ \t]*\\)?" ; pointer |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
375 "\\([a-zA-Z0-9_*]+\\)[ \t]*(" ; name |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
376 )) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
377 |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
378 (defun imenu-example--create-c-index (&optional regexp) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
379 (let ((index-alist '()) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
380 prev-pos char) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
381 (goto-char (point-min)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
382 (imenu-progress-message prev-pos 0) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
383 ;; Search for the function |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
384 (save-match-data |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
385 (while (re-search-forward |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
386 (or regexp imenu-example--function-name-regexp-c) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
387 nil t) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
388 (imenu-progress-message prev-pos) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
389 (backward-up-list 1) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
390 (save-excursion |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
391 (goto-char (scan-sexps (point) 1)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
392 (setq char (following-char))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
393 ;; 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
|
394 (if (not (eq char ?\;)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
395 (push (imenu-example--name-and-position) index-alist)))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
396 (imenu-progress-message prev-pos 100) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
397 (nreverse index-alist))) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
398 |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
399 |
6230 | 400 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
401 ;;; | |
402 ;;; Internal variables | |
403 ;;; | |
404 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
405 | |
406 ;; The item to use in the index for rescanning the buffer. | |
407 (defconst imenu--rescan-item '("*Rescan*" . -99)) | |
408 | |
409 ;; The latest buffer index. | |
410 ;; Buffer local. | |
20857
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
411 (defvar imenu--index-alist nil |
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
412 "The buffer index computed for this buffer in Imenu. |
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
413 Simple elements in the alist look like (INDEX-NAME . INDEX-POSITION). |
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
414 Special elements look like (INDEX-NAME INDEX-POSITION FUNCTION ARGUMENTS...). |
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
415 A nested sub-alist element looks like (INDEX-NAME SUB-ALIST). |
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
416 |
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
417 This variable is local in all buffers, once set.") |
185fa242a2ea
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20770
diff
changeset
|
418 |
6230 | 419 (make-variable-buffer-local 'imenu--index-alist) |
420 | |
13798
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
421 ;; 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
|
422 (defvar imenu--last-menubar-index-alist nil) |
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
423 (make-variable-buffer-local 'imenu--last-menubar-index-alist) |
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
424 |
6230 | 425 ;; 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
|
426 ;; Making this buffer local caused it not to work! |
6230 | 427 (defvar imenu--history-list nil) |
428 | |
429 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
430 ;;; | |
431 ;;; Internal support functions | |
432 ;;; | |
433 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
434 | |
435 ;;; | |
436 ;;; Sort function | |
437 ;;; Sorts the items depending on their index name. | |
438 ;;; An item look like (NAME . POSITION). | |
439 ;;; | |
440 (defun imenu--sort-by-name (item1 item2) | |
441 (string-lessp (car item1) (car item2))) | |
442 | |
443 (defun imenu--relative-position (&optional reverse) | |
444 ;; Support function to calculate relative position in buffer | |
445 ;; Beginning of buffer is 0 and end of buffer is 100 | |
446 ;; If REVERSE is non-nil then the beginning is 100 and the end is 0. | |
447 (let ((pos (point)) | |
448 (total (buffer-size))) | |
449 (and reverse (setq pos (- total pos))) | |
450 (if (> total 50000) | |
451 ;; Avoid overflow from multiplying by 100! | |
452 (/ (1- pos) (max (/ total 100) 1)) | |
453 (/ (* 100 (1- pos)) (max total 1))))) | |
454 | |
455 ;; Split LIST into sublists of max length N. | |
456 ;; Example (imenu--split '(1 2 3 4 5 6 7 8) 3)-> '((1 2 3) (4 5 6) (7 8)) | |
457 (defun imenu--split (list n) | |
458 (let ((remain list) | |
459 (result '()) | |
460 (sublist '()) | |
461 (i 0)) | |
462 (while remain | |
463 (push (pop remain) sublist) | |
464 (incf i) | |
465 (and (= i n) | |
466 ;; We have finished a sublist | |
467 (progn (push (nreverse sublist) result) | |
468 (setq i 0) | |
469 (setq sublist '())))) | |
470 ;; There might be a sublist (if the length of LIST mod n is != 0) | |
471 ;; that has to be added to the result list. | |
472 (and sublist | |
473 (push (nreverse sublist) result)) | |
474 (nreverse result))) | |
475 | |
14726
35e1cfdd29a4
(imenu--menubar-select): No longer interactive.
Richard M. Stallman <rms@gnu.org>
parents:
14725
diff
changeset
|
476 ;;; Split the alist MENULIST into a nested alist, if it is long enough. |
35e1cfdd29a4
(imenu--menubar-select): No longer interactive.
Richard M. Stallman <rms@gnu.org>
parents:
14725
diff
changeset
|
477 ;;; In any case, add TITLE to the front of the alist. |
6230 | 478 (defun imenu--split-menu (menulist title) |
16272
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
479 (let (keep-at-top tail) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
480 (if (memq imenu--rescan-item menulist) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
481 (setq keep-at-top (cons imenu--rescan-item nil) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
482 menulist (delq imenu--rescan-item menulist))) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
483 (setq tail menulist) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
484 (while tail |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
485 (if (imenu--subalist-p (car tail)) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
486 (setq keep-at-top (cons (car tail) keep-at-top) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
487 menulist (delq (car tail) menulist))) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
488 (setq tail (cdr tail))) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
489 (if imenu-sort-function |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
490 (setq menulist |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
491 (sort |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
492 (let ((res nil) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
493 (oldlist menulist)) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
494 ;; Copy list method from the cl package `copy-list' |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
495 (while (consp oldlist) (push (pop oldlist) res)) |
20770
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
496 (if res ; in case, e.g. no functions defined |
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
497 (prog1 (nreverse res) (setcdr res oldlist)))) |
16272
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
498 imenu-sort-function))) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
499 (if (> (length menulist) imenu-max-items) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
500 (let ((count 0)) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
501 (setq menulist |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
502 (mapcar |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
503 (function |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
504 (lambda (menu) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
505 (cons (format "From: %s" (caar menu)) menu))) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
506 (imenu--split menulist imenu-max-items))))) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
507 (cons title |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
508 (nconc (nreverse keep-at-top) menulist)))) |
14726
35e1cfdd29a4
(imenu--menubar-select): No longer interactive.
Richard M. Stallman <rms@gnu.org>
parents:
14725
diff
changeset
|
509 |
35e1cfdd29a4
(imenu--menubar-select): No longer interactive.
Richard M. Stallman <rms@gnu.org>
parents:
14725
diff
changeset
|
510 ;;; Split up each long alist that are nested within ALIST |
35e1cfdd29a4
(imenu--menubar-select): No longer interactive.
Richard M. Stallman <rms@gnu.org>
parents:
14725
diff
changeset
|
511 ;;; into nested alists. |
35e1cfdd29a4
(imenu--menubar-select): No longer interactive.
Richard M. Stallman <rms@gnu.org>
parents:
14725
diff
changeset
|
512 (defun imenu--split-submenus (alist) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
513 (mapcar (function |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
514 (lambda (elt) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
515 (if (and (consp elt) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
516 (stringp (car elt)) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
517 (listp (cdr elt))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
518 (imenu--split-menu (cdr elt) (car elt)) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
519 elt))) |
14726
35e1cfdd29a4
(imenu--menubar-select): No longer interactive.
Richard M. Stallman <rms@gnu.org>
parents:
14725
diff
changeset
|
520 alist)) |
6230 | 521 |
17307
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
522 ;;; Truncate all strings in MENULIST to imenu-max-item-length |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
523 (defun imenu--truncate-items (menulist) |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
524 (mapcar (function |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
525 (lambda (item) |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
526 (cond |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
527 ((consp (cdr item)) |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
528 (imenu--truncate-items (cdr item))) |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
529 (t |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
530 ;; truncate if necessary |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
531 (if (and (numberp imenu-max-item-length) |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
532 (> (length (car item)) imenu-max-item-length)) |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
533 (setcar item (substring (car item) 0 imenu-max-item-length))))))) |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
534 menulist)) |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
535 |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
536 |
16369
187e7c8aaff5
(imenu--make-index-alist): Add doc string.
Richard M. Stallman <rms@gnu.org>
parents:
16315
diff
changeset
|
537 (defun imenu--make-index-alist (&optional noerror) |
187e7c8aaff5
(imenu--make-index-alist): Add doc string.
Richard M. Stallman <rms@gnu.org>
parents:
16315
diff
changeset
|
538 "Create an index-alist for the definitions in the current buffer. |
6230 | 539 |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
540 Report an error if the list is empty unless NOERROR is supplied and |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
541 non-nil. |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
542 |
16369
187e7c8aaff5
(imenu--make-index-alist): Add doc string.
Richard M. Stallman <rms@gnu.org>
parents:
16315
diff
changeset
|
543 Simple elements in the alist look like (INDEX-NAME . INDEX-POSITION). |
187e7c8aaff5
(imenu--make-index-alist): Add doc string.
Richard M. Stallman <rms@gnu.org>
parents:
16315
diff
changeset
|
544 Special elements look like (INDEX-NAME FUNCTION ARGUMENTS...). |
187e7c8aaff5
(imenu--make-index-alist): Add doc string.
Richard M. Stallman <rms@gnu.org>
parents:
16315
diff
changeset
|
545 A nested sub-alist element looks like (INDEX-NAME SUB-ALIST). |
187e7c8aaff5
(imenu--make-index-alist): Add doc string.
Richard M. Stallman <rms@gnu.org>
parents:
16315
diff
changeset
|
546 The function `imenu--subalist-p' tests an element and returns t |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
547 if it is a sub-alist. |
16369
187e7c8aaff5
(imenu--make-index-alist): Add doc string.
Richard M. Stallman <rms@gnu.org>
parents:
16315
diff
changeset
|
548 |
187e7c8aaff5
(imenu--make-index-alist): Add doc string.
Richard M. Stallman <rms@gnu.org>
parents:
16315
diff
changeset
|
549 There is one simple element with negative POSITION; that's intended |
187e7c8aaff5
(imenu--make-index-alist): Add doc string.
Richard M. Stallman <rms@gnu.org>
parents:
16315
diff
changeset
|
550 as a way for the user to ask to recalculate the buffer's index alist." |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
551 (or (and imenu--index-alist |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
552 (or (not imenu-auto-rescan) |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
553 (and imenu-auto-rescan |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
554 (> (buffer-size) imenu-auto-rescan-maxout)))) |
17307
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
555 ;; Get the index; truncate if necessary |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
556 (progn |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
557 (setq imenu--index-alist |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
558 (save-excursion |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
559 (save-restriction |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
560 (widen) |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
561 (funcall imenu-create-index-function)))) |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
562 (imenu--truncate-items imenu--index-alist))) |
13798
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
563 (or imenu--index-alist noerror |
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
564 (error "No items suitable for an index found in this buffer")) |
6230 | 565 (or imenu--index-alist |
13798
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
566 (setq imenu--index-alist (list nil))) |
6230 | 567 ;; Add a rescan option to the index. |
568 (cons imenu--rescan-item imenu--index-alist)) | |
16315
cca1c6324cab
(imenu--cleanup): Handle shared structure in alist.
Richard M. Stallman <rms@gnu.org>
parents:
16272
diff
changeset
|
569 |
8408
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
570 ;;; 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
|
571 ;;; them point nowhere. |
16315
cca1c6324cab
(imenu--cleanup): Handle shared structure in alist.
Richard M. Stallman <rms@gnu.org>
parents:
16272
diff
changeset
|
572 ;;; The top-level call uses nil as the argument; |
cca1c6324cab
(imenu--cleanup): Handle shared structure in alist.
Richard M. Stallman <rms@gnu.org>
parents:
16272
diff
changeset
|
573 ;;; non-nil arguments are in recursivecalls. |
cca1c6324cab
(imenu--cleanup): Handle shared structure in alist.
Richard M. Stallman <rms@gnu.org>
parents:
16272
diff
changeset
|
574 (defvar imenu--cleanup-seen) |
cca1c6324cab
(imenu--cleanup): Handle shared structure in alist.
Richard M. Stallman <rms@gnu.org>
parents:
16272
diff
changeset
|
575 |
8408
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
576 (defun imenu--cleanup (&optional alist) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
577 ;; If alist is provided use that list. |
16315
cca1c6324cab
(imenu--cleanup): Handle shared structure in alist.
Richard M. Stallman <rms@gnu.org>
parents:
16272
diff
changeset
|
578 ;; If not, empty the table of lists already seen |
cca1c6324cab
(imenu--cleanup): Handle shared structure in alist.
Richard M. Stallman <rms@gnu.org>
parents:
16272
diff
changeset
|
579 ;; and use imenu--index-alist. |
cca1c6324cab
(imenu--cleanup): Handle shared structure in alist.
Richard M. Stallman <rms@gnu.org>
parents:
16272
diff
changeset
|
580 (if alist |
cca1c6324cab
(imenu--cleanup): Handle shared structure in alist.
Richard M. Stallman <rms@gnu.org>
parents:
16272
diff
changeset
|
581 (setq imenu--cleanup-seen (cons alist imenu--cleanup-seen)) |
cca1c6324cab
(imenu--cleanup): Handle shared structure in alist.
Richard M. Stallman <rms@gnu.org>
parents:
16272
diff
changeset
|
582 (setq alist imenu--index-alist imenu--cleanup-seen (list alist))) |
cca1c6324cab
(imenu--cleanup): Handle shared structure in alist.
Richard M. Stallman <rms@gnu.org>
parents:
16272
diff
changeset
|
583 |
10795
8cbc8846b19b
(imenu--cleanup): Set alist to its default just once, at the beginning.
Richard M. Stallman <rms@gnu.org>
parents:
10221
diff
changeset
|
584 (and alist |
9176
5646f9ac8ec3
(imenu--cleanup): Changed 'mapc' to 'mapcar'.
Richard M. Stallman <rms@gnu.org>
parents:
8408
diff
changeset
|
585 (mapcar |
8408
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
586 (function |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
587 (lambda (item) |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
588 (cond |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
589 ((markerp (cdr item)) |
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
590 (set-marker (cdr item) nil)) |
16315
cca1c6324cab
(imenu--cleanup): Handle shared structure in alist.
Richard M. Stallman <rms@gnu.org>
parents:
16272
diff
changeset
|
591 ;; Don't process one alist twice. |
cca1c6324cab
(imenu--cleanup): Handle shared structure in alist.
Richard M. Stallman <rms@gnu.org>
parents:
16272
diff
changeset
|
592 ((memq (cdr item) imenu--cleanup-seen)) |
16271
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
593 ((imenu--subalist-p item) |
8408
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
594 (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
|
595 alist) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
596 t)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
597 |
13798
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
598 (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
|
599 (let ((map nil)) |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
600 (mapcar |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
601 (function |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
602 (lambda (item) |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
603 (cond |
16271
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
604 ((imenu--subalist-p item) |
14114
b8c7c891ed63
(imenu--create-keymap-2): Fix bug in constructing
Karl Heuer <kwzh@gnu.org>
parents:
14040
diff
changeset
|
605 (append (list (setq counter (1+ counter)) |
b8c7c891ed63
(imenu--create-keymap-2): Fix bug in constructing
Karl Heuer <kwzh@gnu.org>
parents:
14040
diff
changeset
|
606 (car item) 'keymap (car item)) |
13798
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
607 (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
|
608 (t |
14114
b8c7c891ed63
(imenu--create-keymap-2): Fix bug in constructing
Karl Heuer <kwzh@gnu.org>
parents:
14040
diff
changeset
|
609 (let ((end (if commands `(lambda () (interactive) |
b8c7c891ed63
(imenu--create-keymap-2): Fix bug in constructing
Karl Heuer <kwzh@gnu.org>
parents:
14040
diff
changeset
|
610 (imenu--menubar-select ',item)) |
16148
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
611 (cons '(nil) item)))) |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
612 (cons (car item) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
613 (cons (car item) end))))))) |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
614 alist))) |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
615 |
13798
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
616 ;; If COMMANDS is non-nil, make a real keymap |
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
617 ;; with a real command used as the definition. |
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
618 ;; 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
|
619 (defun imenu--create-keymap-1 (title alist &optional commands) |
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
620 (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
|
621 |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
622 (defun imenu--in-alist (str alist) |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
623 "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
|
624 (let (elt head tail res) |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
625 (setq res nil) |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
626 (while alist |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
627 (setq elt (car alist) |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
628 tail (cdr elt) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
629 alist (cdr alist) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
630 head (car elt)) |
15929
955269257adf
(imenu--in-alist): Accept only bottom-level matches.
Richard M. Stallman <rms@gnu.org>
parents:
15831
diff
changeset
|
631 ;; A nested ALIST element looks like |
955269257adf
(imenu--in-alist): Accept only bottom-level matches.
Richard M. Stallman <rms@gnu.org>
parents:
15831
diff
changeset
|
632 ;; (INDEX-NAME (INDEX-NAME . INDEX-POSITION) ...) |
955269257adf
(imenu--in-alist): Accept only bottom-level matches.
Richard M. Stallman <rms@gnu.org>
parents:
15831
diff
changeset
|
633 ;; while a bottom-level element looks like |
955269257adf
(imenu--in-alist): Accept only bottom-level matches.
Richard M. Stallman <rms@gnu.org>
parents:
15831
diff
changeset
|
634 ;; (INDEX-NAME . INDEX-POSITION) |
955269257adf
(imenu--in-alist): Accept only bottom-level matches.
Richard M. Stallman <rms@gnu.org>
parents:
15831
diff
changeset
|
635 ;; We are only interested in the bottom-level elements, so we need to |
955269257adf
(imenu--in-alist): Accept only bottom-level matches.
Richard M. Stallman <rms@gnu.org>
parents:
15831
diff
changeset
|
636 ;; recurse if TAIL is a list. |
955269257adf
(imenu--in-alist): Accept only bottom-level matches.
Richard M. Stallman <rms@gnu.org>
parents:
15831
diff
changeset
|
637 (cond ((listp tail) |
955269257adf
(imenu--in-alist): Accept only bottom-level matches.
Richard M. Stallman <rms@gnu.org>
parents:
15831
diff
changeset
|
638 (if (setq res (imenu--in-alist str tail)) |
955269257adf
(imenu--in-alist): Accept only bottom-level matches.
Richard M. Stallman <rms@gnu.org>
parents:
15831
diff
changeset
|
639 (setq alist nil))) |
955269257adf
(imenu--in-alist): Accept only bottom-level matches.
Richard M. Stallman <rms@gnu.org>
parents:
15831
diff
changeset
|
640 ((string= str head) |
955269257adf
(imenu--in-alist): Accept only bottom-level matches.
Richard M. Stallman <rms@gnu.org>
parents:
15831
diff
changeset
|
641 (setq alist nil res elt)))) |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
642 res)) |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
643 |
20770
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
644 (defvar imenu-syntax-alist nil |
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
645 "Alist of syntax table modifiers to use while executing `imenu--generic-function'. |
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
646 |
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
647 The car of the assocs may be either a character or a string and the |
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
648 cdr is a syntax description appropriate fo `modify-syntax-entry'. For |
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
649 a string, all the characters in the string get the specified syntax. |
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
650 |
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
651 This is typically used to give word syntax to characters which |
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
652 normallsymbol syntax to simplify `imenu-expression' |
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
653 and speed-up matching.") |
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
654 (make-variable-buffer-local 'imenu-syntax-alist) |
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
655 |
6230 | 656 (defun imenu-default-create-index-function () |
657 "*Wrapper for index searching functions. | |
658 | |
659 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
|
660 `imenu-prev-index-position-function' and `imenu-extract-index-name-function'. |
6230 | 661 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
|
662 ;; 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
|
663 ;; in these major modes. But save that change for later. |
20249
c42156dab61b
(imenu-default-create-index-function):
Karl Heuer <kwzh@gnu.org>
parents:
20051
diff
changeset
|
664 (cond ((and imenu-prev-index-position-function |
c42156dab61b
(imenu-default-create-index-function):
Karl Heuer <kwzh@gnu.org>
parents:
20051
diff
changeset
|
665 imenu-extract-index-name-function) |
7350
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
666 (let ((index-alist '()) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
667 prev-pos name) |
7350
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
668 (goto-char (point-max)) |
8296
b2b493c007ff
(imenu-choose-buffer-index): Use last-nonmenu-event
Richard M. Stallman <rms@gnu.org>
parents:
8256
diff
changeset
|
669 (imenu-progress-message prev-pos 0 t) |
7350
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
670 ;; Search for the function |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
671 (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
|
672 (imenu-progress-message prev-pos nil t) |
7350
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
673 (save-excursion |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
674 (setq name (funcall imenu-extract-index-name-function))) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
675 (and (stringp name) |
17307
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
676 ;; [ydi] updated for imenu-use-markers |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
677 (push (cons name (if imenu-use-markers (point-marker) (point))) |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
678 index-alist))) |
8296
b2b493c007ff
(imenu-choose-buffer-index): Use last-nonmenu-event
Richard M. Stallman <rms@gnu.org>
parents:
8256
diff
changeset
|
679 (imenu-progress-message prev-pos 100 t) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
680 index-alist)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
681 ;; Use generic expression if possible. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
682 ((and imenu-generic-expression) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
683 (imenu--generic-function imenu-generic-expression)) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
684 (t |
17307
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
685 (error "This buffer cannot use `imenu-default-create-index-function'")))) |
6230 | 686 |
687 (defun imenu--replace-spaces (name replacement) | |
688 ;; Replace all spaces in NAME with REPLACEMENT. | |
689 ;; That second argument should be a string. | |
690 (mapconcat | |
691 (function | |
692 (lambda (ch) | |
693 (if (char-equal ch ?\ ) | |
694 replacement | |
695 (char-to-string ch)))) | |
696 name | |
697 "")) | |
698 | |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
699 ;; Not used and would require cl at run time |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
700 ;;; (defun imenu--flatten-index-alist (index-alist &optional concat-names prefix) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
701 ;;; ;; Takes a nested INDEX-ALIST and returns a flat index alist. |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
702 ;;; ;; If optional CONCAT-NAMES is non-nil, then a nested index has its |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
703 ;;; ;; name and a space concatenated to the names of the children. |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
704 ;;; ;; Third argument PREFIX is for internal use only. |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
705 ;;; (mapcan |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
706 ;;; (lambda (item) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
707 ;;; (let* ((name (car item)) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
708 ;;; (pos (cdr item)) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
709 ;;; (new-prefix (and concat-names |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
710 ;;; (if prefix |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
711 ;;; (concat prefix imenu-level-separator name) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
712 ;;; name)))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
713 ;;; (cond |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
714 ;;; ((or (markerp pos) (numberp pos)) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
715 ;;; (list (cons new-prefix pos))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
716 ;;; (t |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
717 ;;; (imenu--flatten-index-alist pos new-prefix))))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
718 ;;; index-alist)) |
6230 | 719 |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
720 ;;; |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
721 ;;; Generic index gathering function. |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
722 ;;; |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
723 |
20769
aa3481dd4d84
(imenu-case-fold-search): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20249
diff
changeset
|
724 (defvar imenu-case-fold-search t |
aa3481dd4d84
(imenu-case-fold-search): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20249
diff
changeset
|
725 "Defines whether `imenu--generic-function' should fold case when matching. |
aa3481dd4d84
(imenu-case-fold-search): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20249
diff
changeset
|
726 |
aa3481dd4d84
(imenu-case-fold-search): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20249
diff
changeset
|
727 This buffer-local variable should be set (only) by initialization code |
aa3481dd4d84
(imenu-case-fold-search): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20249
diff
changeset
|
728 for modes which use `imenu--generic-function'. If it is not set, that |
aa3481dd4d84
(imenu-case-fold-search): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20249
diff
changeset
|
729 function will use the current value of `case-fold-search' to match |
aa3481dd4d84
(imenu-case-fold-search): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20249
diff
changeset
|
730 patterns.") |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
731 ;;;###autoload |
20769
aa3481dd4d84
(imenu-case-fold-search): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20249
diff
changeset
|
732 (make-variable-buffer-local 'imenu-case-fold-search) |
aa3481dd4d84
(imenu-case-fold-search): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20249
diff
changeset
|
733 |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
734 ;; Originally "Built on some ideas that Erik Naggum <erik@naggum.no> |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
735 ;; once posted to comp.emacs" but since substantially re-written. |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
736 (defun imenu--generic-function (patterns) |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
737 "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
|
738 |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
739 PATTERNS is an alist with elements that look like this: |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
740 (MENU-TITLE REGEXP INDEX). |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
741 |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
742 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
|
743 entries are not nested. |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
744 |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
745 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
|
746 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
|
747 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
|
748 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
|
749 |
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
750 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
|
751 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
|
752 |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
753 See `lisp-imenu-generic-expression' for an example of PATTERNS. |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
754 |
12664
ce1cae301efe
(imenu--history-list): Don't make this buffer-local.
Richard M. Stallman <rms@gnu.org>
parents:
12635
diff
changeset
|
755 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
|
756 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
|
757 nested index lists like (INDEX-NAME . INDEX-ALIST) depending on |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
758 PATTERNS." |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
759 |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
760 (let ((index-alist (list 'dummy)) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
761 prev-pos beg |
20770
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
762 (case-fold-search imenu-case-fold-search) |
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
763 (old-table (syntax-table)) |
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
764 (table (copy-syntax-table (syntax-table))) |
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
765 (slist imenu-syntax-alist)) |
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
766 ;; Modify the syntax table used while matching regexps. |
31a8ad177c4c
(imenu-syntax-alist): New buffer-local variable.
Dave Love <fx@gnu.org>
parents:
20769
diff
changeset
|
767 (while slist |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
768 ;; The character(s) to modify may be a single char or a string. |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
769 (if (numberp (caar slist)) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
770 (modify-syntax-entry (caar slist) (cdar slist) table) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
771 (mapcar (function |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
772 (lambda (c) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
773 (modify-syntax-entry c (cdar slist) table))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
774 (caar slist))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
775 (setq slist (cdr slist))) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
776 (goto-char (point-max)) |
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
777 (imenu-progress-message prev-pos 0 t) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
778 (unwind-protect ; for syntax table |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
779 (save-match-data |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
780 (set-syntax-table table) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
781 ;; map over the elements of imenu-generic-expression |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
782 ;; (typically functions, variables ...) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
783 (mapcar |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
784 (function |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
785 (lambda (pat) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
786 (let ((menu-title (car pat)) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
787 (regexp (nth 1 pat)) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
788 (index (nth 2 pat)) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
789 (function (nth 3 pat)) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
790 (rest (nthcdr 4 pat))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
791 ;; Go backwards for convenience of adding items in order. |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
792 (goto-char (point-max)) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
793 (while (re-search-backward regexp nil t) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
794 (imenu-progress-message prev-pos nil t) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
795 (setq beg (match-beginning index)) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
796 ;; Add this sort of submenu only when we've found an |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
797 ;; item for it, avoiding empty, duff menus. |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
798 (unless (assoc menu-title index-alist) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
799 (push (list menu-title) index-alist)) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
800 (if imenu-use-markers |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
801 (setq beg (set-marker (make-marker) beg))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
802 (let ((item |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
803 (if function |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
804 (nconc (list (match-string-no-properties index) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
805 beg function) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
806 rest) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
807 (cons (match-string-no-properties index) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
808 beg))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
809 (menu (cdr (assoc menu-title index-alist)))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
810 ;; avoid duplicates from, e.g. cc-mode patterns |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
811 (unless (member item menu) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
812 ;; insert the item after the (sub-)menu title |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
813 (setcdr (assoc menu-title index-alist) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
814 (cons item menu)))))))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
815 patterns) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
816 (set-syntax-table old-table))) |
14726
35e1cfdd29a4
(imenu--menubar-select): No longer interactive.
Richard M. Stallman <rms@gnu.org>
parents:
14725
diff
changeset
|
817 (imenu-progress-message prev-pos 100 t) |
35e1cfdd29a4
(imenu--menubar-select): No longer interactive.
Richard M. Stallman <rms@gnu.org>
parents:
14725
diff
changeset
|
818 (let ((main-element (assq nil index-alist))) |
16272
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
819 (nconc (delq main-element (delq 'dummy index-alist)) |
b64d00e44e7b
(imenu--split-menu): Keep the rescan item at top level.
Richard M. Stallman <rms@gnu.org>
parents:
16271
diff
changeset
|
820 (cdr main-element))))) |
10093
caafb376e619
(imenu-generic-expression): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
10072
diff
changeset
|
821 |
6230 | 822 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
823 ;;; | |
824 ;;; The main functions for this package! | |
825 ;;; | |
826 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
827 | |
828 (defun imenu--completion-buffer (index-alist &optional prompt) | |
829 "Let the user select from INDEX-ALIST in a completion buffer with PROMPT. | |
830 | |
831 Returns t for rescan and otherwise a position number." | |
832 ;; Create a list for this buffer only when needed. | |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
833 (let ((name (thing-at-point 'symbol)) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
834 choice |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
835 (prepared-index-alist |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
836 (mapcar |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
837 (function |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
838 (lambda (item) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
839 (cons (imenu--replace-spaces (car item) imenu-space-replacement) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
840 (cdr item)))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
841 index-alist))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
842 (cond (prompt) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
843 ((and name (imenu--in-alist name prepared-index-alist)) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
844 (setq prompt (format "Index item (default %s): " name))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
845 (t (setq prompt "Index item: "))) |
10221
34b66bff7aec
(imenu-always-use-completion-buffer-p): A value of
Richard M. Stallman <rms@gnu.org>
parents:
10093
diff
changeset
|
846 (if (eq imenu-always-use-completion-buffer-p 'never) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
847 (setq name (completing-read prompt |
10221
34b66bff7aec
(imenu-always-use-completion-buffer-p): A value of
Richard M. Stallman <rms@gnu.org>
parents:
10093
diff
changeset
|
848 prepared-index-alist |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
849 nil t nil 'imenu--history-list name)) |
10221
34b66bff7aec
(imenu-always-use-completion-buffer-p): A value of
Richard M. Stallman <rms@gnu.org>
parents:
10093
diff
changeset
|
850 (save-window-excursion |
34b66bff7aec
(imenu-always-use-completion-buffer-p): A value of
Richard M. Stallman <rms@gnu.org>
parents:
10093
diff
changeset
|
851 ;; Display the completion buffer |
34b66bff7aec
(imenu-always-use-completion-buffer-p): A value of
Richard M. Stallman <rms@gnu.org>
parents:
10093
diff
changeset
|
852 (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
|
853 (display-completion-list |
34b66bff7aec
(imenu-always-use-completion-buffer-p): A value of
Richard M. Stallman <rms@gnu.org>
parents:
10093
diff
changeset
|
854 (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
|
855 (let ((minibuffer-setup-hook |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
856 (function |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
857 (lambda () |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
858 (let ((buffer (current-buffer))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
859 (save-excursion |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
860 (set-buffer "*Completions*") |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
861 (setq completion-reference-buffer buffer))))))) |
10221
34b66bff7aec
(imenu-always-use-completion-buffer-p): A value of
Richard M. Stallman <rms@gnu.org>
parents:
10093
diff
changeset
|
862 ;; Make a completion question |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
863 (setq name (completing-read prompt |
10221
34b66bff7aec
(imenu-always-use-completion-buffer-p): A value of
Richard M. Stallman <rms@gnu.org>
parents:
10093
diff
changeset
|
864 prepared-index-alist |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
865 nil t nil 'imenu--history-list name))))) |
7350
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
866 (cond ((not (stringp name)) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
867 nil) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
868 ((string= name (car imenu--rescan-item)) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
869 t) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
870 (t |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
871 (setq choice (assoc name prepared-index-alist)) |
16271
00bece0cd6c2
(imenu--generic-function): Create a special entry
Richard M. Stallman <rms@gnu.org>
parents:
16244
diff
changeset
|
872 (if (imenu--subalist-p choice) |
7350
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
873 (imenu--completion-buffer (cdr choice) prompt) |
542ab48d0f18
(imenu-default-create-index-function):
Richard M. Stallman <rms@gnu.org>
parents:
7319
diff
changeset
|
874 choice))))) |
7319
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
875 |
6230 | 876 (defun imenu--mouse-menu (index-alist event &optional title) |
877 "Let the user select from a buffer index from a mouse menu. | |
878 | |
879 INDEX-ALIST is the buffer index and EVENT is a mouse event. | |
880 | |
16148
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
881 Returns t for rescan and otherwise an element or subelement of INDEX-ALIST." |
14726
35e1cfdd29a4
(imenu--menubar-select): No longer interactive.
Richard M. Stallman <rms@gnu.org>
parents:
14725
diff
changeset
|
882 (setq index-alist (imenu--split-submenus index-alist)) |
16148
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
883 (let* ((menu (imenu--split-menu index-alist |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
884 (or title (buffer-name)))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
885 position) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
886 (setq menu (imenu--create-keymap-1 (car menu) |
15374
6b1faae68eba
(imenu--mouse-menu): Always use nested keymaps.
Richard M. Stallman <rms@gnu.org>
parents:
15335
diff
changeset
|
887 (if (< 1 (length (cdr menu))) |
6b1faae68eba
(imenu--mouse-menu): Always use nested keymaps.
Richard M. Stallman <rms@gnu.org>
parents:
15335
diff
changeset
|
888 (cdr menu) |
16148
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
889 (cdr (car (cdr menu)))))) |
6230 | 890 (setq position (x-popup-menu event menu)) |
16148
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
891 (cond ((eq position nil) |
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
892 position) |
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
893 ;; If one call to x-popup-menu handled the nested menus, |
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
894 ;; find the result by looking down the menus here. |
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
895 ((and (listp position) |
15411
9691904c57a5
(imenu--mouse-menu): Don't check imenu-use-keymap-menu.
Richard M. Stallman <rms@gnu.org>
parents:
15374
diff
changeset
|
896 (numberp (car position)) |
9691904c57a5
(imenu--mouse-menu): Don't check imenu-use-keymap-menu.
Richard M. Stallman <rms@gnu.org>
parents:
15374
diff
changeset
|
897 (stringp (nth (1- (length position)) position))) |
16148
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
898 (let ((final menu)) |
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
899 (while position |
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
900 (setq final (assoc (car position) final)) |
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
901 (setq position (cdr position))) |
16236
52620db97569
(imenu--mouse-menu): Add special handling for rescan item.
Richard M. Stallman <rms@gnu.org>
parents:
16148
diff
changeset
|
902 (or (string= (car final) (car imenu--rescan-item)) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
903 (nthcdr 3 final)))) |
16148
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
904 ;; If x-popup-menu went just one level and found a leaf item, |
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
905 ;; return the INDEX-ALIST element for that. |
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
906 ((and (consp position) |
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
907 (stringp (car position)) |
15411
9691904c57a5
(imenu--mouse-menu): Don't check imenu-use-keymap-menu.
Richard M. Stallman <rms@gnu.org>
parents:
15374
diff
changeset
|
908 (null (cdr position))) |
16148
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
909 (or (string= (car position) (car imenu--rescan-item)) |
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
910 (assq (car position) index-alist))) |
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
911 ;; If x-popup-menu went just one level |
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
912 ;; and found a non-leaf item (a submenu), |
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
913 ;; recurse to handle the rest. |
15411
9691904c57a5
(imenu--mouse-menu): Don't check imenu-use-keymap-menu.
Richard M. Stallman <rms@gnu.org>
parents:
15374
diff
changeset
|
914 ((listp position) |
9691904c57a5
(imenu--mouse-menu): Don't check imenu-use-keymap-menu.
Richard M. Stallman <rms@gnu.org>
parents:
15374
diff
changeset
|
915 (imenu--mouse-menu position event |
9691904c57a5
(imenu--mouse-menu): Don't check imenu-use-keymap-menu.
Richard M. Stallman <rms@gnu.org>
parents:
15374
diff
changeset
|
916 (if title |
9691904c57a5
(imenu--mouse-menu): Don't check imenu-use-keymap-menu.
Richard M. Stallman <rms@gnu.org>
parents:
15374
diff
changeset
|
917 (concat title imenu-level-separator |
9691904c57a5
(imenu--mouse-menu): Don't check imenu-use-keymap-menu.
Richard M. Stallman <rms@gnu.org>
parents:
15374
diff
changeset
|
918 (car (rassq position index-alist))) |
16148
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
919 (car (rassq position index-alist)))))))) |
6230 | 920 |
6241 | 921 (defun imenu-choose-buffer-index (&optional prompt alist) |
6230 | 922 "Let the user select from a buffer index and return the chosen index. |
923 | |
924 If the user originally activated this function with the mouse, a mouse | |
925 menu is used. Otherwise a completion buffer is used and the user is | |
926 prompted with PROMPT. | |
927 | |
6241 | 928 If you call this function with index alist ALIST, then it lets the user |
929 select from ALIST. | |
930 | |
6909
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
931 With no index alist ALIST, it calls `imenu--make-index-alist' to |
6241 | 932 create the index alist. |
933 | |
6909
9e59751db725
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
6241
diff
changeset
|
934 If `imenu-always-use-completion-buffer-p' is non-nil, then the |
6230 | 935 completion buffer is always used, no matter if the mouse was used or |
936 not. | |
937 | |
16369
187e7c8aaff5
(imenu--make-index-alist): Add doc string.
Richard M. Stallman <rms@gnu.org>
parents:
16315
diff
changeset
|
938 The returned value is of the form (INDEX-NAME . INDEX-POSITION)." |
6230 | 939 (let (index-alist |
8296
b2b493c007ff
(imenu-choose-buffer-index): Use last-nonmenu-event
Richard M. Stallman <rms@gnu.org>
parents:
8256
diff
changeset
|
940 (mouse-triggered (listp last-nonmenu-event)) |
6230 | 941 (result t) ) |
942 ;; If selected by mouse, see to that the window where the mouse is | |
943 ;; really is selected. | |
944 (and mouse-triggered | |
12396
d0c82df80d70
(imenu-choose-buffer-index): Understand that (menu-bar)
Richard M. Stallman <rms@gnu.org>
parents:
12394
diff
changeset
|
945 (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
|
946 (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
|
947 (or (framep window) (null window) (select-window window)))) |
6230 | 948 ;; Create a list for this buffer only when needed. |
949 (while (eq result t) | |
6241 | 950 (setq index-alist (if alist alist (imenu--make-index-alist))) |
6230 | 951 (setq result |
952 (if (and mouse-triggered | |
953 (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
|
954 (imenu--mouse-menu index-alist last-nonmenu-event) |
6230 | 955 (imenu--completion-buffer index-alist prompt))) |
956 (and (eq result t) | |
8408
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
957 (imenu--cleanup) |
6230 | 958 (setq imenu--index-alist nil))) |
959 result)) | |
960 | |
12394
4fbc70e4d5e7
(imenu-use-keymap-menu): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10795
diff
changeset
|
961 ;;;###autoload |
8408
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
962 (defun imenu-add-to-menubar (name) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
963 "Add an `imenu' entry to the menu bar for the current buffer. |
13798
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
964 NAME is a string used to name the menu bar item. |
14657
4bedd113757f
(imenu-add-to-menubar): Add menu item for current buf only.
Richard M. Stallman <rms@gnu.org>
parents:
14656
diff
changeset
|
965 See the command `imenu' for more information." |
13798
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
966 (interactive "sImenu menu item name: ") |
20249
c42156dab61b
(imenu-default-create-index-function):
Karl Heuer <kwzh@gnu.org>
parents:
20051
diff
changeset
|
967 (if (or (and imenu-prev-index-position-function |
c42156dab61b
(imenu-default-create-index-function):
Karl Heuer <kwzh@gnu.org>
parents:
20051
diff
changeset
|
968 imenu-extract-index-name-function) |
c42156dab61b
(imenu-default-create-index-function):
Karl Heuer <kwzh@gnu.org>
parents:
20051
diff
changeset
|
969 imenu-generic-expression |
c42156dab61b
(imenu-default-create-index-function):
Karl Heuer <kwzh@gnu.org>
parents:
20051
diff
changeset
|
970 (not (eq imenu-create-index-function |
c42156dab61b
(imenu-default-create-index-function):
Karl Heuer <kwzh@gnu.org>
parents:
20051
diff
changeset
|
971 'imenu-default-create-index-function))) |
c42156dab61b
(imenu-default-create-index-function):
Karl Heuer <kwzh@gnu.org>
parents:
20051
diff
changeset
|
972 (let ((newmap (make-sparse-keymap)) |
c42156dab61b
(imenu-default-create-index-function):
Karl Heuer <kwzh@gnu.org>
parents:
20051
diff
changeset
|
973 (menu-bar (lookup-key (current-local-map) [menu-bar]))) |
c42156dab61b
(imenu-default-create-index-function):
Karl Heuer <kwzh@gnu.org>
parents:
20051
diff
changeset
|
974 (define-key newmap [menu-bar] |
c42156dab61b
(imenu-default-create-index-function):
Karl Heuer <kwzh@gnu.org>
parents:
20051
diff
changeset
|
975 (append (make-sparse-keymap) menu-bar)) |
c42156dab61b
(imenu-default-create-index-function):
Karl Heuer <kwzh@gnu.org>
parents:
20051
diff
changeset
|
976 (define-key newmap [menu-bar index] |
c42156dab61b
(imenu-default-create-index-function):
Karl Heuer <kwzh@gnu.org>
parents:
20051
diff
changeset
|
977 (cons name (nconc (make-sparse-keymap "Imenu") |
c42156dab61b
(imenu-default-create-index-function):
Karl Heuer <kwzh@gnu.org>
parents:
20051
diff
changeset
|
978 (make-sparse-keymap)))) |
c42156dab61b
(imenu-default-create-index-function):
Karl Heuer <kwzh@gnu.org>
parents:
20051
diff
changeset
|
979 (use-local-map (append newmap (current-local-map))) |
c42156dab61b
(imenu-default-create-index-function):
Karl Heuer <kwzh@gnu.org>
parents:
20051
diff
changeset
|
980 (add-hook 'menu-bar-update-hook 'imenu-update-menubar)) |
17229
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
981 (error "The mode `%s' does not support Imenu" mode-name))) |
13798
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
982 |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
983 ;;;###autoload |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
984 (defun imenu-add-menubar-index () |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
985 "Add an Imenu \"Index\" entry on the menu bar for the current buffer. |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
986 |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
987 A trivial interface to `imenu-add-to-menubar' suitable for use in a hook." |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
988 (interactive) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
989 (imenu-add-to-menubar "Index")) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
990 |
14642
01e8fdb45deb
(imenu-buffer-menubar): Add defvar.
Karl Heuer <kwzh@gnu.org>
parents:
14575
diff
changeset
|
991 (defvar imenu-buffer-menubar nil) |
01e8fdb45deb
(imenu-buffer-menubar): Add defvar.
Karl Heuer <kwzh@gnu.org>
parents:
14575
diff
changeset
|
992 |
13798
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
993 (defun imenu-update-menubar () |
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
994 (and (current-local-map) |
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
995 (keymapp (lookup-key (current-local-map) [menu-bar index])) |
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
996 (let ((index-alist (imenu--make-index-alist t))) |
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
997 ;; 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
|
998 ;; since the last time we did it. |
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
999 (or (equal index-alist imenu--last-menubar-index-alist) |
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
1000 (let (menu menu1 old) |
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
1001 (setq imenu--last-menubar-index-alist index-alist) |
14726
35e1cfdd29a4
(imenu--menubar-select): No longer interactive.
Richard M. Stallman <rms@gnu.org>
parents:
14725
diff
changeset
|
1002 (setq index-alist (imenu--split-submenus index-alist)) |
16148
8ca583c0b988
(imenu): Tests for when to widen were backwards.
Richard M. Stallman <rms@gnu.org>
parents:
15929
diff
changeset
|
1003 (setq menu (imenu--split-menu index-alist |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
1004 (buffer-name))) |
13798
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
1005 (setq menu1 (imenu--create-keymap-1 (car menu) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
1006 (if (< 1 (length (cdr menu))) |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
1007 (cdr menu) |
13798
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
1008 (cdr (car (cdr menu)))) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
1009 t)) |
13798
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
1010 (setq old (lookup-key (current-local-map) [menu-bar index])) |
15831
d110af120b19
(imenu-update-menubar): Fix code to install the new menu.
Richard M. Stallman <rms@gnu.org>
parents:
15411
diff
changeset
|
1011 (setcdr old (cdr menu1))))))) |
13798
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
1012 |
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
1013 (defun imenu--menubar-select (item) |
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
1014 "Use Imenu to select the function or variable named in this menu item." |
17229
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
1015 (if (equal item imenu--rescan-item) |
14796
29e7001fecf0
(imenu--menubar-select): Handle the "rescan" item.
Richard M. Stallman <rms@gnu.org>
parents:
14733
diff
changeset
|
1016 (progn |
29e7001fecf0
(imenu--menubar-select): Handle the "rescan" item.
Richard M. Stallman <rms@gnu.org>
parents:
14733
diff
changeset
|
1017 (imenu--cleanup) |
29e7001fecf0
(imenu--menubar-select): Handle the "rescan" item.
Richard M. Stallman <rms@gnu.org>
parents:
14733
diff
changeset
|
1018 (setq imenu--index-alist nil) |
29e7001fecf0
(imenu--menubar-select): Handle the "rescan" item.
Richard M. Stallman <rms@gnu.org>
parents:
14733
diff
changeset
|
1019 (imenu-update-menubar)) |
29e7001fecf0
(imenu--menubar-select): Handle the "rescan" item.
Richard M. Stallman <rms@gnu.org>
parents:
14733
diff
changeset
|
1020 (imenu item))) |
8408
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
1021 |
17229
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
1022 (defun imenu-default-goto-function (name position &optional rest) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
1023 "Move the point to the given position. |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
1024 |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
1025 NAME is ignored. POSITION is where to move. REST is also ignored. |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
1026 The ignored args just make this function have the same interface as a |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
1027 function placed in a special index-item." |
17307
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
1028 (if (or (< position (point-min)) |
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
1029 (> position (point-max))) |
17229
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
1030 ;; widen if outside narrowing |
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
1031 (widen)) |
17307
830ad59547e4
(imenu-default-goto-function): Simplify.
Richard M. Stallman <rms@gnu.org>
parents:
17230
diff
changeset
|
1032 (goto-char position)) |
17229
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
1033 |
7319
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
1034 ;;;###autoload |
12664
ce1cae301efe
(imenu--history-list): Don't make this buffer-local.
Richard M. Stallman <rms@gnu.org>
parents:
12635
diff
changeset
|
1035 (defun imenu (index-item) |
7319
cd73ba498964
(imenu): Renamed from goto-index-pos.
Richard M. Stallman <rms@gnu.org>
parents:
6909
diff
changeset
|
1036 "Jump to a place in the buffer chosen using a buffer menu or mouse menu. |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
1037 INDEX-ITEM specifies the position. See `imenu-choose-buffer-index' |
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
1038 for more information." |
16698
13920eac02e0
(imenu-generic-expression): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
16612
diff
changeset
|
1039 (interactive (list (imenu-choose-buffer-index))) |
13798
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
1040 ;; Convert a string to an alist element. |
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
1041 (if (stringp index-item) |
4eac65d000d3
(imenu-update-menubar): New function.
Karl Heuer <kwzh@gnu.org>
parents:
13645
diff
changeset
|
1042 (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
|
1043 (and index-item |
ce1cae301efe
(imenu--history-list): Don't make this buffer-local.
Richard M. Stallman <rms@gnu.org>
parents:
12635
diff
changeset
|
1044 (progn |
ce1cae301efe
(imenu--history-list): Don't make this buffer-local.
Richard M. Stallman <rms@gnu.org>
parents:
12635
diff
changeset
|
1045 (push-mark) |
17229
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
1046 (let* ((is-special-item (listp (cdr index-item))) |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
1047 (function |
17229
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
1048 (if is-special-item |
21852
5898cd2e4cd6
(imenu--generic-function): Doc fix. Rewritten to be faster.
Richard M. Stallman <rms@gnu.org>
parents:
20857
diff
changeset
|
1049 (nth 2 index-item) imenu-default-goto-function)) |
17229
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
1050 (position (if is-special-item |
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
1051 (cadr index-item) (cdr index-item))) |
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
1052 (rest (if is-special-item (cddr index-item)))) |
b48a8dd2d8ce
(imenu-scanning-message): Support for bigger numbers.
Richard M. Stallman <rms@gnu.org>
parents:
16698
diff
changeset
|
1053 (apply function (car index-item) position rest))))) |
8408
109166e311ce
(imenu, imenu--flatten-index-alist): Add marker support.
Richard M. Stallman <rms@gnu.org>
parents:
8296
diff
changeset
|
1054 |
6230 | 1055 (provide 'imenu) |
1056 | |
1057 ;;; imenu.el ends here |