Mercurial > emacs
annotate lisp/progmodes/which-func.el @ 94116:842d446b22d9
Cleanup the bug-report email addresses and make sure the
maintainer is still willing to handle bug reports.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Wed, 16 Apr 2008 14:10:34 +0000 |
parents | 107ccd98fa12 |
children | 606f2d163a64 52b7a8c22af5 |
rev | line source |
---|---|
51349 | 1 ;;; which-func.el --- print current function in mode line |
2 | |
79717 | 3 ;; Copyright (C) 1994, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
61089
dc55bf752d7c
(which-function): Be robust in the face of an
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58774
diff
changeset
|
4 ;; Free Software Foundation, Inc. |
51349 | 5 |
6 ;; Author: Alex Rezinsky <alexr@msil.sps.mot.com> | |
7 ;; (doesn't seem to be responsive any more) | |
8 ;; Keywords: mode-line, imenu, tools | |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
78234
c1ec1c8a8d2e
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
14 ;; the Free Software Foundation; either version 3, or (at your option) |
51349 | 15 ;; any later version. |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 ;; Boston, MA 02110-1301, USA. | |
51349 | 26 |
27 ;;; Commentary: | |
28 | |
29 ;; This package prints name of function where your current point is | |
30 ;; located in mode line. It assumes that you work with imenu package | |
31 ;; and imenu--index-alist is up to date. | |
32 | |
33 ;; KNOWN BUGS | |
34 ;; ---------- | |
35 ;; Really this package shows not "function where the current point is | |
36 ;; located now", but "nearest function which defined above the current | |
37 ;; point". So if your current point is located after end of function | |
38 ;; FOO but before begin of function BAR, FOO will be displayed in mode | |
39 ;; line. | |
40 ;; - if two windows display the same buffer, both windows | |
41 ;; show the same `which-func' information. | |
42 | |
43 ;; TODO LIST | |
44 ;; --------- | |
45 ;; 1. Dependence on imenu package should be removed. Separate | |
46 ;; function determination mechanism should be used to determine the end | |
47 ;; of a function as well as the beginning of a function. | |
48 ;; 2. This package should be realized with the help of overlay | |
49 ;; properties instead of imenu--index-alist variable. | |
50 | |
51 ;;; History: | |
52 | |
53 ;; THANKS TO | |
54 ;; --------- | |
55 ;; Per Abrahamsen <abraham@iesd.auc.dk> | |
56 ;; Some ideas (inserting in mode-line, using of post-command hook | |
57 ;; and toggling this mode) have been borrowed from his package | |
58 ;; column.el | |
59 ;; Peter Eisenhauer <pipe@fzi.de> | |
60 ;; Bug fixing in case nested indexes. | |
61 ;; Terry Tateyama <ttt@ursa0.cs.utah.edu> | |
62 ;; Suggestion to use find-file-hook for first imenu | |
63 ;; index building. | |
64 | |
65 ;;; Code: | |
66 | |
67 ;; Variables for customization | |
68 ;; --------------------------- | |
69 ;; | |
70 (defvar which-func-unknown "???" | |
71 "String to display in the mode line when current function is unknown.") | |
72 | |
73 (defgroup which-func nil | |
74 "Mode to display the current function name in the modeline." | |
75 :group 'tools | |
76 :version "20.3") | |
77 | |
78 (defcustom which-func-modes | |
81825
69b5e2969dfe
(which-func-modes): Add `python-mode'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75347
diff
changeset
|
79 '(emacs-lisp-mode c-mode c++-mode perl-mode cperl-mode python-mode |
84390
28620c3d5a1a
Added diff-mode to `which-func-modes'.
Masatake YAMATO <jet@gyve.org>
parents:
82365
diff
changeset
|
80 makefile-mode sh-mode fortran-mode f90-mode ada-mode |
28620c3d5a1a
Added diff-mode to `which-func-modes'.
Masatake YAMATO <jet@gyve.org>
parents:
82365
diff
changeset
|
81 diff-mode) |
51349 | 82 "List of major modes for which Which Function mode should be used. |
83 For other modes it is disabled. If this is equal to t, | |
84 then Which Function mode is enabled in any major mode that supports it." | |
85 :group 'which-func | |
86 :type '(choice (const :tag "All modes" t) | |
87 (repeat (symbol :tag "Major mode")))) | |
88 | |
89 (defcustom which-func-non-auto-modes nil | |
90 "List of major modes where Which Function mode is inactive till Imenu is used. | |
91 This means that Which Function mode won't really do anything | |
92 until you use Imenu, in these modes. Note that files | |
93 larger than `which-func-maxout' behave in this way too; | |
94 Which Function mode doesn't do anything until you use Imenu." | |
95 :group 'which-func | |
96 :type '(repeat (symbol :tag "Major mode"))) | |
97 | |
98 (defcustom which-func-maxout 500000 | |
99 "Don't automatically compute the Imenu menu if buffer is this big or bigger. | |
100 Zero means compute the Imenu menu regardless of size." | |
101 :group 'which-func | |
102 :type 'integer) | |
103 | |
56442
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
104 (defvar which-func-keymap |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
105 (let ((map (make-sparse-keymap))) |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
106 (define-key map [mode-line mouse-1] 'beginning-of-defun) |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
107 (define-key map [mode-line mouse-2] |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
108 (lambda () |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
109 (interactive) |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
110 (if (eq (point-min) 1) |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
111 (narrow-to-defun) |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
112 (widen)))) |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
113 (define-key map [mode-line mouse-3] 'end-of-defun) |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
114 map) |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
115 "Keymap to display on mode line which-func.") |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
116 |
63457
581fdd0b552d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-417
Miles Bader <miles@gnu.org>
parents:
62858
diff
changeset
|
117 (defface which-func |
63463
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
118 ;; Whether `font-lock-function-name-face' is an appropriate face to |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
119 ;; inherit depends on the mode-line face; define several variants based |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
120 ;; on the default mode-line face. |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
121 '(;; The default mode-line face on a high-color display is a relatively |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
122 ;; light color ("grey75"), and only the light-background variant of |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
123 ;; `font-lock-function-name-face' is visible against it. |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
124 (((class color) (min-colors 88) (background light)) |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
125 :inherit font-lock-function-name-face) |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
126 ;; The default mode-line face on other display types is inverse-video; |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
127 ;; it seems that only in the dark-background case is |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
128 ;; `font-lock-function-name-face' visible against it. |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
129 (((class grayscale mono) (background dark)) |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
130 :inherit font-lock-function-name-face) |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
131 (((class color) (background light)) |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
132 :inherit font-lock-function-name-face) |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
133 ;; If none of the above cases, use an explicit color chosen to contrast |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
134 ;; well with the default mode-line face. |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
135 (((class color) (min-colors 88) (background dark)) |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
136 :foreground "Blue1") |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
137 (((background dark)) |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
138 :foreground "Blue1") |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
139 (t |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
140 :foreground "LightSkyBlue")) |
ad343539d42b
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421
Miles Bader <miles@gnu.org>
parents:
63457
diff
changeset
|
141 "Face used to highlight mode line function names." |
56442
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
142 :group 'which-func) |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
143 |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
144 (defcustom which-func-format |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
145 `("[" |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
146 (:propertize which-func-current |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
147 local-map ,which-func-keymap |
63457
581fdd0b552d
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-417
Miles Bader <miles@gnu.org>
parents:
62858
diff
changeset
|
148 face which-func |
56442
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
149 ;;mouse-face highlight ; currently not evaluated :-( |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
150 help-echo "mouse-1: go to beginning, mouse-2: toggle rest visibility, mouse-3: go to end") |
e8032355ca23
(which-func-keymap): New var.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
53618
diff
changeset
|
151 "]") |
51349 | 152 "Format for displaying the function in the mode line." |
153 :group 'which-func | |
154 :type 'sexp) | |
155 ;;;###autoload (put 'which-func-format 'risky-local-variable t) | |
156 | |
157 (defvar which-func-cleanup-function nil | |
158 "Function to transform a string before displaying it in the mode line. | |
159 The function is called with one argument, the string to display. | |
160 Its return value is displayed in the modeline. | |
161 If nil, no function is called. The default value is nil. | |
162 | |
163 This feature can be useful if Imenu is set up to make more | |
164 detailed entries (e.g., containing the argument list of a function), | |
165 and you want to simplify them for the mode line | |
166 \(e.g., removing the parameter list to just have the function name.)") | |
167 | |
168 ;;; Code, nothing to customize below here | |
169 ;;; ------------------------------------- | |
170 ;;; | |
171 (require 'imenu) | |
172 | |
173 (defvar which-func-table (make-hash-table :test 'eq :weakness 'key)) | |
174 | |
175 (defconst which-func-current | |
176 '(:eval (gethash (selected-window) which-func-table which-func-unknown))) | |
177 ;;;###autoload (put 'which-func-current 'risky-local-variable t) | |
178 | |
179 (defvar which-func-mode nil | |
180 "Non-nil means display current function name in mode line. | |
181 This makes a difference only if `which-function-mode' is non-nil.") | |
182 (make-variable-buffer-local 'which-func-mode) | |
183 ;;(put 'which-func-mode 'permanent-local t) | |
184 | |
185 (add-hook 'find-file-hook 'which-func-ff-hook t) | |
186 | |
187 (defun which-func-ff-hook () | |
188 "File find hook for Which Function mode. | |
189 It creates the Imenu index for the buffer, if necessary." | |
190 (setq which-func-mode | |
191 (and which-function-mode | |
192 (or (eq which-func-modes t) | |
193 (member major-mode which-func-modes)))) | |
194 | |
195 (condition-case nil | |
196 (if (and which-func-mode | |
197 (not (member major-mode which-func-non-auto-modes)) | |
198 (or (null which-func-maxout) | |
199 (< buffer-saved-size which-func-maxout) | |
200 (= which-func-maxout 0))) | |
201 (setq imenu--index-alist | |
202 (save-excursion (funcall imenu-create-index-function)))) | |
203 (error | |
204 (setq which-func-mode nil)))) | |
205 | |
206 (defun which-func-update () | |
207 ;; "Update the Which-Function mode display for all windows." | |
208 ;; (walk-windows 'which-func-update-1 nil 'visible)) | |
209 (which-func-update-1 (selected-window))) | |
210 | |
211 (defun which-func-update-1 (window) | |
56689
f54e121491eb
(which-func-update-1): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
56442
diff
changeset
|
212 "Update the Which Function mode display for window WINDOW." |
51349 | 213 (with-selected-window window |
214 (when which-func-mode | |
215 (condition-case info | |
216 (let ((current (which-function))) | |
217 (unless (equal current (gethash window which-func-table)) | |
218 (puthash window current which-func-table) | |
219 (force-mode-line-update))) | |
220 (error | |
62858
c23f28be371c
(which-func-update-1): Turn the mode
Richard M. Stallman <rms@gnu.org>
parents:
61089
diff
changeset
|
221 (setq which-func-mode nil) |
51349 | 222 (error "Error in which-func-update: %s" info)))))) |
223 | |
224 ;;;###autoload | |
225 (defalias 'which-func-mode 'which-function-mode) | |
226 | |
227 (defvar which-func-update-timer nil) | |
228 | |
229 ;; This is the name people would normally expect. | |
230 ;;;###autoload | |
231 (define-minor-mode which-function-mode | |
232 "Toggle Which Function mode, globally. | |
233 When Which Function mode is enabled, the current function name is | |
234 continuously displayed in the mode line, in certain major modes. | |
235 | |
78487
419c5c316b51
Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents:
78234
diff
changeset
|
236 With prefix ARG, turn Which Function mode on if arg is positive, |
51349 | 237 and off otherwise." |
238 :global t :group 'which-func | |
239 (if which-function-mode | |
240 ;;Turn it on | |
241 (progn | |
242 (setq which-func-update-timer | |
243 (run-with-idle-timer idle-update-delay t 'which-func-update)) | |
244 (dolist (buf (buffer-list)) | |
245 (with-current-buffer buf | |
246 (setq which-func-mode | |
247 (or (eq which-func-modes t) | |
248 (member major-mode which-func-modes)))))) | |
249 ;; Turn it off | |
53618
bd715b02e44e
David Ponce <david@dponce.com>
Glenn Morris <rgm@gnu.org>
parents:
52691
diff
changeset
|
250 (when (timerp which-func-update-timer) |
bd715b02e44e
David Ponce <david@dponce.com>
Glenn Morris <rgm@gnu.org>
parents:
52691
diff
changeset
|
251 (cancel-timer which-func-update-timer)) |
51349 | 252 (setq which-func-update-timer nil) |
253 (dolist (buf (buffer-list)) | |
254 (with-current-buffer buf (setq which-func-mode nil))))) | |
255 | |
256 (defvar which-function-imenu-failed nil | |
257 "Locally t in a buffer if `imenu--make-index-alist' found nothing there.") | |
258 | |
52691
ccda1b53b035
(which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
259 (defvar which-func-functions nil |
ccda1b53b035
(which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
260 "List of functions for `which-function' to call with no arguments. |
ccda1b53b035
(which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
261 It calls them sequentially, and if any returns non-nil, |
ccda1b53b035
(which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
262 `which-function' uses that name and stops looking for the name.") |
ccda1b53b035
(which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
263 |
51349 | 264 (defun which-function () |
265 "Return current function name based on point. | |
72144
2824d0383afd
(which-function): Fix documentation/comment typo.
Nick Roberts <nickrob@snap.net.nz>
parents:
68773
diff
changeset
|
266 Uses `which-func-functions', `imenu--index-alist' |
52691
ccda1b53b035
(which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
267 or `add-log-current-defun-function'. |
51349 | 268 If no function name is found, return nil." |
58774 | 269 (let ((name |
72144
2824d0383afd
(which-function): Fix documentation/comment typo.
Nick Roberts <nickrob@snap.net.nz>
parents:
68773
diff
changeset
|
270 ;; Try the `which-func-functions' functions first. |
58774 | 271 (run-hook-with-args-until-success 'which-func-functions))) |
52691
ccda1b53b035
(which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
272 |
51349 | 273 ;; If Imenu is loaded, try to make an index alist with it. |
52691
ccda1b53b035
(which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
274 (when (and (null name) |
ccda1b53b035
(which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
275 (boundp 'imenu--index-alist) (null imenu--index-alist) |
51349 | 276 (null which-function-imenu-failed)) |
61089
dc55bf752d7c
(which-function): Be robust in the face of an
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58774
diff
changeset
|
277 (imenu--make-index-alist t) |
51349 | 278 (unless imenu--index-alist |
279 (make-local-variable 'which-function-imenu-failed) | |
280 (setq which-function-imenu-failed t))) | |
281 ;; If we have an index alist, use it. | |
52691
ccda1b53b035
(which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
282 (when (and (null name) |
ccda1b53b035
(which-func-modes): Add ada-mode.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
283 (boundp 'imenu--index-alist) imenu--index-alist) |
51349 | 284 (let ((alist imenu--index-alist) |
285 (minoffset (point-max)) | |
286 offset elem pair mark) | |
287 (while alist | |
288 (setq elem (car-safe alist) | |
289 alist (cdr-safe alist)) | |
290 ;; Elements of alist are either ("name" . marker), or | |
291 ;; ("submenu" ("name" . marker) ... ). | |
292 (unless (listp (cdr elem)) | |
293 (setq elem (list elem))) | |
294 (while elem | |
295 (setq pair (car elem) | |
296 elem (cdr elem)) | |
297 (and (consp pair) | |
298 (number-or-marker-p (setq mark (cdr pair))) | |
299 (if (>= (setq offset (- (point) mark)) 0) | |
300 (if (< offset minoffset) ; find the closest item | |
301 (setq minoffset offset | |
302 name (car pair))) | |
303 ;; Entries in order, so can skip all those after point. | |
304 (setq elem nil))))))) | |
305 ;; Try using add-log support. | |
306 (when (and (null name) (boundp 'add-log-current-defun-function) | |
307 add-log-current-defun-function) | |
308 (setq name (funcall add-log-current-defun-function))) | |
309 ;; Filter the name if requested. | |
310 (when name | |
311 (if which-func-cleanup-function | |
312 (funcall which-func-cleanup-function name) | |
313 name)))) | |
314 | |
315 (provide 'which-func) | |
316 | |
61089
dc55bf752d7c
(which-function): Be robust in the face of an
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58774
diff
changeset
|
317 ;; arch-tag: fa8a55c7-bfe3-4ffc-95ab-01bf21796827 |
51349 | 318 ;;; which-func.el ends here |