Mercurial > emacs
annotate lisp/which-func.el @ 51260:a51376ab4a2e
(global-map): Bind M-S-<backspace to
kill-whole-line.
author | Kai Großjohann <kgrossjo@eu.uu.net> |
---|---|
date | Tue, 27 May 2003 13:57:22 +0000 |
parents | 62a2a306bc43 |
children |
rev | line source |
---|---|
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
38423
diff
changeset
|
1 ;;; which-func.el --- print current function in mode line |
20321 | 2 |
51052
322e59c8a00c
(which-func-format): Make it risky-local-variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50649
diff
changeset
|
3 ;; Copyright (C) 1994, 1997, 1998, 2001, 2003 Free Software Foundation, Inc. |
20321 | 4 |
5 ;; Author: Alex Rezinsky <alexr@msil.sps.mot.com> | |
33702
683f3781ab81
Update maintainer line.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32190
diff
changeset
|
6 ;; (doesn't seem to be responsive any more) |
21697 | 7 ;; Keywords: mode-line, imenu, tools |
20321 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
21697 | 26 ;;; Commentary: |
27 | |
28 ;; This package prints name of function where your current point is | |
29 ;; located in mode line. It assumes that you work with imenu package | |
30 ;; and imenu--index-alist is up to date. | |
20321 | 31 |
21697 | 32 ;; KNOWN BUGS |
33 ;; ---------- | |
34 ;; Really this package shows not "function where the current point is | |
35 ;; located now", but "nearest function which defined above the current | |
36 ;; point". So if your current point is located after end of function | |
37 ;; FOO but before begin of function BAR, FOO will be displayed in mode | |
38 ;; line. | |
36606
a72b3da04728
(which-func-modes): Add cperl-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35990
diff
changeset
|
39 ;; - if two windows display the same buffer, both windows |
a72b3da04728
(which-func-modes): Add cperl-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35990
diff
changeset
|
40 ;; show the same `which-func' information. |
20321 | 41 |
21697 | 42 ;; TODO LIST |
43 ;; --------- | |
44 ;; 1. Dependence on imenu package should be removed. Separate | |
45 ;; function determination mechanism should be used to determine the end | |
46 ;; of a function as well as the beginning of a function. | |
47 ;; 2. This package should be realized with the help of overlay | |
48 ;; properties instead of imenu--index-alist variable. | |
49 | |
50 ;;; History: | |
20321 | 51 |
21697 | 52 ;; THANKS TO |
53 ;; --------- | |
54 ;; Per Abrahamsen <abraham@iesd.auc.dk> | |
55 ;; Some ideas (inserting in mode-line, using of post-command hook | |
56 ;; and toggling this mode) have been borrowed from his package | |
57 ;; column.el | |
58 ;; Peter Eisenhauer <pipe@fzi.de> | |
59 ;; Bug fixing in case nested indexes. | |
60 ;; Terry Tateyama <ttt@ursa0.cs.utah.edu> | |
46899
f00337f04e78
Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41357
diff
changeset
|
61 ;; Suggestion to use find-file-hook for first imenu |
21697 | 62 ;; index building. |
20321 | 63 |
21697 | 64 ;;; Code: |
65 | |
66 ;; Variables for customization | |
67 ;; --------------------------- | |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
46899
diff
changeset
|
68 ;; |
20321 | 69 (defvar which-func-unknown "???" |
70 "String to display in the mode line when current function is unknown.") | |
71 | |
21653
e95a88dc6110
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20573
diff
changeset
|
72 (defgroup which-func nil |
e95a88dc6110
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20573
diff
changeset
|
73 "Mode to display the current function name in the modeline." |
e95a88dc6110
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20573
diff
changeset
|
74 :group 'tools |
e95a88dc6110
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20573
diff
changeset
|
75 :version "20.3") |
e95a88dc6110
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20573
diff
changeset
|
76 |
32190
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
77 (defcustom which-func-modes |
36606
a72b3da04728
(which-func-modes): Add cperl-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35990
diff
changeset
|
78 '(emacs-lisp-mode c-mode c++-mode perl-mode cperl-mode makefile-mode |
50649
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
79 sh-mode fortran-mode f90-mode) |
22134
29c2db002dd5
(which-func-modes): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents:
21964
diff
changeset
|
80 "List of major modes for which Which Function mode should be used. |
20321 | 81 For other modes it is disabled. If this is equal to t, |
22134
29c2db002dd5
(which-func-modes): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents:
21964
diff
changeset
|
82 then Which Function mode is enabled in any major mode that supports it." |
20321 | 83 :group 'which-func |
84 :type '(choice (const :tag "All modes" t) | |
22134
29c2db002dd5
(which-func-modes): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents:
21964
diff
changeset
|
85 (repeat (symbol :tag "Major mode")))) |
20321 | 86 |
21964
390352ec56c6
(which-func-non-auto-modes): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
21960
diff
changeset
|
87 (defcustom which-func-non-auto-modes nil |
390352ec56c6
(which-func-non-auto-modes): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
21960
diff
changeset
|
88 "List of major modes where Which Function mode is inactive till Imenu is used. |
22134
29c2db002dd5
(which-func-modes): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents:
21964
diff
changeset
|
89 This means that Which Function mode won't really do anything |
29c2db002dd5
(which-func-modes): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents:
21964
diff
changeset
|
90 until you use Imenu, in these modes. Note that files |
29c2db002dd5
(which-func-modes): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents:
21964
diff
changeset
|
91 larger than `which-func-maxout' behave in this way too; |
29c2db002dd5
(which-func-modes): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents:
21964
diff
changeset
|
92 Which Function mode doesn't do anything until you use Imenu." |
20321 | 93 :group 'which-func |
22134
29c2db002dd5
(which-func-modes): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents:
21964
diff
changeset
|
94 :type '(repeat (symbol :tag "Major mode"))) |
20321 | 95 |
38194
a23820c19d03
(which-func-maxout): Increase default to 500000.
Richard M. Stallman <rms@gnu.org>
parents:
36606
diff
changeset
|
96 (defcustom which-func-maxout 500000 |
20321 | 97 "Don't automatically compute the Imenu menu if buffer is this big or bigger. |
98 Zero means compute the Imenu menu regardless of size." | |
99 :group 'which-func | |
100 :type 'integer) | |
101 | |
32190
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
102 (defcustom which-func-format '("[" which-func-current "]") |
20321 | 103 "Format for displaying the function in the mode line." |
104 :group 'which-func | |
105 :type 'sexp) | |
51069
20b5efbd58c6
(which-func-current, which-func-format):
Richard M. Stallman <rms@gnu.org>
parents:
51052
diff
changeset
|
106 ;;;###autoload (put 'which-func-format 'risky-local-variable t) |
20321 | 107 |
25425
f85f374e5395
(which-func-cleanup-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24649
diff
changeset
|
108 (defvar which-func-cleanup-function nil |
f85f374e5395
(which-func-cleanup-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24649
diff
changeset
|
109 "Function to transform a string before displaying it in the mode line. |
f85f374e5395
(which-func-cleanup-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24649
diff
changeset
|
110 The function is called with one argument, the string to display. |
f85f374e5395
(which-func-cleanup-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24649
diff
changeset
|
111 Its return value is displayed in the modeline. |
f85f374e5395
(which-func-cleanup-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24649
diff
changeset
|
112 If nil, no function is called. The default value is nil. |
f85f374e5395
(which-func-cleanup-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24649
diff
changeset
|
113 |
f85f374e5395
(which-func-cleanup-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24649
diff
changeset
|
114 This feature can be useful if Imenu is set up to make more |
f85f374e5395
(which-func-cleanup-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24649
diff
changeset
|
115 detailed entries (e.g., containing the argument list of a function), |
f85f374e5395
(which-func-cleanup-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24649
diff
changeset
|
116 and you want to simplify them for the mode line |
f85f374e5395
(which-func-cleanup-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24649
diff
changeset
|
117 \(e.g., removing the parameter list to just have the function name.)") |
f85f374e5395
(which-func-cleanup-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24649
diff
changeset
|
118 |
20321 | 119 ;;; Code, nothing to customize below here |
120 ;;; ------------------------------------- | |
121 ;;; | |
122 (require 'imenu) | |
123 | |
51052
322e59c8a00c
(which-func-format): Make it risky-local-variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50649
diff
changeset
|
124 (defvar which-func-table (make-hash-table :test 'eq :weakness 'key)) |
322e59c8a00c
(which-func-format): Make it risky-local-variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50649
diff
changeset
|
125 |
322e59c8a00c
(which-func-format): Make it risky-local-variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50649
diff
changeset
|
126 (defconst which-func-current |
322e59c8a00c
(which-func-format): Make it risky-local-variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50649
diff
changeset
|
127 '(:eval (gethash (selected-window) which-func-table which-func-unknown))) |
51069
20b5efbd58c6
(which-func-current, which-func-format):
Richard M. Stallman <rms@gnu.org>
parents:
51052
diff
changeset
|
128 ;;;###autoload (put 'which-func-current 'risky-local-variable t) |
20321 | 129 |
130 (defvar which-func-mode nil | |
131 "Non-nil means display current function name in mode line. | |
38437 | 132 This makes a difference only if `which-function-mode' is non-nil.") |
20321 | 133 (make-variable-buffer-local 'which-func-mode) |
32190
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
134 ;;(put 'which-func-mode 'permanent-local t) |
20321 | 135 |
46899
f00337f04e78
Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41357
diff
changeset
|
136 (add-hook 'find-file-hook 'which-func-ff-hook t) |
20321 | 137 |
138 (defun which-func-ff-hook () | |
139 "File find hook for Which Function mode. | |
140 It creates the Imenu index for the buffer, if necessary." | |
32190
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
141 (setq which-func-mode |
38405
d215f2e13397
(which-func-mode, which-func-ff-hook)
Gerd Moellmann <gerd@gnu.org>
parents:
38194
diff
changeset
|
142 (and which-function-mode |
d215f2e13397
(which-func-mode, which-func-ff-hook)
Gerd Moellmann <gerd@gnu.org>
parents:
38194
diff
changeset
|
143 (or (eq which-func-modes t) |
d215f2e13397
(which-func-mode, which-func-ff-hook)
Gerd Moellmann <gerd@gnu.org>
parents:
38194
diff
changeset
|
144 (member major-mode which-func-modes)))) |
20321 | 145 |
22308
87366acfb1e9
(which-func-ff-hook): If imenu gets error,
Karl Heuer <kwzh@gnu.org>
parents:
22134
diff
changeset
|
146 (condition-case nil |
87366acfb1e9
(which-func-ff-hook): If imenu gets error,
Karl Heuer <kwzh@gnu.org>
parents:
22134
diff
changeset
|
147 (if (and which-func-mode |
87366acfb1e9
(which-func-ff-hook): If imenu gets error,
Karl Heuer <kwzh@gnu.org>
parents:
22134
diff
changeset
|
148 (not (member major-mode which-func-non-auto-modes)) |
32190
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
149 (or (null which-func-maxout) |
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
150 (< buffer-saved-size which-func-maxout) |
22308
87366acfb1e9
(which-func-ff-hook): If imenu gets error,
Karl Heuer <kwzh@gnu.org>
parents:
22134
diff
changeset
|
151 (= which-func-maxout 0))) |
87366acfb1e9
(which-func-ff-hook): If imenu gets error,
Karl Heuer <kwzh@gnu.org>
parents:
22134
diff
changeset
|
152 (setq imenu--index-alist |
87366acfb1e9
(which-func-ff-hook): If imenu gets error,
Karl Heuer <kwzh@gnu.org>
parents:
22134
diff
changeset
|
153 (save-excursion (funcall imenu-create-index-function)))) |
87366acfb1e9
(which-func-ff-hook): If imenu gets error,
Karl Heuer <kwzh@gnu.org>
parents:
22134
diff
changeset
|
154 (error |
87366acfb1e9
(which-func-ff-hook): If imenu gets error,
Karl Heuer <kwzh@gnu.org>
parents:
22134
diff
changeset
|
155 (setq which-func-mode nil)))) |
20321 | 156 |
157 (defun which-func-update () | |
51052
322e59c8a00c
(which-func-format): Make it risky-local-variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50649
diff
changeset
|
158 ;; "Update the Which-Function mode display for all windows." |
322e59c8a00c
(which-func-format): Make it risky-local-variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50649
diff
changeset
|
159 ;; (walk-windows 'which-func-update-1 nil 'visible)) |
322e59c8a00c
(which-func-format): Make it risky-local-variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50649
diff
changeset
|
160 (which-func-update-1 (selected-window))) |
41357
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
161 |
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
162 (defun which-func-update-1 (window) |
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
163 "Update the Which-Function mode display for window WINDOW." |
51052
322e59c8a00c
(which-func-format): Make it risky-local-variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50649
diff
changeset
|
164 (with-selected-window window |
41357
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
165 (when which-func-mode |
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
166 (condition-case info |
51052
322e59c8a00c
(which-func-format): Make it risky-local-variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50649
diff
changeset
|
167 (let ((current (which-function))) |
322e59c8a00c
(which-func-format): Make it risky-local-variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50649
diff
changeset
|
168 (unless (equal current (gethash window which-func-table)) |
322e59c8a00c
(which-func-format): Make it risky-local-variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50649
diff
changeset
|
169 (puthash window current which-func-table) |
322e59c8a00c
(which-func-format): Make it risky-local-variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50649
diff
changeset
|
170 (force-mode-line-update))) |
41357
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
171 (error |
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
172 (which-func-mode -1) |
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
173 (error "Error in which-func-update: %s" info)))))) |
20321 | 174 |
38194
a23820c19d03
(which-func-maxout): Increase default to 500000.
Richard M. Stallman <rms@gnu.org>
parents:
36606
diff
changeset
|
175 ;;;###autoload |
a23820c19d03
(which-func-maxout): Increase default to 500000.
Richard M. Stallman <rms@gnu.org>
parents:
36606
diff
changeset
|
176 (defalias 'which-func-mode 'which-function-mode) |
a23820c19d03
(which-func-maxout): Increase default to 500000.
Richard M. Stallman <rms@gnu.org>
parents:
36606
diff
changeset
|
177 |
51221
62a2a306bc43
(which-func-update-timer): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
51069
diff
changeset
|
178 (defvar which-func-update-timer nil) |
62a2a306bc43
(which-func-update-timer): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
51069
diff
changeset
|
179 |
21960
79c7369b9ab4
(which-function-mode): New alias.
Richard M. Stallman <rms@gnu.org>
parents:
21697
diff
changeset
|
180 ;; This is the name people would normally expect. |
79c7369b9ab4
(which-function-mode): New alias.
Richard M. Stallman <rms@gnu.org>
parents:
21697
diff
changeset
|
181 ;;;###autoload |
38194
a23820c19d03
(which-func-maxout): Increase default to 500000.
Richard M. Stallman <rms@gnu.org>
parents:
36606
diff
changeset
|
182 (define-minor-mode which-function-mode |
20321 | 183 "Toggle Which Function mode, globally. |
184 When Which Function mode is enabled, the current function name is | |
185 continuously displayed in the mode line, in certain major modes. | |
186 | |
32190
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
187 With prefix ARG, turn Which Function mode on iff arg is positive, |
20321 | 188 and off otherwise." |
36606
a72b3da04728
(which-func-modes): Add cperl-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35990
diff
changeset
|
189 :global t :group 'which-func |
38405
d215f2e13397
(which-func-mode, which-func-ff-hook)
Gerd Moellmann <gerd@gnu.org>
parents:
38194
diff
changeset
|
190 (if which-function-mode |
35990
7ded5b71182f
(which-func-mode): Invert which-func-mode-global.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33702
diff
changeset
|
191 ;;Turn it on |
32190
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
192 (progn |
51221
62a2a306bc43
(which-func-update-timer): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
51069
diff
changeset
|
193 (setq which-func-update-timer |
62a2a306bc43
(which-func-update-timer): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
51069
diff
changeset
|
194 (run-with-idle-timer idle-update-delay t 'which-func-update)) |
35990
7ded5b71182f
(which-func-mode): Invert which-func-mode-global.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33702
diff
changeset
|
195 (dolist (buf (buffer-list)) |
7ded5b71182f
(which-func-mode): Invert which-func-mode-global.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33702
diff
changeset
|
196 (with-current-buffer buf |
7ded5b71182f
(which-func-mode): Invert which-func-mode-global.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33702
diff
changeset
|
197 (setq which-func-mode |
7ded5b71182f
(which-func-mode): Invert which-func-mode-global.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33702
diff
changeset
|
198 (or (eq which-func-modes t) |
7ded5b71182f
(which-func-mode): Invert which-func-mode-global.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33702
diff
changeset
|
199 (member major-mode which-func-modes)))))) |
7ded5b71182f
(which-func-mode): Invert which-func-mode-global.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33702
diff
changeset
|
200 ;; Turn it off |
51221
62a2a306bc43
(which-func-update-timer): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
51069
diff
changeset
|
201 (cancel-timer which-func-update-timer) |
62a2a306bc43
(which-func-update-timer): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
51069
diff
changeset
|
202 (setq which-func-update-timer nil) |
32190
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
203 (dolist (buf (buffer-list)) |
35990
7ded5b71182f
(which-func-mode): Invert which-func-mode-global.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33702
diff
changeset
|
204 (with-current-buffer buf (setq which-func-mode nil))))) |
20321 | 205 |
41357
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
206 (defvar which-function-imenu-failed nil |
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
207 "Locally t in a buffer if `imenu--make-index-alist' found nothing there.") |
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
208 |
20321 | 209 (defun which-function () |
21697 | 210 "Return current function name based on point. |
36606
a72b3da04728
(which-func-modes): Add cperl-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35990
diff
changeset
|
211 Uses `imenu--index-alist' or `add-log-current-defun-function'. |
a72b3da04728
(which-func-modes): Add cperl-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35990
diff
changeset
|
212 If no function name is found, return nil." |
32190
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
213 (let (name) |
41357
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
214 ;; If Imenu is loaded, try to make an index alist with it. |
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
215 (when (and (boundp 'imenu--index-alist) (null imenu--index-alist) |
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
216 (null which-function-imenu-failed)) |
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
217 (imenu--make-index-alist) |
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
218 (unless imenu--index-alist |
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
219 (make-local-variable 'which-function-imenu-failed) |
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
220 (setq which-function-imenu-failed t))) |
9e8cfa1e3b05
(which-function): Call imenu--make-index-alist
Richard M. Stallman <rms@gnu.org>
parents:
38437
diff
changeset
|
221 ;; If we have an index alist, use it. |
32190
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
222 (when (and (boundp 'imenu--index-alist) imenu--index-alist) |
50649
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
223 (let ((alist imenu--index-alist) |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
224 (minoffset (point-max)) |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
225 offset elem pair mark) |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
226 (while alist |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
227 (setq elem (car-safe alist) |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
228 alist (cdr-safe alist)) |
51221
62a2a306bc43
(which-func-update-timer): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
51069
diff
changeset
|
229 ;; Elements of alist are either ("name" . marker), or |
50649
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
230 ;; ("submenu" ("name" . marker) ... ). |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
231 (unless (listp (cdr elem)) |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
232 (setq elem (list elem))) |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
233 (while elem |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
234 (setq pair (car elem) |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
235 elem (cdr elem)) |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
236 (and (consp pair) |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
237 (number-or-marker-p (setq mark (cdr pair))) |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
238 (if (>= (setq offset (- (point) mark)) 0) |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
239 (if (< offset minoffset) ; find the closest item |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
240 (setq minoffset offset |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
241 name (car pair))) |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
242 ;; Entries in order, so can skip all those after point. |
c2fa5aacd170
(which-func-modes): Add f90-mode.
Glenn Morris <rgm@gnu.org>
parents:
49597
diff
changeset
|
243 (setq elem nil))))))) |
32190
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
244 ;; Try using add-log support. |
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
245 (when (and (null name) (boundp 'add-log-current-defun-function) |
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
246 add-log-current-defun-function) |
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
247 (setq name (funcall add-log-current-defun-function))) |
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
248 ;; Filter the name if requested. |
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
249 (when name |
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
250 (if which-func-cleanup-function |
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
251 (funcall which-func-cleanup-function name) |
af0c1b2c3d6e
(which-func-format): Remove spurious space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25425
diff
changeset
|
252 name)))) |
20321 | 253 |
254 (provide 'which-func) | |
255 | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
38423
diff
changeset
|
256 ;;; which-func.el ends here |