annotate lisp/emacs-lisp/find-func.el @ 47446:8bd5dd6cc381

(find-library-name): Don't forget the empty suffix. Fix stale variable name.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 12 Sep 2002 21:48:20 +0000
parents 8268e926d8e9
children 85021da80289
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
38557
cda1a73acb68 (find-function-regexp): Add
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
3 ;; Copyright (C) 1997, 1999, 2001 Free Software Foundation, Inc.
20183
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
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 33198
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
45326
892ea515fb3a (find-function-search-for-symbol): Find funs defined with defun-cvs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45257
diff changeset
57 (defconst find-function-space-re "\\(?:\\s-\\|\n\\|;.*\n\\)+")
892ea515fb3a (find-function-search-for-symbol): Find funs defined with defun-cvs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45257
diff changeset
58
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
59 (defcustom find-function-regexp
24013
2f040734bd5f Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 23862
diff changeset
60 ;; Match things like (defun foo ...), (defmacro foo ...),
2f040734bd5f Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 23862
diff changeset
61 ;; (define-skeleton foo ...), (define-generic-mode 'foo ...),
26558
2daba92c1033 (find-function-regexp): Use `define-minor-mode' after easy-menu
Dave Love <fx@gnu.org>
parents: 25424
diff changeset
62 ;; (define-derived-mode foo ...), (define-minor-mode foo)
45326
892ea515fb3a (find-function-search-for-symbol): Find funs defined with defun-cvs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45257
diff changeset
63 (concat
892ea515fb3a (find-function-search-for-symbol): Find funs defined with defun-cvs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45257
diff changeset
64 "^\\s-*(\\(def\\(ine-skeleton\\|ine-generic-mode\\|ine-derived-mode\\|\
38557
cda1a73acb68 (find-function-regexp): Add
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
65 \[^cgv\W]\\w+\\*?\\)\\|define-minor-mode\
45326
892ea515fb3a (find-function-search-for-symbol): Find funs defined with defun-cvs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45257
diff changeset
66 \\|easy-mmode-define-global-mode\\)" find-function-space-re
892ea515fb3a (find-function-search-for-symbol): Find funs defined with defun-cvs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45257
diff changeset
67 "\\('\\|\(quote \\)?%s\\(\\s-\\|$\\|\(\\|\)\\)")
24013
2f040734bd5f Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 23862
diff changeset
68 "The regexp used by `find-function' to search for a function definition.
2f040734bd5f Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 23862
diff changeset
69 Note it must contain a `%s' at the place where `format'
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
70 should insert the function name. The default value avoids `defconst',
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
71 `defgroup', `defvar'.
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
72
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
73 Please send improvements and fixes to the maintainer."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
74 :type 'regexp
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
75 :group 'find-function
26558
2daba92c1033 (find-function-regexp): Use `define-minor-mode' after easy-menu
Dave Love <fx@gnu.org>
parents: 25424
diff changeset
76 :version "21.1")
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
77
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
78 (defcustom find-variable-regexp
45326
892ea515fb3a (find-function-search-for-symbol): Find funs defined with defun-cvs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45257
diff changeset
79 (concat"^\\s-*(def[^umag]\\(\\w\\|\\s_\\)+\\*?" find-function-space-re "%s\\(\\s-\\|$\\)")
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
80 "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
81 It should match right up to the variable name. The default value
33155
02b0153b79a7 (find-variable-regexp): Avoid defgroup.
Dave Love <fx@gnu.org>
parents: 32226
diff changeset
82 avoids `defun', `defmacro', `defalias', `defadvice', `defgroup'.
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
83
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
84 Please send improvements and fixes to the maintainer."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
85 :type 'regexp
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
86 :group 'find-function
32226
2af46c6c8bde (find-function-regexp): Remove spurion.
Dave Love <fx@gnu.org>
parents: 26593
diff changeset
87 :version "21.1")
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
88
20962
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20184
diff changeset
89 (defcustom find-function-source-path nil
24013
2f040734bd5f Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 23862
diff changeset
90 "The default list of directories where `find-function' searches.
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
91
24013
2f040734bd5f Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 23862
diff changeset
92 If this variable is nil then `find-function' searches `load-path' by
20962
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20184
diff changeset
93 default."
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20184
diff changeset
94 :type '(repeat directory)
54413501e4a9 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20184
diff changeset
95 :group 'find-function)
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
96
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
97 (defcustom find-function-recenter-line 1
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
98 "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
99 A value of nil implies center the beginning of the definition.
47298
c6dddb2746ee * emacs-lisp/cl-indent.el (extended-loop-p): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents: 47255
diff changeset
100 See `find-function' and `find-variable'."
c6dddb2746ee * emacs-lisp/cl-indent.el (extended-loop-p): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents: 47255
diff changeset
101 :type '(choice (const :tag "Center" nil)
c6dddb2746ee * emacs-lisp/cl-indent.el (extended-loop-p): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents: 47255
diff changeset
102 integer)
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
103 :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
104 :version "20.3")
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
105
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
106 (defcustom find-function-after-hook nil
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
107 "Hook run after finding symbol definition.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
108
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
109 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
110 :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
111 :version "20.3")
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
112
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
113 ;;; Functions:
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
114
47345
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
115 (defun find-library-suffixes ()
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
116 (let ((suffixes nil))
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
117 (dolist (suffix load-suffixes (nreverse suffixes))
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
118 (unless (string-match "elc" suffix) (push suffix suffixes)))))
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
119
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
120 (defun find-library-name (library)
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
121 "Return the full name of the elisp source of LIBRARY."
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
122 ;; If the library is byte-compiled, try to find a source library by
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
123 ;; the same name.
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
124 (if (string-match "\\.el\\(c\\(\\..*\\)\\)\\'" library)
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
125 (setq library (replace-match "" t t library 1)))
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
126 (or (locate-file library
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
127 (or find-function-source-path load-path)
47446
8bd5dd6cc381 (find-library-name): Don't forget the empty suffix. Fix stale variable name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47345
diff changeset
128 (append (find-library-suffixes) ""))
8bd5dd6cc381 (find-library-name): Don't forget the empty suffix. Fix stale variable name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47345
diff changeset
129 (error "Can't find library %s" library)))
47345
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
130
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
131 ;;;###autoload
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
132 (defun find-library (library)
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
133 "Find the elisp source of LIBRARY."
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
134 (interactive
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
135 (list
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
136 (completing-read "Library name: "
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
137 'locate-file-completion
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
138 (cons (or find-function-source-path load-path)
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
139 (find-library-suffixes)))))
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
140 (let ((buf (find-file-noselect (find-library-name library))))
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
141 (condition-case nil (switch-to-buffer buf) (error (pop-to-buffer buf)))))
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
142
45190
9c3195b605f7 (find-function-search-for-symbol): Add autoload cookie.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 45150
diff changeset
143 ;;;###autoload
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
144 (defun find-function-search-for-symbol (symbol variable-p library)
24013
2f040734bd5f Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 23862
diff changeset
145 "Search for SYMBOL.
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
146 If VARIABLE-P is nil, `find-function-regexp' is used, otherwise
47255
ad258fa595db (find-function-search-for-symbol): Fix spacing.
Juanma Barranquero <lekktu@gmail.com>
parents: 46893
diff changeset
147 `find-variable-regexp' is used. The search is done in library LIBRARY."
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
148 (if (null library)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
149 (error "Don't know where `%s' is defined" symbol))
46874
cbd462ecc9ad (find-function-search-for-symbol): Obey `definition-name' properties.
Richard M. Stallman <rms@gnu.org>
parents: 45326
diff changeset
150 ;; Some functions are defined as part of the construct
cbd462ecc9ad (find-function-search-for-symbol): Obey `definition-name' properties.
Richard M. Stallman <rms@gnu.org>
parents: 45326
diff changeset
151 ;; that defines something else.
cbd462ecc9ad (find-function-search-for-symbol): Obey `definition-name' properties.
Richard M. Stallman <rms@gnu.org>
parents: 45326
diff changeset
152 (while (get symbol 'definition-name)
cbd462ecc9ad (find-function-search-for-symbol): Obey `definition-name' properties.
Richard M. Stallman <rms@gnu.org>
parents: 45326
diff changeset
153 (setq symbol (get symbol 'definition-name)))
23862
d0e08cc0aa3d (find-function-search-for-symbol):
Dave Love <fx@gnu.org>
parents: 23737
diff changeset
154 (save-match-data
d0e08cc0aa3d (find-function-search-for-symbol):
Dave Love <fx@gnu.org>
parents: 23737
diff changeset
155 (if (string-match "\\.el\\(c\\)\\'" library)
d0e08cc0aa3d (find-function-search-for-symbol):
Dave Love <fx@gnu.org>
parents: 23737
diff changeset
156 (setq library (substring library 0 (match-beginning 1))))
47345
8268e926d8e9 (find-library-suffixes, find-library-name)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47298
diff changeset
157 (let* ((filename (find-library-name library)))
23862
d0e08cc0aa3d (find-function-search-for-symbol):
Dave Love <fx@gnu.org>
parents: 23737
diff changeset
158 (with-current-buffer (find-file-noselect filename)
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
159 (let ((regexp (format (if variable-p
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
160 find-variable-regexp
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
161 find-function-regexp)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
162 (regexp-quote (symbol-name symbol))))
45120
254bce531056 (find-function-search-for-symbol): Bind case-fold-search when searching.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 40480
diff changeset
163 (case-fold-search))
45150
4a2bcce6b13a (find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 45120
diff changeset
164 (with-syntax-table emacs-lisp-mode-syntax-table
4a2bcce6b13a (find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 45120
diff changeset
165 (goto-char (point-min))
4a2bcce6b13a (find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 45120
diff changeset
166 (if (or (re-search-forward regexp nil t)
4a2bcce6b13a (find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 45120
diff changeset
167 (re-search-forward
45326
892ea515fb3a (find-function-search-for-symbol): Find funs defined with defun-cvs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45257
diff changeset
168 (concat "^([^ ]+" find-function-space-re "['(]"
45150
4a2bcce6b13a (find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 45120
diff changeset
169 (regexp-quote (symbol-name symbol))
4a2bcce6b13a (find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 45120
diff changeset
170 "\\>")
4a2bcce6b13a (find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 45120
diff changeset
171 nil t))
4a2bcce6b13a (find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 45120
diff changeset
172 (progn
4a2bcce6b13a (find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 45120
diff changeset
173 (beginning-of-line)
4a2bcce6b13a (find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 45120
diff changeset
174 (cons (current-buffer) (point)))
4a2bcce6b13a (find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 45120
diff changeset
175 (error "Cannot find definition of `%s' in library `%s'"
4a2bcce6b13a (find-function-search-for-symbol): Use with-syntax-table.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 45120
diff changeset
176 symbol library))))))))
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
177
22851
2c2eb47ec8e3 (find-function-noselect): Autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 22759
diff changeset
178 ;;;###autoload
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
179 (defun find-function-noselect (function)
24013
2f040734bd5f Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 23862
diff changeset
180 "Return a pair (BUFFER . POINT) pointing to the definition of FUNCTION.
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
181
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
182 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
183 in a buffer and the point of the definition. The buffer is
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
184 not selected.
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
185
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
186 If the file where FUNCTION is defined is not known, then it is
24013
2f040734bd5f Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 23862
diff changeset
187 searched for in `find-function-source-path' if non nil, otherwise
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
188 in `load-path'."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
189 (if (not function)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
190 (error "You didn't specify a function"))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
191 (and (subrp (symbol-function function))
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
192 (error "%s is a primitive function" function))
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
193 (let ((def (symbol-function function))
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
194 aliases)
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
195 (while (symbolp def)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
196 (or (eq def function)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
197 (if aliases
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
198 (setq aliases (concat aliases
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
199 (format ", which is an alias for `%s'"
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
200 (symbol-name def))))
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
201 (setq aliases (format "`%s' an alias for `%s'"
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
202 function (symbol-name def)))))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
203 (setq function (symbol-function function)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
204 def (symbol-function function)))
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
205 (if aliases
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
206 (message aliases))
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
207 (let ((library
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
208 (cond ((eq (car-safe def) 'autoload)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
209 (nth 1 def))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
210 ((symbol-file function)))))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
211 (find-function-search-for-symbol function nil library))))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
212
32226
2af46c6c8bde (find-function-regexp): Remove spurion.
Dave Love <fx@gnu.org>
parents: 26593
diff changeset
213 (defalias 'function-at-point 'function-called-at-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 (defun find-function-read (&optional variable-p)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
216 "Read and return an interned symbol, defaulting to the one near point.
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
217
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
218 If the optional VARIABLE-P is nil, then a function is gotten
24013
2f040734bd5f Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 23862
diff changeset
219 defaulting to the value of the function `function-at-point', otherwise
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
220 a variable is asked for, with the default coming from
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
221 `variable-at-point'."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
222 (let ((symb (funcall (if variable-p
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
223 'variable-at-point
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
224 'function-at-point)))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
225 (enable-recursive-minibuffers t)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
226 val)
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
227 (if (equal symb 0)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
228 (setq symb nil))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
229 (setq val (if variable-p
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
230 (completing-read
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
231 (concat "Find variable"
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
232 (if symb
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
233 (format " (default %s)" symb))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
234 ": ")
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
235 obarray 'boundp t nil)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
236 (completing-read
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
237 (concat "Find function"
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
238 (if symb
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
239 (format " (default %s)" symb))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
240 ": ")
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
241 obarray 'fboundp t nil)))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
242 (list (if (equal val "")
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
243 symb
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
244 (intern val)))))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
245
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
246 (defun find-function-do-it (symbol variable-p switch-fn)
24013
2f040734bd5f Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 23862
diff changeset
247 "Find Emacs Lisp SYMBOL in a buffer and display it.
2f040734bd5f Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 23862
diff changeset
248 If VARIABLE-P is nil, a function definition is searched for, otherwise
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
249 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
250 centered according to the variable `find-function-recenter-line'.
24013
2f040734bd5f Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 23862
diff changeset
251 See also `find-function-after-hook' It is displayed with function SWITCH-FN.
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
252
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
253 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
254 (let* ((orig-point (point))
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
255 (orig-buf (window-buffer))
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
256 (orig-buffers (buffer-list))
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
257 (buffer-point (save-excursion
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
258 (funcall (if variable-p
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
259 'find-variable-noselect
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
260 'find-function-noselect)
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
261 symbol)))
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
262 (new-buf (car buffer-point))
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
263 (new-point (cdr buffer-point)))
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
264 (when buffer-point
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
265 (when (memq new-buf orig-buffers)
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
266 (push-mark orig-point))
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
267 (funcall switch-fn new-buf)
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
268 (goto-char new-point)
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
269 (recenter find-function-recenter-line)
33198
167dad6064bf (find-function-do-it): Quote the hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33155
diff changeset
270 (run-hooks 'find-function-after-hook))))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
271
20184
c8d4024e07de (find-function, find-function-other-window, find-function-other-frame,
Dave Love <fx@gnu.org>
parents: 20183
diff changeset
272 ;;;###autoload
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
273 (defun find-function (function)
24021
a937ab82e54f More doc fixes.
Dave Love <fx@gnu.org>
parents: 24013
diff changeset
274 "Find the definition of the FUNCTION near point.
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
275
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
276 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
277 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
278 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
279 it is one of the current buffers.
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
280
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
281 The library where FUNCTION is defined is searched for in
24013
2f040734bd5f Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 23862
diff changeset
282 `find-function-source-path', if non nil, otherwise in `load-path'.
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
283 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
284 (interactive (find-function-read))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
285 (find-function-do-it function nil 'switch-to-buffer))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
286
20184
c8d4024e07de (find-function, find-function-other-window, find-function-other-frame,
Dave Love <fx@gnu.org>
parents: 20183
diff changeset
287 ;;;###autoload
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
288 (defun find-function-other-window (function)
24021
a937ab82e54f More doc fixes.
Dave Love <fx@gnu.org>
parents: 24013
diff changeset
289 "Find, in another window, the definition of FUNCTION near point.
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
290
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
291 See `find-function' for more details."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
292 (interactive (find-function-read))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
293 (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
294
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
295 ;;;###autoload
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
296 (defun find-function-other-frame (function)
24021
a937ab82e54f More doc fixes.
Dave Love <fx@gnu.org>
parents: 24013
diff changeset
297 "Find, in ananother frame, the definition of FUNCTION near point.
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
298
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
299 See `find-function' for more details."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
300 (interactive (find-function-read))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
301 (find-function-do-it function nil 'switch-to-buffer-other-frame))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
302
23659
e221aa952b5b (find-variable-noselect): Autoload.
Karl Heuer <kwzh@gnu.org>
parents: 23287
diff changeset
303 ;;;###autoload
40480
5ebd79883369 (find-function-search-for-symbol):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38557
diff changeset
304 (defun find-variable-noselect (variable &optional file)
5ebd79883369 (find-function-search-for-symbol):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38557
diff changeset
305 "Return a pair `(BUFFER . POINT)' pointing to the definition of SYMBOL.
22641
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 Finds the Emacs Lisp library containing the definition of SYMBOL
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
308 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
309 not selected.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
310
40480
5ebd79883369 (find-function-search-for-symbol):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38557
diff changeset
311 The library where VARIABLE is defined is searched for in FILE or
24013
2f040734bd5f Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 23862
diff changeset
312 `find-function-source-path', if non nil, otherwise in `load-path'."
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
313 (if (not variable)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
314 (error "You didn't specify a variable"))
40480
5ebd79883369 (find-function-search-for-symbol):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38557
diff changeset
315 (let ((library (or file (symbol-file variable))))
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
316 (find-function-search-for-symbol variable 'variable library)))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
317
20184
c8d4024e07de (find-function, find-function-other-window, find-function-other-frame,
Dave Love <fx@gnu.org>
parents: 20183
diff changeset
318 ;;;###autoload
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
319 (defun find-variable (variable)
24021
a937ab82e54f More doc fixes.
Dave Love <fx@gnu.org>
parents: 24013
diff changeset
320 "Find the definition of the VARIABLE near point.
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
321
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
322 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
323 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
324 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
325 it is one of the current buffers.
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
326
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
327 The library where VARIABLE is defined is searched for in
24013
2f040734bd5f Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 23862
diff changeset
328 `find-function-source-path', if non nil, otherwise in `load-path'.
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
329 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
330 (interactive (find-function-read 'variable))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
331 (find-function-do-it variable t 'switch-to-buffer))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
332
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
333 ;;;###autoload
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
334 (defun find-variable-other-window (variable)
24021
a937ab82e54f More doc fixes.
Dave Love <fx@gnu.org>
parents: 24013
diff changeset
335 "Find, in another window, the definition of VARIABLE near point.
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
336
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
337 See `find-variable' for more details."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
338 (interactive (find-function-read 'variable))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
339 (find-function-do-it variable t 'switch-to-buffer-other-window))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
340
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
341 ;;;###autoload
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
342 (defun find-variable-other-frame (variable)
24021
a937ab82e54f More doc fixes.
Dave Love <fx@gnu.org>
parents: 24013
diff changeset
343 "Find, in annother frame, the definition of VARIABLE near point.
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
344
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
345 See `find-variable' for more details."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
346 (interactive (find-function-read 'variable))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
347 (find-function-do-it variable t 'switch-to-buffer-other-frame))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
348
20184
c8d4024e07de (find-function, find-function-other-window, find-function-other-frame,
Dave Love <fx@gnu.org>
parents: 20183
diff changeset
349 ;;;###autoload
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
350 (defun find-function-on-key (key)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
351 "Find the function that KEY invokes. KEY is a string.
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
352 Point is saved if FUNCTION is in the current buffer."
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
353 (interactive "kFind function on key: ")
24034
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
354 (save-excursion
24062
dd143e80ffcf (find-function-on-key): Fix previous
Dave Love <fx@gnu.org>
parents: 24034
diff changeset
355 (let* ((event (and (eventp key) (aref key 0))) ; Null event OK below.
24034
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
356 (start (event-start event))
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
357 (modifiers (event-modifiers event))
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
358 (window (and (or (memq 'click modifiers) (memq 'down modifiers)
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
359 (memq 'drag modifiers))
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
360 (posn-window start))))
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
361 ;; For a mouse button event, go to the button it applies to
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
362 ;; to get the right key bindings. And go to the right place
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
363 ;; in case the keymap depends on where you clicked.
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
364 (when (windowp window)
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
365 (set-buffer (window-buffer window))
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
366 (goto-char (posn-point start)))
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
367 (let ((defn (key-binding key))
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
368 (key-desc (key-description key)))
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
369 (if (or (null defn) (integerp defn))
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
370 (message "%s is unbound" key-desc)
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
371 (if (consp defn)
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
372 (message "%s runs %s" key-desc (prin1-to-string defn))
25a9e0ae5c91 (find-function-on-key): DTRT for mouse
Dave Love <fx@gnu.org>
parents: 24021
diff changeset
373 (find-function-other-window defn)))))))
22641
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
374
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
375 ;;;###autoload
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
376 (defun find-function-at-point ()
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
377 "Find directly the function at point in the other window."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
378 (interactive)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
379 (let ((symb (function-at-point)))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
380 (when symb
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
381 (find-function-other-window symb))))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
382
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
383 ;;;###autoload
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
384 (defun find-variable-at-point ()
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
385 "Find directly the function at point in the other window."
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
386 (interactive)
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
387 (let ((symb (variable-at-point)))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
388 (when (and symb (not (equal symb 0)))
1c5197790616 Require `loadhist'. Variable
Richard M. Stallman <rms@gnu.org>
parents: 22487
diff changeset
389 (find-variable-other-window symb))))
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
390
22759
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
391 ;;;###autoload
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
392 (defun find-function-setup-keys ()
be3e1a724828 (find-function-regexp): Added :version 20.3.
Richard M. Stallman <rms@gnu.org>
parents: 22641
diff changeset
393 "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
394 (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
395 (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
396 (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
397 (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
398 (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
399 (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
400 (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
401
20183
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
402 (provide 'find-func)
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
403
add8b7b3a7da Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
404 ;;; find-func.el ends here