annotate lisp/emacs-lisp/find-func.el @ 23201:392b44751a22

(ccl_coding_driver): Always calculate correct mulibyte chars in produced byte sequence. (Ffind_operation_coding_system): Doc-string fixed.
author Kenichi Handa <handa@m17n.org>
date Mon, 07 Sep 1998 13:39:15 +0000
parents d311287a03a6
children bf60e2b4da28
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
1 ;;; find-func.el --- find the definition of the Emacs Lisp function near point
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
2
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
4
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
5 ;; Author: Jens Petersen <petersen@kurims.kyoto-u.ac.jp>
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
6 ;; Maintainer: petersen@kurims.kyoto-u.ac.jp
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
7 ;; Keywords: emacs-lisp, functions, variables
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
8 ;; Created: 97/07/25
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
9
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
11
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
15 ;; any later version.
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
16
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
21
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
26
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
28 ;;
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
29 ;; The funniest thing about this is that I can't imagine why a package
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
30 ;; so obviously useful as this hasn't been written before!!
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
31 ;; ;;; find-func
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
32 ;; (find-function-setup-keys)
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
33 ;;
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
34 ;; or just:
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
35 ;;
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
36 ;; (load "find-func")
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
37 ;;
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
38 ;; if you don't like the given keybindings and away you go! It does
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
39 ;; pretty much what you would expect, putting the cursor at the
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
40 ;; definition of the function or variable at point.
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
41 ;;
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
42 ;; The code started out from `describe-function', `describe-key'
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
43 ;; ("help.el") and `fff-find-loaded-emacs-lisp-function' (Noah Friedman's
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
44 ;; "fff.el").
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
45
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
46 ;;;; Code:
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
47
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
48 (require 'loadhist)
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
49
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
50 ;;; User variables:
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
51
20962
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20184
diff changeset
52 (defgroup find-function nil
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
53 "Finds the definition of the Emacs Lisp symbol near point."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
54 ;; :prefix "find-function"
20962
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20184
diff changeset
55 :group 'lisp)
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
56
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
57 (defcustom find-function-regexp
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
58 "^\\s-*(def[^cgv\W]\\w+\\*?\\s-+%s\\(\\s-\\|$\\)"
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
59 "The regexp used by `find-function' to search for a function
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
60 definition. Note it must contain a `%s' at the place where `format'
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
61 should insert the function name. The default value avoids `defconst',
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
62 `defgroup', `defvar'.
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
63
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
64 Please send improvements and fixes to the maintainer."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
65 :type 'regexp
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
66 :group 'find-function
23100
043247d0ced9 Fix :version tags to have a string value, not a float.
Andreas Schwab <schwab@suse.de>
parents: 22867
diff changeset
67 :version "20.3")
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
68
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
69 (defcustom find-variable-regexp
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
70 "^\\s-*(def[^uma\W]\\w+\\*?\\s-+%s\\(\\s-\\|$\\)"
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
71 "The regexp used by `find-variable' to search for a variable definition.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
72 It should match right up to the variable name. The default value
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
73 avoids `defun', `defmacro', `defalias', `defadvice'.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
74
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
75 Please send improvements and fixes to the maintainer."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
76 :type 'regexp
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
77 :group 'find-function
23100
043247d0ced9 Fix :version tags to have a string value, not a float.
Andreas Schwab <schwab@suse.de>
parents: 22867
diff changeset
78 :version "20.3")
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
79
20962
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20184
diff changeset
80 (defcustom find-function-source-path nil
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
81 "The default list of directories where find-function searches.
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
82
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
83 If this variable is `nil' then find-function searches `load-path' by
20962
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20184
diff changeset
84 default."
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20184
diff changeset
85 :type '(repeat directory)
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20184
diff changeset
86 :group 'find-function)
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
87
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
88 (defcustom find-function-recenter-line 1
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
89 "The window line-number from which to start displaying a symbol definition.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
90 A value of nil implies center the beginning of the definition.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
91 See the function `center-to-window-line' for more information, and
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
92 `find-function' and `find-variable'."
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
93 :group 'find-function
23100
043247d0ced9 Fix :version tags to have a string value, not a float.
Andreas Schwab <schwab@suse.de>
parents: 22867
diff changeset
94 :version "20.3")
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
95
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
96 (defcustom find-function-after-hook nil
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
97 "Hook run after finding symbol definition.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
98
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
99 See the functions `find-function' and `find-variable'."
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
100 :group 'find-function
23100
043247d0ced9 Fix :version tags to have a string value, not a float.
Andreas Schwab <schwab@suse.de>
parents: 22867
diff changeset
101 :version "20.3")
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
102
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
103 ;;; Functions:
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
104
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
105 (defun find-function-search-for-symbol (symbol variable-p library)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
106 "Search for SYMBOL in LIBRARY.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
107 If VARIABLE-P is nil, `find-function-regexp' is used, otherwise
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
108 `find-variable-regexp' is used."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
109 (if (null library)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
110 (error "Don't know where `%s' is defined" symbol))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
111 (if (string-match "\\.el\\(c\\)\\'" library)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
112 (setq library (substring library 0 (match-beginning 1))))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
113 (let* ((path find-function-source-path)
23118
d311287a03a6 (find-function-search-for-symbol): Look
Dave Love <fx@gnu.org>
parents: 23100
diff changeset
114 (compression (or (rassq 'jka-compr-handler file-name-handler-alist)
d311287a03a6 (find-function-search-for-symbol): Look
Dave Love <fx@gnu.org>
parents: 23100
diff changeset
115 (member 'crypt-find-file-hook find-file-hooks)))
22867
7e35e50acaa4 (find-function-search-for-symbol): Ignore directories
Richard M. Stallman <rms@gnu.org>
parents: 22851
diff changeset
116 (filename (if (and (file-exists-p library)
7e35e50acaa4 (find-function-search-for-symbol): Ignore directories
Richard M. Stallman <rms@gnu.org>
parents: 22851
diff changeset
117 (not (file-directory-p library)))
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
118 library
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
119 ;; use `file-name-sans-extension' here? (if it gets fixed)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
120 (if (string-match "\\(\\.el\\)\\'" library)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
121 (setq library (substring library 0
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
122 (match-beginning 1))))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
123 (or (locate-library (concat library ".el") t path)
23118
d311287a03a6 (find-function-search-for-symbol): Look
Dave Love <fx@gnu.org>
parents: 23100
diff changeset
124 (locate-library library t path)
d311287a03a6 (find-function-search-for-symbol): Look
Dave Love <fx@gnu.org>
parents: 23100
diff changeset
125 (if compression
d311287a03a6 (find-function-search-for-symbol): Look
Dave Love <fx@gnu.org>
parents: 23100
diff changeset
126 (or (locate-library (concat library ".el.gz")
d311287a03a6 (find-function-search-for-symbol): Look
Dave Love <fx@gnu.org>
parents: 23100
diff changeset
127 t path)
d311287a03a6 (find-function-search-for-symbol): Look
Dave Love <fx@gnu.org>
parents: 23100
diff changeset
128 (locate-library (concat library ".gz")
d311287a03a6 (find-function-search-for-symbol): Look
Dave Love <fx@gnu.org>
parents: 23100
diff changeset
129 t path)))))))
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
130 (if (not filename)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
131 (error "The library \"%s\" is not in the path." library))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
132 (with-current-buffer (find-file-noselect filename)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
133 (save-match-data
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
134 (let ((regexp (format (if variable-p
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
135 find-variable-regexp
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
136 find-function-regexp)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
137 (regexp-quote (symbol-name symbol))))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
138 (syn-table (syntax-table)))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
139 (unwind-protect
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
140 (progn
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
141 (set-syntax-table emacs-lisp-mode-syntax-table)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
142 (goto-char (point-min))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
143 (if (re-search-forward regexp nil t)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
144 (progn
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
145 (beginning-of-line)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
146 (cons (current-buffer) (point)))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
147 (error "Cannot find definition of `%s' in library \"%s\""
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
148 symbol library)))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
149 (set-syntax-table syn-table)))))))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
150
22851
2c2eb47ec8e3 (find-function-noselect): Autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 22759
diff changeset
151 ;;;###autoload
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
152 (defun find-function-noselect (function)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
153 "Returns a pair (BUFFER . POINT) pointing to the definition of FUNCTION.
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
154
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
155 Finds the Emacs Lisp library containing the definition of FUNCTION
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
156 in a buffer and the point of the definition. The buffer is
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
157 not selected.
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
158
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
159 If the file where FUNCTION is defined is not known, then it is
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
160 searched for in `find-function-source-path' if non `nil', otherwise
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
161 in `load-path'."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
162 (if (not function)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
163 (error "You didn't specify a function"))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
164 (and (subrp (symbol-function function))
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
165 (error "%s is a primitive function" function))
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
166 (let ((def (symbol-function function))
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
167 aliases)
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
168 (while (symbolp def)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
169 (or (eq def function)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
170 (if aliases
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
171 (setq aliases (concat aliases
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
172 (format ", which is an alias for `%s'"
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
173 (symbol-name def))))
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
174 (setq aliases (format "`%s' an alias for `%s'"
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
175 function (symbol-name def)))))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
176 (setq function (symbol-function function)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
177 def (symbol-function function)))
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
178 (if aliases
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
179 (message aliases))
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
180 (let ((library
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
181 (cond ((eq (car-safe def) 'autoload)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
182 (nth 1 def))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
183 ((symbol-file function)))))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
184 (find-function-search-for-symbol function nil library))))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
185
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
186 (defun function-at-point ()
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
187 (or (condition-case ()
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
188 (let ((stab (syntax-table)))
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
189 (unwind-protect
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
190 (save-excursion
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
191 (set-syntax-table emacs-lisp-mode-syntax-table)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
192 (or (not (zerop (skip-syntax-backward "_w")))
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
193 (eq (char-syntax (char-after (point))) ?w)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
194 (eq (char-syntax (char-after (point))) ?_)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
195 (forward-sexp -1))
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
196 (skip-chars-forward "`'")
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
197 (let ((obj (read (current-buffer))))
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
198 (and (symbolp obj) (fboundp obj) obj)))
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
199 (set-syntax-table stab)))
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
200 (error nil))
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
201 (condition-case ()
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
202 (save-excursion
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
203 (save-restriction
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
204 (narrow-to-region (max (point-min) (- (point) 1000)) (point-max))
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
205 (backward-up-list 1)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
206 (forward-char 1)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
207 (let (obj)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
208 (setq obj (read (current-buffer)))
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
209 (and (symbolp obj) (fboundp obj) obj))))
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
210 (error nil))))
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
211
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
212 (defun find-function-read (&optional variable-p)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
213 "Read and return an interned symbol, defaulting to the one near point.
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
214
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
215 If the optional VARIABLE-P is nil, then a function is gotten
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
216 defaulting to the value of the function `function-at-point', otherwise
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
217 a variable is asked for, with the default coming from
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
218 `variable-at-point'."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
219 (let ((symb (funcall (if variable-p
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
220 'variable-at-point
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
221 'function-at-point)))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
222 (enable-recursive-minibuffers t)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
223 val)
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
224 (if (equal symb 0)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
225 (setq symb nil))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
226 (setq val (if variable-p
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
227 (completing-read
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
228 (concat "Find variable"
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
229 (if symb
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
230 (format " (default %s)" symb))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
231 ": ")
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
232 obarray 'boundp t nil)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
233 (completing-read
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
234 (concat "Find function"
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
235 (if symb
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
236 (format " (default %s)" symb))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
237 ": ")
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
238 obarray 'fboundp t nil)))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
239 (list (if (equal val "")
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
240 symb
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
241 (intern val)))))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
242
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
243 (defun find-function-do-it (symbol variable-p switch-fn)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
244 "Find Emacs Lisp SYMBOL in a buffer and display it with SWITCH-FN.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
245 If VARIABLE-P is nil, a function definition is searched for, otherwise
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
246 a variable definition is searched for. The start of a definition is
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
247 centered according to the variable `find-function-recenter-line'.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
248 See also `find-function-after-hook'.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
249
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
250 Point is saved in the buffer if it is one of the current buffers."
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
251 (let* ((orig-point (point))
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
252 (orig-buf (window-buffer))
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
253 (orig-buffers (buffer-list))
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
254 (buffer-point (save-excursion
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
255 (funcall (if variable-p
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
256 'find-variable-noselect
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
257 'find-function-noselect)
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
258 symbol)))
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
259 (new-buf (car buffer-point))
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
260 (new-point (cdr buffer-point)))
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
261 (when buffer-point
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
262 (when (memq new-buf orig-buffers)
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
263 (push-mark orig-point))
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
264 (funcall switch-fn new-buf)
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
265 (goto-char new-point)
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
266 (recenter find-function-recenter-line)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
267 (run-hooks find-function-after-hook))))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
268
20184
c8d4024e07de (find-function, find-function-other-window, find-function-other-frame,
Dave Love <fx@gnu.org>
parents: 20183
diff changeset
269 ;;;###autoload
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
270 (defun find-function (function)
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
271 "Find the definition of the function near point in the current window.
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
272
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
273 Finds the Emacs Lisp library containing the definition of the function
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
274 near point (selected by `function-at-point') in a buffer and
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
275 places point before the definition. Point is saved in the buffer if
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
276 it is one of the current buffers.
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
277
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
278 The library where FUNCTION is defined is searched for in
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
279 `find-function-source-path', if non `nil', otherwise in `load-path'.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
280 See also `find-function-recenter-line' and `find-function-after-hook'."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
281 (interactive (find-function-read))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
282 (find-function-do-it function nil 'switch-to-buffer))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
283
20184
c8d4024e07de (find-function, find-function-other-window, find-function-other-frame,
Dave Love <fx@gnu.org>
parents: 20183
diff changeset
284 ;;;###autoload
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
285 (defun find-function-other-window (function)
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
286 "Find the definition of the function near point in the other window.
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
287
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
288 See `find-function' for more details."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
289 (interactive (find-function-read))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
290 (find-function-do-it function nil 'switch-to-buffer-other-window))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
291
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
292 ;;;###autoload
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
293 (defun find-function-other-frame (function)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
294 "Find the definition of the function near point in the another frame.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
295
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
296 See `find-function' for more details."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
297 (interactive (find-function-read))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
298 (find-function-do-it function nil 'switch-to-buffer-other-frame))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
299
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
300 (defun find-variable-noselect (variable)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
301 "Returns a pair `(buffer . point)' pointing to the definition of SYMBOL.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
302
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
303 Finds the Emacs Lisp library containing the definition of SYMBOL
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
304 in a buffer and the point of the definition. The buffer is
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
305 not selected.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
306
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
307 The library where VARIABLE is defined is searched for in
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
308 `find-function-source-path', if non `nil', otherwise in `load-path'."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
309 (if (not variable)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
310 (error "You didn't specify a variable"))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
311 (let ((library (symbol-file variable)))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
312 (find-function-search-for-symbol variable 'variable library)))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
313
20184
c8d4024e07de (find-function, find-function-other-window, find-function-other-frame,
Dave Love <fx@gnu.org>
parents: 20183
diff changeset
314 ;;;###autoload
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
315 (defun find-variable (variable)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
316 "Find the definition of the variable near point in the current window.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
317
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
318 Finds the Emacs Lisp library containing the definition of the variable
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
319 near point (selected by `variable-at-point') in a buffer and
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
320 places point before the definition. Point is saved in the buffer if
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
321 it is one of the current buffers.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
322
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
323 The library where VARIABLE is defined is searched for in
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
324 `find-function-source-path', if non `nil', otherwise in `load-path'.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
325 See also `find-function-recenter-line' and `find-function-after-hook'."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
326 (interactive (find-function-read 'variable))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
327 (find-function-do-it variable t 'switch-to-buffer))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
328
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
329 ;;;###autoload
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
330 (defun find-variable-other-window (variable)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
331 "Find the definition of the variable near point in the other window.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
332
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
333 See `find-variable' for more details."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
334 (interactive (find-function-read 'variable))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
335 (find-function-do-it variable t 'switch-to-buffer-other-window))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
336
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
337 ;;;###autoload
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
338 (defun find-variable-other-frame (variable)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
339 "Find the definition of the variable near point in the another frame.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
340
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
341 See `find-variable' for more details."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
342 (interactive (find-function-read 'variable))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
343 (find-function-do-it variable t 'switch-to-buffer-other-frame))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
344
20184
c8d4024e07de (find-function, find-function-other-window, find-function-other-frame,
Dave Love <fx@gnu.org>
parents: 20183
diff changeset
345 ;;;###autoload
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
346 (defun find-function-on-key (key)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
347 "Find the function that KEY invokes. KEY is a string.
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
348 Point is saved if FUNCTION is in the current buffer."
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
349 (interactive "kFind function on key: ")
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
350 (let ((defn (key-binding key))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
351 (key-desc (key-description key)))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
352 (if (or (null defn) (integerp defn))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
353 (message "%s is unbound" key-desc)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
354 (if (consp defn)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
355 (message "%s runs %s" key-desc (prin1-to-string defn))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
356 (find-function-other-window defn)))))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
357
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
358 ;;;###autoload
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
359 (defun find-function-at-point ()
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
360 "Find directly the function at point in the other window."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
361 (interactive)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
362 (let ((symb (function-at-point)))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
363 (when symb
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
364 (find-function-other-window symb))))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
365
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
366 ;;;###autoload
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
367 (defun find-variable-at-point ()
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
368 "Find directly the function at point in the other window."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
369 (interactive)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
370 (let ((symb (variable-at-point)))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
371 (when (and symb (not (equal symb 0)))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
372 (find-variable-other-window symb))))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
373
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
374 ;;;###autoload
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
375 (defun find-function-setup-keys ()
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
376 "Define some key bindings for the find-function family of functions."
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
377 (define-key ctl-x-map "F" 'find-function)
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
378 (define-key ctl-x-4-map "F" 'find-function-other-window)
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
379 (define-key ctl-x-5-map "F" 'find-function-other-frame)
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
380 (define-key ctl-x-map "K" 'find-function-on-key)
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
381 (define-key ctl-x-map "V" 'find-variable)
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
382 (define-key ctl-x-4-map "V" 'find-variable-other-window)
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
383 (define-key ctl-x-5-map "V" 'find-variable-other-frame))
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
384
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
385 (provide 'find-func)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
386
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
387 ;;; find-func.el ends here