/[emacs]/emacs/lisp/emacs-lisp/find-func.el
ViewVC logotype

Diff of /emacs/lisp/emacs-lisp/find-func.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.46.4.1 by handa, Fri Apr 16 12:50:13 2004 UTC revision 1.46.4.2 by miles, Mon Jun 28 07:29:46 2004 UTC
# Line 1  Line 1 
1  ;;; find-func.el --- find the definition of the Emacs Lisp function near point  ;;; find-func.el --- find the definition of the Emacs Lisp function near point
2    
3  ;; Copyright (C) 1997, 1999, 2001 Free Software Foundation, Inc.  ;; Copyright (C) 1997, 1999, 2001, 2004  Free Software Foundation, Inc.
4    
5  ;; Author: Jens Petersen <petersen@kurims.kyoto-u.ac.jp>  ;; Author: Jens Petersen <petersen@kurims.kyoto-u.ac.jp>
6  ;; Maintainer: petersen@kurims.kyoto-u.ac.jp  ;; Maintainer: petersen@kurims.kyoto-u.ac.jp
# Line 128  See the functions `find-function' and `f Line 128  See the functions `find-function' and `f
128                     (append (find-library-suffixes) '("")))                     (append (find-library-suffixes) '("")))
129        (error "Can't find library %s" library)))        (error "Can't find library %s" library)))
130    
131    (defvar find-function-C-source-directory
132      (let ((dir (expand-file-name "src" source-directory)))
133        (when (and (file-directory-p dir) (file-readable-p dir))
134          dir))
135      "Directory where the C source files of Emacs can be found.
136    If nil, do not try to find the source code of functions and variables
137    defined in C.")
138    
139    (defun find-function-C-source (fun-or-var file variable-p)
140      "Find the source location where SUBR-OR-VAR is defined in FILE.
141    VARIABLE-P should be non-nil for a variable or nil for a subroutine."
142      (unless find-function-C-source-directory
143        (setq find-function-C-source-directory
144              (read-directory-name "Emacs C source dir: " nil nil t)))
145      (setq file (expand-file-name file find-function-C-source-directory))
146      (unless (file-readable-p file)
147        (error "The C source file %s is not available"
148               (file-name-nondirectory file)))
149      (unless variable-p
150        (setq fun-or-var (indirect-function fun-or-var)))
151      (with-current-buffer (find-file-noselect file)
152        (goto-char (point-min))
153        (unless (re-search-forward
154                 (if variable-p
155                     (concat "DEFVAR[A-Z_]*[ \t\n]*([ \t\n]*\""
156                             (regexp-quote (symbol-name fun-or-var))
157                             "\"")
158                   (concat "DEFUN[ \t\n]*([ \t\n]*\""
159                           (regexp-quote (subr-name fun-or-var))
160                           "\""))
161                 nil t)
162          (error "Can't find source for %s" fun-or-var))
163        (cons (current-buffer) (match-beginning 0))))
164    
165  ;;;###autoload  ;;;###autoload
166  (defun find-library (library)  (defun find-library (library)
167    "Find the elisp source of LIBRARY."    "Find the elisp source of LIBRARY."
# Line 149  If VARIABLE-P is nil, `find-function-reg Line 183  If VARIABLE-P is nil, `find-function-reg
183        (error "Don't know where `%s' is defined" symbol))        (error "Don't know where `%s' is defined" symbol))
184    ;; Some functions are defined as part of the construct    ;; Some functions are defined as part of the construct
185    ;; that defines something else.    ;; that defines something else.
186    (while (get symbol 'definition-name)    (while (and (symbolp symbol) (get symbol 'definition-name))
187      (setq symbol (get symbol 'definition-name)))      (setq symbol (get symbol 'definition-name)))
188    (save-match-data    (if (string-match "\\`src/\\(.*\\.c\\)\\'" library)
189          (find-function-C-source symbol (match-string 1 library) variable-p)
190      (if (string-match "\\.el\\(c\\)\\'" library)      (if (string-match "\\.el\\(c\\)\\'" library)
191          (setq library (substring library 0 (match-beginning 1))))          (setq library (substring library 0 (match-beginning 1))))
192      (let* ((filename (find-library-name library)))      (let* ((filename (find-library-name library)))

Legend:
Removed from v.1.46.4.1  
changed lines
  Added in v.1.46.4.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26