annotate lisp/imenu.el @ 8240:363f719d47a5

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