annotate lisp/prim/find-func.el @ 207:e45d5e7c476e r20-4b2

Import from CVS: tag r20-4b2
author cvs
date Mon, 13 Aug 2007 10:03:52 +0200
parents 850242ba4a81
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
1 ;;; find-func.el --- find the definition of the Emacs Lisp function near point
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
2
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
4
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
5 ;; Author: Jens Petersen <petersen@kurims.kyoto-u.ac.jp>
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
6 ;; Maintainer: petersen@kurims.kyoto-u.ac.jp
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
7 ;; Keywords: emacs-lisp, functions
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
8 ;; Created: 97/07/25
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
9 ;; URL: <http://www.kurims.kyoto-u.ac.jp/~petersen/emacs-lisp/>
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
10
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
11 ;; $Id: find-func.el,v 1.2 1997/10/31 14:53:07 steve Exp $
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
12
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
13 ;; This file is part of XEmacs.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
14
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
15 ;; XEmacs is free software; you can redistribute it and/or modify it
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
16 ;; under the terms of the GNU General Public License as published by
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
17 ;; the Free Software Foundation; either version 2, or (at your option)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
18 ;; any later version.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
19
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
20 ;; XEmacs is distributed in the hope that it will be useful, but
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
23 ;; General Public License for more details.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
24
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
25 ;; You should have received a copy of the GNU General Public License
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
26 ;; along with XEmacs; see the file COPYING. If not, write to the
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
27 ;; Free Software Foundation, 59 Temple Place - Suite 330,
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
28 ;; Boston, MA 02111-1307, USA.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
29
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
30 ;;; Commentary:
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
31 ;;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
32 ;; The funniest thing about this is that I can't imagine why a package
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
33 ;; so obviously useful as this hasn't been written before!!
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
34 ;;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
35 ;; Put this file in your `load-path', byte-compile it and add the
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
36 ;; following code in your init file:
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
37 ;;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
38 ;; ;;; find-func
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
39 ;; (load "find-func")
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
40 ;; (global-set-key [(control ?c) ?f] 'find-function)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
41 ;; (global-set-key [(control ?c) ?4 ?f] 'find-function-other-window)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
42 ;; (global-set-key [(control ?c) ?5 ?f] 'find-function-other-frame)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
43 ;; (global-set-key [(control ?c) ?k] 'find-function-on-key)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
44 ;;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
45 ;; and away you go! It does pretty much what you would expect,
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
46 ;; putting the cursor at the definition of the function at point.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
47 ;;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
48 ;; In XEmacs the source file of dumped functions is recorded (and can
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
49 ;; be accessed with the function `compiled-function-annotation', which
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
50 ;; doesn't exist in Emacs), so in XEmacs non-primitive dumped
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
51 ;; functions can also be found. Unfortunately this is not possible in
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
52 ;; Emacs. It would be nice if the location of primitive functions in
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
53 ;; the C code was also recorded!
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
54
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
55 ;; The code is adapted from `describe-function', `describe-key'
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
56 ;; ("help.el") and `fff-find-loaded-emacs-lisp-function' (Noah Friedman's
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
57 ;; "fff.el").
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
58
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
59 ;;; To do:
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
60 ;;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
61 ;; o improve handling of advice'd functions? (at the moment it goes to
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
62 ;; the advice, not the actual definition)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
63 ;;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
64 ;; o `find-function-other-frame' is not quite right when the function
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
65 ;; is in the current buffer.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
66 ;;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
67 ;;;; Code:
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
68
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
69 (defgroup find-function nil
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
70 "Find the definition of the Emacs Lisp function near point."
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
71 :group 'lisp)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
72
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
73 ;;; User variables:
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
74
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
75 (defcustom find-function-source-path nil
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
76 "The default list of directories where find-function searches.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
77
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
78 If this variable is `nil' then find-function searches `load-path' by
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
79 default."
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
80 :type '(choice (const :tag "Use `load-path'" nil)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
81 (repeat :tag "Directories"
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
82 :menu-tag "List"
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
83 :value ("")
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
84 directory))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
85 :group 'find-function)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
86
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
87
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
88 ;;; Functions:
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
89
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
90 (defun find-function-noselect (function)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
91 "Returns a pair `(buffer . point)' pointing to the definition of FUNCTION.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
92
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
93 Finds the Emacs Lisp library containing the definition of FUNCTION
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
94 in a buffer and the point of the definition. The buffer is
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
95 not selected.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
96
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
97 The library where FUNCTION is defined is searched for in
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
98 `find-function-source-path', if non `nil', otherwise in `load-path'."
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
99 (if (not function)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
100 (error "You didn't specify a function"))
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
101 (and (subrp (symbol-function function))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
102 (error "%s is a primitive function" function))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
103 (let ((def (symbol-function function))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
104 library aliases)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
105 (while (symbolp def)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
106 (or (eq def function)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
107 (if aliases
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
108 (setq aliases (concat aliases
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
109 (format ", which is an alias for %s"
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
110 (symbol-name def))))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
111 (setq aliases (format "an alias for %s" (symbol-name def)))))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
112 (setq function (symbol-function function)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
113 def (symbol-function function)))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
114 (if aliases
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
115 (message aliases))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
116 (setq library
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
117 (cond ((eq (car-safe def) 'autoload)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
118 (nth 1 def))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
119 ((describe-function-find-file function))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
120 ((compiled-function-p def)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
121 (substring (compiled-function-annotation def) 0 -4))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
122 ((eq 'macro (car-safe def))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
123 (and (compiled-function-p (cdr def))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
124 (substring (compiled-function-annotation (cdr def)) 0 -4)))))
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
125 (if (null library)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
126 (error (format "Don't know where `%s' is defined" function)))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
127 (if (string-match "\\.el\\(c\\)\\'" library)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
128 (setq library (substring library 0 (match-beginning 1))))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
129 (let* ((path find-function-source-path)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
130 (filename (if (file-exists-p library)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
131 library
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
132 (if (string-match "\\(\\.el\\)\\'" library)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
133 (setq library (substring library 0
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
134 (match-beginning
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
135 1))))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
136 (or (locate-library (concat library ".el") t path)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
137 (locate-library library t path)))))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
138 (if (not filename)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
139 (error "The library \"%s\" is not in the path." library))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
140 (with-current-buffer (find-file-noselect filename)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
141 (save-match-data
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
142 (let (;; avoid defconst, defgroup, defvar (any others?)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
143 (regexp
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
144 (format "^\\s-*(def[^cgv\W]\\w+\\*?\\s-+%s\\s-" function))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
145 (syntable (syntax-table)))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
146 (set-syntax-table emacs-lisp-mode-syntax-table)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
147 (goto-char (point-min))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
148 (if (prog1
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
149 (re-search-forward regexp nil t)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
150 (set-syntax-table syntable))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
151 (progn
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
152 (beginning-of-line)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
153 (cons (current-buffer) (point)))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
154 (error "Cannot find definition of `%s'" function))))))))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
155
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
156 (defun find-function-read-function ()
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
157 "Read and return a function, defaulting to the one near point.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
158
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
159 `function-at-point' is used to select the default function."
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
160 (let ((fn (function-at-point))
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
161 (enable-recursive-minibuffers t)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
162 val)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
163 (setq val (completing-read
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
164 (if fn
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
165 (format "Find function (default %s): " fn)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
166 "Find function: ")
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
167 obarray 'fboundp t nil 'function-history))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
168 (list (if (equal val "")
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
169 fn (intern val)))))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
170
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
171 (defun find-function-do-it (function switch-fn)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
172 "Find Emacs Lisp FUNCTION in a buffer and display it with SWITCH-FN.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
173 Point is saved in the buffer if it is one of the current buffers."
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
174 (let ((orig-point (point))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
175 (orig-buffers (buffer-list))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
176 (buffer-point (find-function-noselect function)))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
177 (when buffer-point
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
178 (funcall switch-fn (car buffer-point))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
179 (when (memq (car buffer-point) orig-buffers)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
180 (push-mark orig-point))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
181 (goto-char (cdr buffer-point))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
182 (recenter 0))))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
183
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
184 ;;;###autoload
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
185 (defun find-function (function)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
186 "Find the definition of the function near point in the current window.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
187
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
188 Finds the Emacs Lisp library containing the definition of the function
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
189 near point (selected by `function-at-point') in a buffer and
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
190 places point before the definition. Point is saved in the buffer if
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
191 it is one of the current buffers.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
192
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
193 The library where FUNCTION is defined is searched for in
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
194 `find-function-source-path', if non `nil', otherwise in `load-path'."
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
195 (interactive (find-function-read-function))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
196 (find-function-do-it function 'switch-to-buffer))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
197
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
198 ;;;###autoload
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
199 (defun find-function-other-window (function)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
200 "Find the definition of the function near point in the other window.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
201
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
202 Finds the Emacs Lisp library containing the definition of the function
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
203 near point (selected by `function-at-point') in a buffer and
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
204 places point before the definition. Point is saved in the buffer if
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
205 it is one of the current buffers.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
206
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
207 The library where FUNCTION is defined is searched for in
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
208 `find-function-source-path', if non `nil', otherwise in `load-path'."
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
209 (interactive (find-function-read-function))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
210 (find-function-do-it function 'switch-to-buffer-other-window))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
211
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
212 ;;;###autoload
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
213 (defun find-function-other-frame (function)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
214 "Find the definition of the function near point in the another frame.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
215
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
216 Finds the Emacs Lisp library containing the definition of the function
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
217 near point (selected by `function-at-point') in a buffer and
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
218 places point before the definition. Point is saved in the buffer if
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
219 it is one of the current buffers.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
220
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
221 The library where FUNCTION is defined is searched for in
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
222 `find-function-source-path', if non `nil', otherwise in `load-path'."
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
223 (interactive (find-function-read-function))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
224 (find-function-do-it function 'switch-to-buffer-other-frame))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
225
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
226 ;;;###autoload
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
227 (defun find-function-on-key (key)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
228 "Find the function that KEY invokes. KEY is a string.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
229 Point is saved if FUNCTION is in the current buffer."
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
230 (interactive "kFind function on key: ")
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
231 (let ((defn (key-or-menu-binding key)))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
232 (if (or (null defn) (integerp defn))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
233 (message "%s is undefined" (key-description key))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
234 (if (and (consp defn) (not (eq 'lambda (car-safe defn))))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
235 (message "runs %s" (prin1-to-string defn))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
236 (find-function-other-window defn)))))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
237
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
238 ;;;###autoload
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
239 (defun find-function-at-point ()
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
240 "Find directly the function at point in the other window."
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
241 (interactive)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
242 (let ((symb (function-at-point)))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
243 (when symb
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
244 (find-function-other-window symb))))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
245
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
246 ;; (define-key ctl-x-map "F" 'find-function) ; conflicts with `facemenu-keymap'
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
247
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
248 ;;;###autoload
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
249 (define-key ctl-x-4-map "F" 'find-function-other-window)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
250 ;;;###autoload
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
251 (define-key ctl-x-5-map "F" 'find-function-other-frame)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
252 ;;;###autoload
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
253 (define-key ctl-x-map "K" 'find-function-on-key)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
254
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
255 (provide 'find-func)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents:
diff changeset
256 ;;; find-func.el ends here