find-func.el 22 KB

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