22641
|
1 ;;; find-func.el --- find the definition of the Emacs Lisp function near point
|
20183
|
2
|
64751
|
3 ;; Copyright (C) 1997, 1999, 2001, 2002, 2003, 2004,
|
68648
|
4 ;; 2005, 2006 Free Software Foundation, Inc.
|
20183
|
5
|
|
6 ;; Author: Jens Petersen <petersen@kurims.kyoto-u.ac.jp>
|
|
7 ;; Maintainer: petersen@kurims.kyoto-u.ac.jp
|
22641
|
8 ;; Keywords: emacs-lisp, functions, variables
|
20183
|
9 ;; Created: 97/07/25
|
|
10
|
|
11 ;; This file is part of GNU Emacs.
|
|
12
|
|
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
14 ;; it under the terms of the GNU General Public License as published by
|
|
15 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
16 ;; any later version.
|
|
17
|
|
18 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21 ;; GNU General Public License for more details.
|
|
22
|
|
23 ;; You should have received a copy of the GNU General Public License
|
|
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
64085
|
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
26 ;; Boston, MA 02110-1301, USA.
|
20183
|
27
|
|
28 ;;; Commentary:
|
|
29 ;;
|
|
30 ;; The funniest thing about this is that I can't imagine why a package
|
|
31 ;; so obviously useful as this hasn't been written before!!
|
|
32 ;; ;;; find-func
|
22759
|
33 ;; (find-function-setup-keys)
|
|
34 ;;
|
|
35 ;; or just:
|
|
36 ;;
|
22641
|
37 ;; (load "find-func")
|
20183
|
38 ;;
|
22759
|
39 ;; if you don't like the given keybindings and away you go! It does
|
22641
|
40 ;; pretty much what you would expect, putting the cursor at the
|
|
41 ;; definition of the function or variable at point.
|
20183
|
42 ;;
|
22641
|
43 ;; The code started out from `describe-function', `describe-key'
|
20183
|
44 ;; ("help.el") and `fff-find-loaded-emacs-lisp-function' (Noah Friedman's
|
|
45 ;; "fff.el").
|
|
46
|
38436
|
47 ;;; Code:
|
20183
|
48
|
22641
|
49 (require 'loadhist)
|
20183
|
50
|
|
51 ;;; User variables:
|
22641
|
52
|
20962
|
53 (defgroup find-function nil
|
22641
|
54 "Finds the definition of the Emacs Lisp symbol near point."
|
|
55 ;; :prefix "find-function"
|
20962
|
56 :group 'lisp)
|
20183
|
57
|
45326
892ea515fb3a
(find-function-search-for-symbol): Find funs defined with defun-cvs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
58 (defconst find-function-space-re "\\(?:\\s-\\|\n\\|;.*\n\\)+")
|
892ea515fb3a
(find-function-search-for-symbol): Find funs defined with defun-cvs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
59
|
22641
|
60 (defcustom find-function-regexp
|
24013
|
61 ;; Match things like (defun foo ...), (defmacro foo ...),
|
|
62 ;; (define-skeleton foo ...), (define-generic-mode 'foo ...),
|
26558
|
63 ;; (define-derived-mode foo ...), (define-minor-mode foo)
|
45326
892ea515fb3a
(find-function-search-for-symbol): Find funs defined with defun-cvs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
64 (concat
|
892ea515fb3a
(find-function-search-for-symbol): Find funs defined with defun-cvs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
65 "^\\s-*(\\(def\\(ine-skeleton\\|ine-generic-mode\\|ine-derived-mode\\|\
|
67294
|
66 ine\\(?:-global\\)?-minor-mode\\|ine-compilation-mode\\|un-cvs-mode\\|\
|
69921
055c0dc190ac
(find-function-regexp): Allow dashes in defun name, in similar fashion
Bill Wohler <wohler@newt.com>
diff
changeset
|
67 foo\\|[^cfgv]\\(\\w\\|\\s_\\)+\\*?\\)\\|easy-mmode-define-[a-z-]+\\|easy-menu-define\\|\
|
67294
|
68 menu-bar-make-toggle\\)"
|
60628
532be1846a28
(find-function-regexp): Add defun-emitting macro `menu-bar-make-toggle'.
Juri Linkov <juri@jurta.org>
diff
changeset
|
69 find-function-space-re
|
45326
892ea515fb3a
(find-function-search-for-symbol): Find funs defined with defun-cvs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
70 "\\('\\|\(quote \\)?%s\\(\\s-\\|$\\|\(\\|\)\\)")
|
24013
|
71 "The regexp used by `find-function' to search for a function definition.
|
|
72 Note it must contain a `%s' at the place where `format'
|
22641
|
73 should insert the function name. The default value avoids `defconst',
|
58261
212733e53508
(find-function-regexp): Optimize `define-minor-mode'. Add `defun-cvs-mode'.
Juri Linkov <juri@jurta.org>
diff
changeset
|
74 `defgroup', `defvar', `defface'.
|
20183
|
75
|
22641
|
76 Please send improvements and fixes to the maintainer."
|
|
77 :type 'regexp
|
22759
|
78 :group 'find-function
|
26558
|
79 :version "21.1")
|
22641
|
80
|
|
81 (defcustom find-variable-regexp
|
67294
|
82 (concat
|
|
83 "^\\s-*(\\(def[^fumag]\\(\\w\\|\\s_\\)+\\*?\\|\
|
|
84 easy-mmode-def\\(map\\|syntax\\)\\|easy-menu-define\\)"
|
|
85 find-function-space-re
|
|
86 "%s\\(\\s-\\|$\\)")
|
22641
|
87 "The regexp used by `find-variable' to search for a variable definition.
|
59367
|
88 Note it must contain a `%s' at the place where `format'
|
|
89 should insert the variable name. The default value
|
59330
|
90 avoids `defun', `defmacro', `defalias', `defadvice', `defgroup', `defface'.
|
22641
|
91
|
|
92 Please send improvements and fixes to the maintainer."
|
|
93 :type 'regexp
|
22759
|
94 :group 'find-function
|
32226
|
95 :version "21.1")
|
20183
|
96
|
59367
|
97 (defcustom find-face-regexp
|
|
98 (concat"^\\s-*(defface" find-function-space-re "%s\\(\\s-\\|$\\)")
|
|
99 "The regexp used by `find-face' to search for a face definition.
|
|
100 Note it must contain a `%s' at the place where `format'
|
|
101 should insert the face name.
|
|
102
|
|
103 Please send improvements and fixes to the maintainer."
|
|
104 :type 'regexp
|
|
105 :group 'find-function
|
59996
|
106 :version "22.1")
|
59367
|
107
|
|
108 (defvar find-function-regexp-alist
|
|
109 '((nil . find-function-regexp)
|
|
110 (defvar . find-variable-regexp)
|
|
111 (defface . find-face-regexp))
|
|
112 "Alist mapping definition types into regexp variables.
|
|
113 Each regexp variable's value should actually be a format string
|
|
114 to be used to substitute the desired symbol name into the regexp.")
|
|
115 (put 'find-function-regexp-alist 'risky-local-variable t)
|
|
116
|
20962
|
117 (defcustom find-function-source-path nil
|
24013
|
118 "The default list of directories where `find-function' searches.
|
20183
|
119
|
24013
|
120 If this variable is nil then `find-function' searches `load-path' by
|
20962
|
121 default."
|
|
122 :type '(repeat directory)
|
|
123 :group 'find-function)
|
20183
|
124
|
22641
|
125 (defcustom find-function-recenter-line 1
|
|
126 "The window line-number from which to start displaying a symbol definition.
|
|
127 A value of nil implies center the beginning of the definition.
|
47298
|
128 See `find-function' and `find-variable'."
|
|
129 :type '(choice (const :tag "Center" nil)
|
|
130 integer)
|
22759
|
131 :group 'find-function
|
23100
|
132 :version "20.3")
|
22641
|
133
|
|
134 (defcustom find-function-after-hook nil
|
|
135 "Hook run after finding symbol definition.
|
|
136
|
|
137 See the functions `find-function' and `find-variable'."
|
22759
|
138 :group 'find-function
|
23100
|
139 :version "20.3")
|
22641
|
140
|
|
141 ;;; Functions:
|
|
142
|
47345
|
143 (defun find-library-suffixes ()
|
|
144 (let ((suffixes nil))
|
69169
10a4ff23378e
(find-library-suffixes): Use `get-load-suffixes' instead of `load-suffixes'.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
145 (dolist (suffix (get-load-suffixes) (nreverse suffixes))
|
47345
|
146 (unless (string-match "elc" suffix) (push suffix suffixes)))))
|
|
147
|
|
148 (defun find-library-name (library)
|
66288
|
149 "Return the absolute file name of the Lisp source of LIBRARY."
|
66446
7e631d51e6e3
(find-library-name): Also strip extension if library name ends in .el,
Romain Francoise <romain@orebokech.com>
diff
changeset
|
150 ;; Strip off the extension to take advantage of library suffixes in
|
7e631d51e6e3
(find-library-name): Also strip extension if library name ends in .el,
Romain Francoise <romain@orebokech.com>
diff
changeset
|
151 ;; the call to `locate-file'.
|
7e631d51e6e3
(find-library-name): Also strip extension if library name ends in .el,
Romain Francoise <romain@orebokech.com>
diff
changeset
|
152 (if (string-match "\\.el\\(c\\(\\..*\\)?\\)?\\'" library)
|
47610
8a24f7edde82
(find-library-name): Correctly find "f.el.gz" from "f.elc" or "f.elc.gz".
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
153 (setq library (replace-match "" t t library)))
|
47345
|
154 (or (locate-file library
|
|
155 (or find-function-source-path load-path)
|
69169
10a4ff23378e
(find-library-suffixes): Use `get-load-suffixes' instead of `load-suffixes'.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
156 (append (find-library-suffixes) load-file-rep-suffixes))
|
47446
8bd5dd6cc381
(find-library-name): Don't forget the empty suffix. Fix stale variable name.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
157 (error "Can't find library %s" library)))
|
47345
|
158
|
55231
|
159 (defvar find-function-C-source-directory
|
|
160 (let ((dir (expand-file-name "src" source-directory)))
|
|
161 (when (and (file-directory-p dir) (file-readable-p dir))
|
|
162 dir))
|
|
163 "Directory where the C source files of Emacs can be found.
|
|
164 If nil, do not try to find the source code of functions and variables
|
|
165 defined in C.")
|
|
166
|
59367
|
167 (defun find-function-C-source (fun-or-var file type)
|
68320
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
168 "Find the source location where FUN-OR-VAR is defined in FILE.
|
59367
|
169 TYPE should be nil to find a function, or `defvar' to find a variable."
|
55231
|
170 (unless find-function-C-source-directory
|
|
171 (setq find-function-C-source-directory
|
|
172 (read-directory-name "Emacs C source dir: " nil nil t)))
|
|
173 (setq file (expand-file-name file find-function-C-source-directory))
|
|
174 (unless (file-readable-p file)
|
|
175 (error "The C source file %s is not available"
|
|
176 (file-name-nondirectory file)))
|
59367
|
177 (unless type
|
55231
|
178 (setq fun-or-var (indirect-function fun-or-var)))
|
|
179 (with-current-buffer (find-file-noselect file)
|
|
180 (goto-char (point-min))
|
|
181 (unless (re-search-forward
|
59367
|
182 (if type
|
55231
|
183 (concat "DEFVAR[A-Z_]*[ \t\n]*([ \t\n]*\""
|
|
184 (regexp-quote (symbol-name fun-or-var))
|
|
185 "\"")
|
|
186 (concat "DEFUN[ \t\n]*([ \t\n]*\""
|
|
187 (regexp-quote (subr-name fun-or-var))
|
|
188 "\""))
|
|
189 nil t)
|
|
190 (error "Can't find source for %s" fun-or-var))
|
|
191 (cons (current-buffer) (match-beginning 0))))
|
|
192
|
47345
|
193 ;;;###autoload
|
|
194 (defun find-library (library)
|
|
195 "Find the elisp source of LIBRARY."
|
|
196 (interactive
|
|
197 (list
|
|
198 (completing-read "Library name: "
|
|
199 'locate-file-completion
|
|
200 (cons (or find-function-source-path load-path)
|
|
201 (find-library-suffixes)))))
|
|
202 (let ((buf (find-file-noselect (find-library-name library))))
|
|
203 (condition-case nil (switch-to-buffer buf) (error (pop-to-buffer buf)))))
|
|
204
|
45190
|
205 ;;;###autoload
|
59367
|
206 (defun find-function-search-for-symbol (symbol type library)
|
|
207 "Search for SYMBOL's definition of type TYPE in LIBRARY.
|
|
208 If TYPE is nil, look for a function definition.
|
|
209 Otherwise, TYPE specifies the kind of definition,
|
|
210 and it is interpreted via `find-function-regexp-alist'.
|
|
211 The search is done in the source for library LIBRARY."
|
22641
|
212 (if (null library)
|
|
213 (error "Don't know where `%s' is defined" symbol))
|
46874
cbd462ecc9ad
(find-function-search-for-symbol): Obey `definition-name' properties.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
214 ;; Some functions are defined as part of the construct
|
cbd462ecc9ad
(find-function-search-for-symbol): Obey `definition-name' properties.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
215 ;; that defines something else.
|
55231
|
216 (while (and (symbolp symbol) (get symbol 'definition-name))
|
46874
cbd462ecc9ad
(find-function-search-for-symbol): Obey `definition-name' properties.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
217 (setq symbol (get symbol 'definition-name)))
|
55231
|
218 (if (string-match "\\`src/\\(.*\\.c\\)\\'" library)
|
59367
|
219 (find-function-C-source symbol (match-string 1 library) type)
|
23862
|
220 (if (string-match "\\.el\\(c\\)\\'" library)
|
|
221 (setq library (substring library 0 (match-beginning 1))))
|
59367
|
222 (let* ((filename (find-library-name library))
|
|
223 (regexp-symbol (cdr (assq type find-function-regexp-alist))))
|
23862
|
224 (with-current-buffer (find-file-noselect filename)
|
59367
|
225 (let ((regexp (format (symbol-value regexp-symbol)
|
22641
|
226 (regexp-quote (symbol-name symbol))))
|
45120
254bce531056
(find-function-search-for-symbol): Bind case-fold-search when searching.
Markus Rost <rost@math.uni-bielefeld.de>
diff
changeset
|
227 (case-fold-search))
|
45150
4a2bcce6b13a
(find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
diff
changeset
|
228 (with-syntax-table emacs-lisp-mode-syntax-table
|
4a2bcce6b13a
(find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
diff
changeset
|
229 (goto-char (point-min))
|
4a2bcce6b13a
(find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
diff
changeset
|
230 (if (or (re-search-forward regexp nil t)
|
70013
|
231 ;; `regexp' matches definitions using known forms like
|
|
232 ;; `defun', or `defvar'. But some functions/variables
|
|
233 ;; are defined using special macros (or functions), so
|
|
234 ;; if `regexp' can't find the definition, we look for
|
|
235 ;; something of the form "(SOMETHING <symbol> ...)".
|
|
236 ;; This fails to distinguish function definitions from
|
|
237 ;; variable declarations (or even uses thereof), but is
|
|
238 ;; a good pragmatic fallback.
|
45150
4a2bcce6b13a
(find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
diff
changeset
|
239 (re-search-forward
|
69916
62a4fbb2cb81
(find-function-search-for-symbol): Fix regexp so the defined var/fun doesn't
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
240 (concat "^([^ ]+" find-function-space-re "['(]?"
|
45150
4a2bcce6b13a
(find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
diff
changeset
|
241 (regexp-quote (symbol-name symbol))
|
58261
212733e53508
(find-function-regexp): Optimize `define-minor-mode'. Add `defun-cvs-mode'.
Juri Linkov <juri@jurta.org>
diff
changeset
|
242 "\\_>")
|
45150
4a2bcce6b13a
(find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
diff
changeset
|
243 nil t))
|
4a2bcce6b13a
(find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
diff
changeset
|
244 (progn
|
4a2bcce6b13a
(find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
diff
changeset
|
245 (beginning-of-line)
|
4a2bcce6b13a
(find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
diff
changeset
|
246 (cons (current-buffer) (point)))
|
4a2bcce6b13a
(find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
diff
changeset
|
247 (error "Cannot find definition of `%s' in library `%s'"
|
4a2bcce6b13a
(find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
diff
changeset
|
248 symbol library))))))))
|
22641
|
249
|
22851
|
250 ;;;###autoload
|
22641
|
251 (defun find-function-noselect (function)
|
24013
|
252 "Return a pair (BUFFER . POINT) pointing to the definition of FUNCTION.
|
20183
|
253
|
68320
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
254 Finds the source file containing the definition of FUNCTION
|
22641
|
255 in a buffer and the point of the definition. The buffer is
|
20183
|
256 not selected.
|
|
257
|
22641
|
258 If the file where FUNCTION is defined is not known, then it is
|
24013
|
259 searched for in `find-function-source-path' if non nil, otherwise
|
22641
|
260 in `load-path'."
|
|
261 (if (not function)
|
|
262 (error "You didn't specify a function"))
|
20183
|
263 (let ((def (symbol-function function))
|
22641
|
264 aliases)
|
20183
|
265 (while (symbolp def)
|
|
266 (or (eq def function)
|
|
267 (if aliases
|
|
268 (setq aliases (concat aliases
|
22641
|
269 (format ", which is an alias for `%s'"
|
20183
|
270 (symbol-name def))))
|
22641
|
271 (setq aliases (format "`%s' an alias for `%s'"
|
|
272 function (symbol-name def)))))
|
20183
|
273 (setq function (symbol-function function)
|
|
274 def (symbol-function function)))
|
|
275 (if aliases
|
65590
|
276 (message "%s" aliases))
|
22641
|
277 (let ((library
|
|
278 (cond ((eq (car-safe def) 'autoload)
|
|
279 (nth 1 def))
|
62908
|
280 ((subrp def)
|
|
281 (help-C-file-name def 'subr))
|
59122
|
282 ((symbol-file function 'defun)))))
|
22641
|
283 (find-function-search-for-symbol function nil library))))
|
20183
|
284
|
59367
|
285 (defun find-function-read (&optional type)
|
22641
|
286 "Read and return an interned symbol, defaulting to the one near point.
|
20183
|
287
|
59367
|
288 If TYPE is nil, insist on a symbol with a function definition.
|
|
289 Otherwise TYPE should be `defvar' or `defface'.
|
|
290 If TYPE is nil, defaults using `function-called-at-point',
|
|
291 otherwise uses `variable-at-point'."
|
|
292 (let ((symb (if (null type)
|
|
293 (function-called-at-point)
|
|
294 (if (eq type 'defvar)
|
|
295 (variable-at-point)
|
|
296 (variable-at-point t))))
|
|
297 (predicate (cdr (assq type '((nil . fboundp) (defvar . boundp)
|
|
298 (defface . facep)))))
|
|
299 (prompt (cdr (assq type '((nil . "function") (defvar . "variable")
|
|
300 (defface . "face")))))
|
20183
|
301 (enable-recursive-minibuffers t)
|
|
302 val)
|
22641
|
303 (if (equal symb 0)
|
|
304 (setq symb nil))
|
59367
|
305 (setq val (completing-read
|
|
306 (concat "Find "
|
|
307 prompt
|
|
308 (if symb
|
|
309 (format " (default %s)" symb))
|
|
310 ": ")
|
|
311 obarray predicate t nil))
|
20183
|
312 (list (if (equal val "")
|
22641
|
313 symb
|
|
314 (intern val)))))
|
20183
|
315
|
59367
|
316 (defun find-function-do-it (symbol type switch-fn)
|
24013
|
317 "Find Emacs Lisp SYMBOL in a buffer and display it.
|
59367
|
318 TYPE is nil to search for a function definition,
|
|
319 or else `defvar' or `defface'.
|
22641
|
320
|
59367
|
321 The variable `find-function-recenter-line' controls how
|
|
322 to recenter the display. SWITCH-FN is the function to call
|
|
323 to display and select the buffer.
|
|
324 See also `find-function-after-hook'.
|
|
325
|
|
326 Set mark before moving, if the buffer already existed."
|
22759
|
327 (let* ((orig-point (point))
|
|
328 (orig-buf (window-buffer))
|
22641
|
329 (orig-buffers (buffer-list))
|
22759
|
330 (buffer-point (save-excursion
|
59367
|
331 (find-definition-noselect symbol type)))
|
22759
|
332 (new-buf (car buffer-point))
|
|
333 (new-point (cdr buffer-point)))
|
22641
|
334 (when buffer-point
|
22759
|
335 (when (memq new-buf orig-buffers)
|
22641
|
336 (push-mark orig-point))
|
22759
|
337 (funcall switch-fn new-buf)
|
|
338 (goto-char new-point)
|
22641
|
339 (recenter find-function-recenter-line)
|
33198
|
340 (run-hooks 'find-function-after-hook))))
|
20183
|
341
|
20184
|
342 ;;;###autoload
|
22641
|
343 (defun find-function (function)
|
24021
|
344 "Find the definition of the FUNCTION near point.
|
20183
|
345
|
68320
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
346 Finds the source file containing the definition of the function
|
59377
b9540957b07c
(find-variable, find-variable-other-window, find-variable-other-frame):
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
347 near point (selected by `function-called-at-point') in a buffer and
|
59367
|
348 places point before the definition.
|
|
349 Set mark before moving, if the buffer already existed.
|
20183
|
350
|
22641
|
351 The library where FUNCTION is defined is searched for in
|
24013
|
352 `find-function-source-path', if non nil, otherwise in `load-path'.
|
22641
|
353 See also `find-function-recenter-line' and `find-function-after-hook'."
|
|
354 (interactive (find-function-read))
|
|
355 (find-function-do-it function nil 'switch-to-buffer))
|
20183
|
356
|
20184
|
357 ;;;###autoload
|
22641
|
358 (defun find-function-other-window (function)
|
24021
|
359 "Find, in another window, the definition of FUNCTION near point.
|
20183
|
360
|
22641
|
361 See `find-function' for more details."
|
|
362 (interactive (find-function-read))
|
|
363 (find-function-do-it function nil 'switch-to-buffer-other-window))
|
|
364
|
|
365 ;;;###autoload
|
|
366 (defun find-function-other-frame (function)
|
68320
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
367 "Find, in another frame, the definition of FUNCTION near point.
|
22641
|
368
|
|
369 See `find-function' for more details."
|
|
370 (interactive (find-function-read))
|
|
371 (find-function-do-it function nil 'switch-to-buffer-other-frame))
|
20183
|
372
|
23659
|
373 ;;;###autoload
|
40480
|
374 (defun find-variable-noselect (variable &optional file)
|
68320
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
375 "Return a pair `(BUFFER . POINT)' pointing to the definition of VARIABLE.
|
22641
|
376
|
68320
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
377 Finds the library containing the definition of VARIABLE in a buffer and
|
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
378 the point of the definition. The buffer is not selected.
|
22641
|
379
|
40480
|
380 The library where VARIABLE is defined is searched for in FILE or
|
24013
|
381 `find-function-source-path', if non nil, otherwise in `load-path'."
|
22641
|
382 (if (not variable)
|
68320
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
383 (error "You didn't specify a variable")
|
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
384 (let ((library (or file
|
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
385 (symbol-file variable 'defvar)
|
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
386 (help-C-file-name variable 'var))))
|
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
387 (find-function-search-for-symbol variable 'defvar library))))
|
20183
|
388
|
20184
|
389 ;;;###autoload
|
22641
|
390 (defun find-variable (variable)
|
24021
|
391 "Find the definition of the VARIABLE near point.
|
22641
|
392
|
68320
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
393 Finds the library containing the definition of the variable
|
22641
|
394 near point (selected by `variable-at-point') in a buffer and
|
59367
|
395 places point before the definition.
|
|
396
|
|
397 Set mark before moving, if the buffer already existed.
|
22641
|
398
|
|
399 The library where VARIABLE is defined is searched for in
|
24013
|
400 `find-function-source-path', if non nil, otherwise in `load-path'.
|
22641
|
401 See also `find-function-recenter-line' and `find-function-after-hook'."
|
59377
b9540957b07c
(find-variable, find-variable-other-window, find-variable-other-frame):
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
402 (interactive (find-function-read 'defvar))
|
b9540957b07c
(find-variable, find-variable-other-window, find-variable-other-frame):
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
403 (find-function-do-it variable 'defvar 'switch-to-buffer))
|
20183
|
404
|
22641
|
405 ;;;###autoload
|
|
406 (defun find-variable-other-window (variable)
|
24021
|
407 "Find, in another window, the definition of VARIABLE near point.
|
22641
|
408
|
|
409 See `find-variable' for more details."
|
59377
b9540957b07c
(find-variable, find-variable-other-window, find-variable-other-frame):
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
410 (interactive (find-function-read 'defvar))
|
b9540957b07c
(find-variable, find-variable-other-window, find-variable-other-frame):
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
411 (find-function-do-it variable 'defvar 'switch-to-buffer-other-window))
|
20183
|
412
|
22641
|
413 ;;;###autoload
|
|
414 (defun find-variable-other-frame (variable)
|
68320
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
415 "Find, in another frame, the definition of VARIABLE near point.
|
22641
|
416
|
|
417 See `find-variable' for more details."
|
59377
b9540957b07c
(find-variable, find-variable-other-window, find-variable-other-frame):
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
418 (interactive (find-function-read 'defvar))
|
b9540957b07c
(find-variable, find-variable-other-window, find-variable-other-frame):
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
419 (find-function-do-it variable 'defvar 'switch-to-buffer-other-frame))
|
20183
|
420
|
20184
|
421 ;;;###autoload
|
59367
|
422 (defun find-definition-noselect (symbol type &optional file)
|
|
423 "Return a pair `(BUFFER . POINT)' pointing to the definition of SYMBOL.
|
68320
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
424 TYPE says what type of definition: nil for a function, `defvar' for a
|
68623
|
425 variable, `defface' for a face. This function does not switch to the
|
68320
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
426 buffer nor display it.
|
59367
|
427
|
|
428 The library where SYMBOL is defined is searched for in FILE or
|
|
429 `find-function-source-path', if non nil, otherwise in `load-path'."
|
68320
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
430 (cond
|
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
431 ((not symbol)
|
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
432 (error "You didn't specify a symbol"))
|
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
433 ((null type)
|
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
434 (find-function-noselect symbol))
|
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
435 ((eq type 'defvar)
|
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
436 (find-variable-noselect symbol file))
|
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
437 (t
|
59367
|
438 (let ((library (or file (symbol-file symbol type))))
|
68320
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
439 (find-function-search-for-symbol symbol type library)))))
|
59367
|
440
|
59404
|
441 ;; For symmetry, this should be called find-face; but some programs
|
|
442 ;; assume that, if that name is defined, it means something else.
|
59367
|
443 ;;;###autoload
|
59404
|
444 (defun find-face-definition (face)
|
59367
|
445 "Find the definition of FACE. FACE defaults to the name near point.
|
|
446
|
|
447 Finds the Emacs Lisp library containing the definition of the face
|
|
448 near point (selected by `variable-at-point') in a buffer and
|
|
449 places point before the definition.
|
|
450
|
|
451 Set mark before moving, if the buffer already existed.
|
|
452
|
|
453 The library where FACE is defined is searched for in
|
|
454 `find-function-source-path', if non nil, otherwise in `load-path'.
|
|
455 See also `find-function-recenter-line' and `find-function-after-hook'."
|
|
456 (interactive (find-function-read 'defface))
|
|
457 (find-function-do-it face 'defface 'switch-to-buffer))
|
|
458
|
|
459 ;;;###autoload
|
20183
|
460 (defun find-function-on-key (key)
|
|
461 "Find the function that KEY invokes. KEY is a string.
|
59367
|
462 Set mark before moving, if the buffer already existed."
|
20183
|
463 (interactive "kFind function on key: ")
|
51097
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
464 (let (defn)
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
465 (save-excursion
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
466 (let* ((event (and (eventp key) (aref key 0))) ; Null event OK below.
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
467 (start (event-start event))
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
468 (modifiers (event-modifiers event))
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
469 (window (and (or (memq 'click modifiers) (memq 'down modifiers)
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
470 (memq 'drag modifiers))
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
471 (posn-window start))))
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
472 ;; For a mouse button event, go to the button it applies to
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
473 ;; to get the right key bindings. And go to the right place
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
474 ;; in case the keymap depends on where you clicked.
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
475 (when (windowp window)
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
476 (set-buffer (window-buffer window))
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
477 (goto-char (posn-point start)))
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
478 (setq defn (key-binding key))))
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
479 (let ((key-desc (key-description key)))
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
480 (if (or (null defn) (integerp defn))
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
481 (message "%s is unbound" key-desc)
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
482 (if (consp defn)
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
483 (message "%s runs %s" key-desc (prin1-to-string defn))
|
37a69a2f1992
(find-function-on-key): Move the call to find-function-other-window
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
484 (find-function-other-window defn))))))
|
22641
|
485
|
|
486 ;;;###autoload
|
|
487 (defun find-function-at-point ()
|
|
488 "Find directly the function at point in the other window."
|
|
489 (interactive)
|
59377
b9540957b07c
(find-variable, find-variable-other-window, find-variable-other-frame):
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
490 (let ((symb (function-called-at-point)))
|
22641
|
491 (when symb
|
|
492 (find-function-other-window symb))))
|
|
493
|
|
494 ;;;###autoload
|
|
495 (defun find-variable-at-point ()
|
68320
a2ccca4b13a3
(find-definition-noselect, find-variable-noselect): Search variables in
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
496 "Find directly the variable at point in the other window."
|
22641
|
497 (interactive)
|
|
498 (let ((symb (variable-at-point)))
|
|
499 (when (and symb (not (equal symb 0)))
|
|
500 (find-variable-other-window symb))))
|
20183
|
501
|
22759
|
502 ;;;###autoload
|
|
503 (defun find-function-setup-keys ()
|
|
504 "Define some key bindings for the find-function family of functions."
|
|
505 (define-key ctl-x-map "F" 'find-function)
|
|
506 (define-key ctl-x-4-map "F" 'find-function-other-window)
|
|
507 (define-key ctl-x-5-map "F" 'find-function-other-frame)
|
|
508 (define-key ctl-x-map "K" 'find-function-on-key)
|
|
509 (define-key ctl-x-map "V" 'find-variable)
|
|
510 (define-key ctl-x-4-map "V" 'find-variable-other-window)
|
|
511 (define-key ctl-x-5-map "V" 'find-variable-other-frame))
|
|
512
|
20183
|
513 (provide 'find-func)
|
|
514
|
59330
|
515 ;; arch-tag: 43ecd81c-74dc-4d9a-8f63-a61e55670d64
|
20183
|
516 ;;; find-func.el ends here
|