diff options
| author | Stefan Monnier | 2004-04-29 18:39:14 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2004-04-29 18:39:14 +0000 |
| commit | 4479a2f89ae5b29bdedf55cd00de40843c9df59d (patch) | |
| tree | d2f66ae5c220c0b2f0681f2f64c17b4df301cbba | |
| parent | 0fddae66f4ac29a98fd7073ba4a1fdfc5139fa17 (diff) | |
| download | emacs-4479a2f89ae5b29bdedf55cd00de40843c9df59d.tar.gz emacs-4479a2f89ae5b29bdedf55cd00de40843c9df59d.zip | |
(find-function-C-source-directory): New var.
(find-function-C-source): New fun.
(find-function-search-for-symbol): Use it.
| -rw-r--r-- | lisp/emacs-lisp/find-func.el | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el index 5a7cd1093c4..54efd14b358 100644 --- a/lisp/emacs-lisp/find-func.el +++ b/lisp/emacs-lisp/find-func.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; find-func.el --- find the definition of the Emacs Lisp function near point | 1 | ;;; find-func.el --- find the definition of the Emacs Lisp function near point |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1997, 1999, 2001 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1997, 1999, 2001, 2004 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Jens Petersen <petersen@kurims.kyoto-u.ac.jp> | 5 | ;; Author: Jens Petersen <petersen@kurims.kyoto-u.ac.jp> |
| 6 | ;; Maintainer: petersen@kurims.kyoto-u.ac.jp | 6 | ;; Maintainer: petersen@kurims.kyoto-u.ac.jp |
| @@ -128,6 +128,40 @@ See the functions `find-function' and `find-variable'." | |||
| 128 | (append (find-library-suffixes) '(""))) | 128 | (append (find-library-suffixes) '(""))) |
| 129 | (error "Can't find library %s" library))) | 129 | (error "Can't find library %s" library))) |
| 130 | 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 | |||
| 131 | ;;;###autoload | 165 | ;;;###autoload |
| 132 | (defun find-library (library) | 166 | (defun find-library (library) |
| 133 | "Find the elisp source of LIBRARY." | 167 | "Find the elisp source of LIBRARY." |
| @@ -149,9 +183,10 @@ If VARIABLE-P is nil, `find-function-regexp' is used, otherwise | |||
| 149 | (error "Don't know where `%s' is defined" symbol)) | 183 | (error "Don't know where `%s' is defined" symbol)) |
| 150 | ;; Some functions are defined as part of the construct | 184 | ;; Some functions are defined as part of the construct |
| 151 | ;; that defines something else. | 185 | ;; that defines something else. |
| 152 | (while (get symbol 'definition-name) | 186 | (while (and (symbolp symbol) (get symbol 'definition-name)) |
| 153 | (setq symbol (get symbol 'definition-name))) | 187 | (setq symbol (get symbol 'definition-name))) |
| 154 | (save-match-data | 188 | (if (string-match "\\`src/\\(.*\\.c\\)\\'" library) |
| 189 | (find-function-C-source symbol (match-string 1 library) variable-p) | ||
| 155 | (if (string-match "\\.el\\(c\\)\\'" library) | 190 | (if (string-match "\\.el\\(c\\)\\'" library) |
| 156 | (setq library (substring library 0 (match-beginning 1)))) | 191 | (setq library (substring library 0 (match-beginning 1)))) |
| 157 | (let* ((filename (find-library-name library))) | 192 | (let* ((filename (find-library-name library))) |