annotate lisp/imenu.el @ 11488:d5ede70b5897

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