annotate lisp/imenu.el @ 7248:48ef5c3465ae

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