]> code.delx.au - gnu-emacs/blob - lisp/emacs-lisp/find-func.el
b04a9d2dea53f57f1e30cacfb28a78255795a043
[gnu-emacs] / lisp / emacs-lisp / find-func.el
1 ;;; find-func.el --- find the definition of the Emacs Lisp function near point -*- lexical-binding:t -*-
2
3 ;; Copyright (C) 1997, 1999, 2001-2016 Free Software Foundation, Inc.
4
5 ;; Author: Jens Petersen <petersen@kurims.kyoto-u.ac.jp>
6 ;; Maintainer: petersen@kurims.kyoto-u.ac.jp
7 ;; Keywords: emacs-lisp, functions, variables
8 ;; Created: 97/07/25
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
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
24
25 ;;; Commentary:
26 ;;
27 ;; The funniest thing about this is that I can't imagine why a package
28 ;; so obviously useful as this hasn't been written before!!
29 ;; ;;; find-func
30 ;; (find-function-setup-keys)
31 ;;
32 ;; or just:
33 ;;
34 ;; (load "find-func")
35 ;;
36 ;; if you don't like the given keybindings and away you go! It does
37 ;; pretty much what you would expect, putting the cursor at the
38 ;; definition of the function or variable at point.
39 ;;
40 ;; The code started out from `describe-function', `describe-key'
41 ;; ("help.el") and `fff-find-loaded-emacs-lisp-function' (Noah Friedman's
42 ;; "fff.el").
43
44 ;;; Code:
45
46 ;;; User variables:
47
48 (defgroup find-function nil
49 "Finds the definition of the Emacs Lisp symbol near point."
50 ;; :prefix "find-function"
51 :group 'lisp)
52
53 (defconst find-function-space-re "\\(?:\\s-\\|\n\\|;.*\n\\)+")
54
55 (defcustom find-function-regexp
56 ;; Match things like (defun foo ...), (defmacro foo ...),
57 ;; (define-skeleton foo ...), (define-generic-mode 'foo ...),
58 ;; (define-derived-mode foo ...), (define-minor-mode foo)
59 (concat
60 "^\\s-*(\\(def\\(ine-skeleton\\|ine-generic-mode\\|ine-derived-mode\\|\
61 ine\\(?:-global\\)?-minor-mode\\|ine-compilation-mode\\|un-cvs-mode\\|\
62 foo\\|\\(?:[^icfgv]\\|g[^r]\\)\\(\\w\\|\\s_\\)+\\*?\\)\\|easy-mmode-define-[a-z-]+\\|easy-menu-define\\|\
63 menu-bar-make-toggle\\)"
64 find-function-space-re
65 "\\('\\|(quote \\)?%s\\(\\s-\\|$\\|[()]\\)")
66 "The regexp used by `find-function' to search for a function definition.
67 Note it must contain a `%s' at the place where `format'
68 should insert the function name. The default value avoids `defconst',
69 `defgroup', `defvar', `defface'.
70
71 Please send improvements and fixes to the maintainer."
72 :type 'regexp
73 :group 'find-function
74 :version "21.1")
75
76 (defcustom find-variable-regexp
77 (concat
78 "^\\s-*(\\(def[^fumag]\\(\\w\\|\\s_\\)+\\*?\\|\
79 easy-mmode-def\\(map\\|syntax\\)\\|easy-menu-define\\)"
80 find-function-space-re
81 "%s\\(\\s-\\|$\\)")
82 "The regexp used by `find-variable' to search for a variable definition.
83 Note it must contain a `%s' at the place where `format'
84 should insert the variable name. The default value
85 avoids `defun', `defmacro', `defalias', `defadvice', `defgroup', `defface'.
86
87 Please send improvements and fixes to the maintainer."
88 :type 'regexp
89 :group 'find-function
90 :version "21.1")
91
92 (defcustom find-face-regexp
93 (concat"^\\s-*(defface" find-function-space-re "%s\\(\\s-\\|$\\)")
94 "The regexp used by `find-face' to search for a face definition.
95 Note it must contain a `%s' at the place where `format'
96 should insert the face name.
97
98 Please send improvements and fixes to the maintainer."
99 :type 'regexp
100 :group 'find-function
101 :version "22.1")
102
103 (defcustom find-feature-regexp
104 (concat ";;; Code:")
105 "The regexp used by `xref-find-definitions' when searching for a feature definition.
106 Note it must contain a `%s' at the place where `format'
107 should insert the feature name."
108 ;; We search for ";;; Code" rather than (feature '%s) because the
109 ;; former is near the start of the code, and the latter is very
110 ;; uninteresting. If the regexp is not found, just goes to
111 ;; (point-min), which is acceptable in this case.
112 :type 'regexp
113 :group 'xref
114 :version "25.0")
115
116 (defcustom find-alias-regexp
117 "(defalias +'%s"
118 "The regexp used by `xref-find-definitions' to search for an alias definition.
119 Note it must contain a `%s' at the place where `format'
120 should insert the feature name."
121 :type 'regexp
122 :group 'xref
123 :version "25.0")
124
125 (defvar find-function-regexp-alist
126 '((nil . find-function-regexp)
127 (defvar . find-variable-regexp)
128 (defface . find-face-regexp)
129 (feature . find-feature-regexp)
130 (defalias . find-alias-regexp))
131 "Alist mapping definition types into regexp variables.
132 Each regexp variable's value should actually be a format string
133 to be used to substitute the desired symbol name into the regexp.
134 Instead of regexp variable, types can be mapped to functions as well,
135 in which case the function is called with one argument (the object
136 we're looking for) and it should search for it.")
137 (put 'find-function-regexp-alist 'risky-local-variable t)
138
139 (defcustom find-function-source-path nil
140 "The default list of directories where `find-function' searches.
141
142 If this variable is nil then `find-function' searches `load-path' by
143 default."
144 :type '(repeat directory)
145 :group 'find-function)
146
147 (defcustom find-function-recenter-line 1
148 "The window line-number from which to start displaying a symbol definition.
149 A value of nil implies center the beginning of the definition.
150 See `find-function' and `find-variable'."
151 :type '(choice (const :tag "Center" nil)
152 integer)
153 :group 'find-function
154 :version "20.3")
155
156 (defcustom find-function-after-hook nil
157 "Hook run after finding symbol definition.
158
159 See the functions `find-function' and `find-variable'."
160 :type 'hook
161 :group 'find-function
162 :version "20.3")
163
164 ;;; Functions:
165
166 (defun find-library-suffixes ()
167 (let ((suffixes nil))
168 (dolist (suffix (get-load-suffixes) (nreverse suffixes))
169 (unless (string-match "elc" suffix) (push suffix suffixes)))))
170
171 (defun find-library--load-name (library)
172 (let ((name library))
173 (dolist (dir load-path)
174 (let ((rel (file-relative-name library dir)))
175 (if (and (not (string-match "\\`\\.\\./" rel))
176 (< (length rel) (length name)))
177 (setq name rel))))
178 (unless (equal name library) name)))
179
180 (defun find-library-name (library)
181 "Return the absolute file name of the Emacs Lisp source of LIBRARY.
182 LIBRARY should be a string (the name of the library)."
183 ;; If the library is byte-compiled, try to find a source library by
184 ;; the same name.
185 (if (string-match "\\.el\\(c\\(\\..*\\)?\\)\\'" library)
186 (setq library (replace-match "" t t library)))
187 (or
188 (locate-file library
189 (or find-function-source-path load-path)
190 (find-library-suffixes))
191 (locate-file library
192 (or find-function-source-path load-path)
193 load-file-rep-suffixes)
194 (when (file-name-absolute-p library)
195 (let ((rel (find-library--load-name library)))
196 (when rel
197 (or
198 (locate-file rel
199 (or find-function-source-path load-path)
200 (find-library-suffixes))
201 (locate-file rel
202 (or find-function-source-path load-path)
203 load-file-rep-suffixes)))))
204 (error "Can't find library %s" library)))
205
206 (defvar find-function-C-source-directory
207 (let ((dir (expand-file-name "src" source-directory)))
208 (if (file-accessible-directory-p dir) dir))
209 "Directory where the C source files of Emacs can be found.
210 If nil, do not try to find the source code of functions and variables
211 defined in C.")
212
213 (declare-function ad-get-advice-info "advice" (function))
214
215 (defun find-function-advised-original (func)
216 "Return the original function definition of an advised function FUNC.
217 If FUNC is not a symbol, return it. Else, if it's not advised,
218 return the symbol's function definition."
219 (or (and (symbolp func)
220 (featurep 'nadvice)
221 (let ((ofunc (advice--symbol-function func)))
222 (if (advice--p ofunc)
223 (advice--cd*r ofunc)
224 ofunc)))
225 func))
226
227 (defun find-function-C-source (fun-or-var file type)
228 "Find the source location where FUN-OR-VAR is defined in FILE.
229 TYPE should be nil to find a function, or `defvar' to find a variable."
230 (let ((dir (or find-function-C-source-directory
231 (read-directory-name "Emacs C source dir: " nil nil t))))
232 (setq file (expand-file-name file dir))
233 (if (file-readable-p file)
234 (if (null find-function-C-source-directory)
235 (setq find-function-C-source-directory dir))
236 (error "The C source file %s is not available"
237 (file-name-nondirectory file))))
238 (unless type
239 ;; Either or both an alias and its target might be advised.
240 (setq fun-or-var (find-function-advised-original
241 (indirect-function
242 (find-function-advised-original fun-or-var)))))
243 (with-current-buffer (find-file-noselect file)
244 (goto-char (point-min))
245 (unless (re-search-forward
246 (if type
247 (concat "DEFVAR[A-Z_]*[ \t\n]*([ \t\n]*\""
248 (regexp-quote (symbol-name fun-or-var))
249 "\"")
250 (concat "DEFUN[ \t\n]*([ \t\n]*\""
251 (regexp-quote (subr-name (advice--cd*r fun-or-var)))
252 "\""))
253 nil t)
254 (error "Can't find source for %s" fun-or-var))
255 (cons (current-buffer) (match-beginning 0))))
256
257 ;;;###autoload
258 (defun find-library (library)
259 "Find the Emacs Lisp source of LIBRARY.
260 LIBRARY should be a string (the name of the library)."
261 (interactive
262 (let* ((dirs (or find-function-source-path load-path))
263 (suffixes (find-library-suffixes))
264 (table (apply-partially 'locate-file-completion-table
265 dirs suffixes))
266 (def (if (eq (function-called-at-point) 'require)
267 ;; `function-called-at-point' may return 'require
268 ;; with `point' anywhere on this line. So wrap the
269 ;; `save-excursion' below in a `condition-case' to
270 ;; avoid reporting a scan-error here.
271 (condition-case nil
272 (save-excursion
273 (backward-up-list)
274 (forward-char)
275 (forward-sexp 2)
276 (thing-at-point 'symbol))
277 (error nil))
278 (thing-at-point 'symbol))))
279 (when (and def (not (test-completion def table)))
280 (setq def nil))
281 (list
282 (completing-read (if def (format "Library name (default %s): " def)
283 "Library name: ")
284 table nil nil nil nil def))))
285 (let ((buf (find-file-noselect (find-library-name library))))
286 (condition-case nil
287 (prog1
288 (switch-to-buffer buf)
289 (run-hooks 'find-function-after-hook))
290 (error (pop-to-buffer buf)))))
291
292 ;;;###autoload
293 (defun find-function-search-for-symbol (symbol type library)
294 "Search for SYMBOL's definition of type TYPE in LIBRARY.
295 Visit the library in a buffer, and return a cons cell (BUFFER . POSITION),
296 or just (BUFFER . nil) if the definition can't be found in the file.
297
298 If TYPE is nil, look for a function definition.
299 Otherwise, TYPE specifies the kind of definition,
300 and it is interpreted via `find-function-regexp-alist'.
301 The search is done in the source for library LIBRARY."
302 (if (null library)
303 (error "Don't know where `%s' is defined" symbol))
304 ;; Some functions are defined as part of the construct
305 ;; that defines something else.
306 (while (and (symbolp symbol) (get symbol 'definition-name))
307 (setq symbol (get symbol 'definition-name)))
308 (if (string-match "\\`src/\\(.*\\.\\(c\\|m\\)\\)\\'" library)
309 (find-function-C-source symbol (match-string 1 library) type)
310 (when (string-match "\\.el\\(c\\)\\'" library)
311 (setq library (substring library 0 (match-beginning 1))))
312 ;; Strip extension from .emacs.el to make sure symbol is searched in
313 ;; .emacs too.
314 (when (string-match "\\.emacs\\(.el\\)" library)
315 (setq library (substring library 0 (match-beginning 1))))
316 (let* ((filename (find-library-name library))
317 (regexp-symbol (cdr (assq type find-function-regexp-alist))))
318 (with-current-buffer (find-file-noselect filename)
319 (let ((regexp (if (functionp regexp-symbol) regexp-symbol
320 (format (symbol-value regexp-symbol)
321 ;; Entry for ` (backquote) macro in loaddefs.el,
322 ;; (defalias (quote \`)..., has a \ but
323 ;; (symbol-name symbol) doesn't. Add an
324 ;; optional \ to catch this.
325 (concat "\\\\?"
326 (regexp-quote (symbol-name symbol))))))
327 (case-fold-search))
328 (with-syntax-table emacs-lisp-mode-syntax-table
329 (goto-char (point-min))
330 (if (if (functionp regexp)
331 (funcall regexp symbol)
332 (or (re-search-forward regexp nil t)
333 ;; `regexp' matches definitions using known forms like
334 ;; `defun', or `defvar'. But some functions/variables
335 ;; are defined using special macros (or functions), so
336 ;; if `regexp' can't find the definition, we look for
337 ;; something of the form "(SOMETHING <symbol> ...)".
338 ;; This fails to distinguish function definitions from
339 ;; variable declarations (or even uses thereof), but is
340 ;; a good pragmatic fallback.
341 (re-search-forward
342 (concat "^([^ ]+" find-function-space-re "['(]?"
343 (regexp-quote (symbol-name symbol))
344 "\\_>")
345 nil t)))
346 (progn
347 (beginning-of-line)
348 (cons (current-buffer) (point)))
349 (cons (current-buffer) nil))))))))
350
351 (defun find-function-library (function &optional lisp-only verbose)
352 "Return the pair (ORIG-FUNCTION . LIBRARY) for FUNCTION.
353
354 ORIG-FUNCTION is the original name, after removing all advice and
355 resolving aliases. LIBRARY is an absolute file name, a relative
356 file name inside the C sources directory, or a name of an
357 autoloaded feature.
358
359 If ORIG-FUNCTION is a built-in function and LISP-ONLY is non-nil,
360 signal an error.
361
362 If VERBOSE is non-nil, and FUNCTION is an alias, display a
363 message about the whole chain of aliases."
364 (let ((def (if (symbolp function)
365 (find-function-advised-original function)))
366 aliases)
367 ;; FIXME for completeness, it might be nice to print something like:
368 ;; foo (which is advised), which is an alias for bar (which is advised).
369 (while (and def (symbolp def))
370 (or (eq def function)
371 (not verbose)
372 (setq aliases (if aliases
373 (concat aliases
374 (format-message
375 ", which is an alias for `%s'"
376 (symbol-name def)))
377 (format-message "`%s' is an alias for `%s'"
378 function (symbol-name def)))))
379 (setq function (find-function-advised-original function)
380 def (find-function-advised-original function)))
381 (if aliases
382 (message "%s" aliases))
383 (cons function
384 (cond
385 ((autoloadp def) (nth 1 def))
386 ((subrp def)
387 (if lisp-only
388 (error "%s is a built-in function" function))
389 (help-C-file-name def 'subr))
390 ((symbol-file function 'defun))))))
391
392 ;;;###autoload
393 (defun find-function-noselect (function &optional lisp-only)
394 "Return a pair (BUFFER . POINT) pointing to the definition of FUNCTION.
395
396 Finds the source file containing the definition of FUNCTION
397 in a buffer and the point of the definition. The buffer is
398 not selected. If the function definition can't be found in
399 the buffer, returns (BUFFER).
400
401 If FUNCTION is a built-in function, this function normally
402 attempts to find it in the Emacs C sources; however, if LISP-ONLY
403 is non-nil, signal an error instead.
404
405 If the file where FUNCTION is defined is not known, then it is
406 searched for in `find-function-source-path' if non-nil, otherwise
407 in `load-path'."
408 (if (not function)
409 (error "You didn't specify a function"))
410 (let ((func-lib (find-function-library function lisp-only t)))
411 (find-function-search-for-symbol (car func-lib) nil (cdr func-lib))))
412
413 (defun find-function-read (&optional type)
414 "Read and return an interned symbol, defaulting to the one near point.
415
416 If TYPE is nil, insist on a symbol with a function definition.
417 Otherwise TYPE should be `defvar' or `defface'.
418 If TYPE is nil, defaults using `function-called-at-point',
419 otherwise uses `variable-at-point'."
420 (let* ((symb1 (cond ((null type) (function-called-at-point))
421 ((eq type 'defvar) (variable-at-point))
422 (t (variable-at-point t))))
423 (symb (unless (eq symb1 0) symb1))
424 (predicate (cdr (assq type '((nil . fboundp)
425 (defvar . boundp)
426 (defface . facep)))))
427 (prompt-type (cdr (assq type '((nil . "function")
428 (defvar . "variable")
429 (defface . "face")))))
430 (prompt (concat "Find " prompt-type
431 (and symb (format " (default %s)" symb))
432 ": "))
433 (enable-recursive-minibuffers t))
434 (list (intern (completing-read
435 prompt obarray predicate
436 t nil nil (and symb (symbol-name symb)))))))
437
438 (defun find-function-do-it (symbol type switch-fn)
439 "Find Emacs Lisp SYMBOL in a buffer and display it.
440 TYPE is nil to search for a function definition,
441 or else `defvar' or `defface'.
442
443 The variable `find-function-recenter-line' controls how
444 to recenter the display. SWITCH-FN is the function to call
445 to display and select the buffer.
446 See also `find-function-after-hook'.
447
448 Set mark before moving, if the buffer already existed."
449 (let* ((orig-point (point))
450 (orig-buffers (buffer-list))
451 (buffer-point (save-excursion
452 (find-definition-noselect symbol type)))
453 (new-buf (car buffer-point))
454 (new-point (cdr buffer-point)))
455 (when buffer-point
456 (when (memq new-buf orig-buffers)
457 (push-mark orig-point))
458 (funcall switch-fn new-buf)
459 (when new-point (goto-char new-point))
460 (recenter find-function-recenter-line)
461 (run-hooks 'find-function-after-hook))))
462
463 ;;;###autoload
464 (defun find-function (function)
465 "Find the definition of the FUNCTION near point.
466
467 Finds the source file containing the definition of the function
468 near point (selected by `function-called-at-point') in a buffer and
469 places point before the definition.
470 Set mark before moving, if the buffer already existed.
471
472 The library where FUNCTION is defined is searched for in
473 `find-function-source-path', if non-nil, otherwise in `load-path'.
474 See also `find-function-recenter-line' and `find-function-after-hook'."
475 (interactive (find-function-read))
476 (find-function-do-it function nil 'switch-to-buffer))
477
478 ;;;###autoload
479 (defun find-function-other-window (function)
480 "Find, in another window, the definition of FUNCTION near point.
481
482 See `find-function' for more details."
483 (interactive (find-function-read))
484 (find-function-do-it function nil 'switch-to-buffer-other-window))
485
486 ;;;###autoload
487 (defun find-function-other-frame (function)
488 "Find, in another frame, the definition of FUNCTION near point.
489
490 See `find-function' for more details."
491 (interactive (find-function-read))
492 (find-function-do-it function nil 'switch-to-buffer-other-frame))
493
494 ;;;###autoload
495 (defun find-variable-noselect (variable &optional file)
496 "Return a pair `(BUFFER . POINT)' pointing to the definition of VARIABLE.
497
498 Finds the library containing the definition of VARIABLE in a buffer and
499 the point of the definition. The buffer is not selected.
500 If the variable's definition can't be found in the buffer, return (BUFFER).
501
502 The library where VARIABLE is defined is searched for in FILE or
503 `find-function-source-path', if non-nil, otherwise in `load-path'."
504 (if (not variable)
505 (error "You didn't specify a variable")
506 (let ((library (or file
507 (symbol-file variable 'defvar)
508 (help-C-file-name variable 'var))))
509 (find-function-search-for-symbol variable 'defvar library))))
510
511 ;;;###autoload
512 (defun find-variable (variable)
513 "Find the definition of the VARIABLE at or before point.
514
515 Finds the library containing the definition of the variable
516 near point (selected by `variable-at-point') in a buffer and
517 places point before the definition.
518
519 Set mark before moving, if the buffer already existed.
520
521 The library where VARIABLE is defined is searched for in
522 `find-function-source-path', if non-nil, otherwise in `load-path'.
523 See also `find-function-recenter-line' and `find-function-after-hook'."
524 (interactive (find-function-read 'defvar))
525 (find-function-do-it variable 'defvar 'switch-to-buffer))
526
527 ;;;###autoload
528 (defun find-variable-other-window (variable)
529 "Find, in another window, the definition of VARIABLE near point.
530
531 See `find-variable' for more details."
532 (interactive (find-function-read 'defvar))
533 (find-function-do-it variable 'defvar 'switch-to-buffer-other-window))
534
535 ;;;###autoload
536 (defun find-variable-other-frame (variable)
537 "Find, in another frame, the definition of VARIABLE near point.
538
539 See `find-variable' for more details."
540 (interactive (find-function-read 'defvar))
541 (find-function-do-it variable 'defvar 'switch-to-buffer-other-frame))
542
543 ;;;###autoload
544 (defun find-definition-noselect (symbol type &optional file)
545 "Return a pair `(BUFFER . POINT)' pointing to the definition of SYMBOL.
546 If the definition can't be found in the buffer, return (BUFFER).
547 TYPE says what type of definition: nil for a function, `defvar' for a
548 variable, `defface' for a face. This function does not switch to the
549 buffer nor display it.
550
551 The library where SYMBOL is defined is searched for in FILE or
552 `find-function-source-path', if non-nil, otherwise in `load-path'."
553 (cond
554 ((not symbol)
555 (error "You didn't specify a symbol"))
556 ((null type)
557 (find-function-noselect symbol))
558 ((eq type 'defvar)
559 (find-variable-noselect symbol file))
560 (t
561 (let ((library (or file (symbol-file symbol type))))
562 (find-function-search-for-symbol symbol type library)))))
563
564 ;; For symmetry, this should be called find-face; but some programs
565 ;; assume that, if that name is defined, it means something else.
566 ;;;###autoload
567 (defun find-face-definition (face)
568 "Find the definition of FACE. FACE defaults to the name near point.
569
570 Finds the Emacs Lisp library containing the definition of the face
571 near point (selected by `variable-at-point') in a buffer and
572 places point before the definition.
573
574 Set mark before moving, if the buffer already existed.
575
576 The library where FACE is defined is searched for in
577 `find-function-source-path', if non-nil, otherwise in `load-path'.
578 See also `find-function-recenter-line' and `find-function-after-hook'."
579 (interactive (find-function-read 'defface))
580 (find-function-do-it face 'defface 'switch-to-buffer))
581
582 (defun find-function-on-key-do-it (key find-fn)
583 "Find the function that KEY invokes. KEY is a string.
584 Set mark before moving, if the buffer already existed.
585
586 FIND-FN is the function to call to navigate to the function."
587 (let (defn)
588 (save-excursion
589 (let* ((event (and (eventp key) (aref key 0))) ; Null event OK below.
590 (start (event-start event))
591 (modifiers (event-modifiers event))
592 (window (and (or (memq 'click modifiers) (memq 'down modifiers)
593 (memq 'drag modifiers))
594 (posn-window start))))
595 ;; For a mouse button event, go to the button it applies to
596 ;; to get the right key bindings. And go to the right place
597 ;; in case the keymap depends on where you clicked.
598 (when (windowp window)
599 (set-buffer (window-buffer window))
600 (goto-char (posn-point start)))
601 (setq defn (key-binding key))))
602 (let ((key-desc (key-description key)))
603 (if (or (null defn) (integerp defn))
604 (message "%s is unbound" key-desc)
605 (if (consp defn)
606 (message "%s runs %s" key-desc (prin1-to-string defn))
607 (funcall find-fn defn))))))
608
609 ;;;###autoload
610 (defun find-function-on-key (key)
611 "Find the function that KEY invokes. KEY is a string.
612 Set mark before moving, if the buffer already existed."
613 (interactive "kFind function on key: ")
614 (find-function-on-key-do-it key #'find-function))
615
616 ;;;###autoload
617 (defun find-function-on-key-other-window (key)
618 "Find, in the other window, the function that KEY invokes.
619 See `find-function-on-key'."
620 (interactive "kFind function on key: ")
621 (find-function-on-key-do-it key #'find-function-other-window))
622
623 ;;;###autoload
624 (defun find-function-on-key-other-frame (key)
625 "Find, in the other frame, the function that KEY invokes.
626 See `find-function-on-key'."
627 (interactive "kFind function on key: ")
628 (find-function-on-key-do-it key #'find-function-other-frame))
629
630 ;;;###autoload
631 (defun find-function-at-point ()
632 "Find directly the function at point in the other window."
633 (interactive)
634 (let ((symb (function-called-at-point)))
635 (when symb
636 (find-function-other-window symb))))
637
638 ;;;###autoload
639 (defun find-variable-at-point ()
640 "Find directly the variable at point in the other window."
641 (interactive)
642 (let ((symb (variable-at-point)))
643 (when (and symb (not (equal symb 0)))
644 (find-variable-other-window symb))))
645
646 ;;;###autoload
647 (defun find-function-setup-keys ()
648 "Define some key bindings for the find-function family of functions."
649 (define-key ctl-x-map "F" 'find-function)
650 (define-key ctl-x-4-map "F" 'find-function-other-window)
651 (define-key ctl-x-5-map "F" 'find-function-other-frame)
652 (define-key ctl-x-map "K" 'find-function-on-key)
653 (define-key ctl-x-4-map "K" 'find-function-on-key-other-window)
654 (define-key ctl-x-5-map "K" 'find-function-on-key-other-frame)
655 (define-key ctl-x-map "V" 'find-variable)
656 (define-key ctl-x-4-map "V" 'find-variable-other-window)
657 (define-key ctl-x-5-map "V" 'find-variable-other-frame))
658
659 (provide 'find-func)
660
661 ;;; find-func.el ends here