annotate lisp/imenu.el @ 9073:43aa8427db01

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