diff options
| author | Stefan Monnier | 2004-04-29 18:46:13 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2004-04-29 18:46:13 +0000 |
| commit | 3ff0a7e940fcd238439d985f67d223e2a071c74f (patch) | |
| tree | 6b1e2a2004246d65027a3af0390d6aeadd3369e2 | |
| parent | 2ea0f8fde524c4998c0ab933cd27ecd50c54e09a (diff) | |
| download | emacs-3ff0a7e940fcd238439d985f67d223e2a071c74f.tar.gz emacs-3ff0a7e940fcd238439d985f67d223e2a071c74f.zip | |
(help-C-file-name): Use new subr-name.
Prepend `src/' to the file name.
(help-C-source-directory, help-subr-name, help-find-C-source): Remove.
(describe-function-1, describe-variable): Only find a C source file name
if DOC is already loaded.
| -rw-r--r-- | lisp/help-fns.el | 60 |
1 files changed, 14 insertions, 46 deletions
diff --git a/lisp/help-fns.el b/lisp/help-fns.el index 6a71a544638..4e57ea6d74e 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el | |||
| @@ -216,27 +216,13 @@ ARGLIST can also be t or a string of the form \"(fun ARG1 ARG2 ...)\"." | |||
| 216 | (intern (upcase name)))))) | 216 | (intern (upcase name)))))) |
| 217 | arglist))) | 217 | arglist))) |
| 218 | 218 | ||
| 219 | (defvar help-C-source-directory | ||
| 220 | (let ((dir (expand-file-name "src" source-directory))) | ||
| 221 | (when (and (file-directory-p dir) (file-readable-p dir)) | ||
| 222 | dir)) | ||
| 223 | "Directory where the C source files of Emacs can be found. | ||
| 224 | If nil, do not try to find the source code of functions and variables | ||
| 225 | defined in C.") | ||
| 226 | |||
| 227 | (defun help-subr-name (subr) | ||
| 228 | (let ((name (prin1-to-string subr))) | ||
| 229 | (if (string-match "\\`#<subr \\(.*\\)>\\'" name) | ||
| 230 | (match-string 1 name) | ||
| 231 | (error "Unexpected subroutine print name: %s" name)))) | ||
| 232 | |||
| 233 | (defun help-C-file-name (subr-or-var kind) | 219 | (defun help-C-file-name (subr-or-var kind) |
| 234 | "Return the name of the C file where SUBR-OR-VAR is defined. | 220 | "Return the name of the C file where SUBR-OR-VAR is defined. |
| 235 | KIND should be `var' for a variable or `subr' for a subroutine." | 221 | KIND should be `var' for a variable or `subr' for a subroutine." |
| 236 | (let ((docbuf (get-buffer-create " *DOC*")) | 222 | (let ((docbuf (get-buffer-create " *DOC*")) |
| 237 | (name (if (eq 'var kind) | 223 | (name (if (eq 'var kind) |
| 238 | (concat "V" (symbol-name subr-or-var)) | 224 | (concat "V" (symbol-name subr-or-var)) |
| 239 | (concat "F" (help-subr-name subr-or-var))))) | 225 | (concat "F" (subr-name subr-or-var))))) |
| 240 | (with-current-buffer docbuf | 226 | (with-current-buffer docbuf |
| 241 | (goto-char (point-min)) | 227 | (goto-char (point-min)) |
| 242 | (if (eobp) | 228 | (if (eobp) |
| @@ -246,31 +232,11 @@ KIND should be `var' for a variable or `subr' for a subroutine." | |||
| 246 | (re-search-backward "S\\(.*\\)") | 232 | (re-search-backward "S\\(.*\\)") |
| 247 | (let ((file (match-string 1))) | 233 | (let ((file (match-string 1))) |
| 248 | (if (string-match "\\.\\(o\\|obj\\)\\'" file) | 234 | (if (string-match "\\.\\(o\\|obj\\)\\'" file) |
| 249 | (replace-match ".c" t t file) | 235 | (setq file (replace-match ".c" t t file))) |
| 236 | (if (string-match "\\.c\\'" file) | ||
| 237 | (concat "src/" file) | ||
| 250 | file))))) | 238 | file))))) |
| 251 | 239 | ||
| 252 | (defun help-find-C-source (fun-or-var file kind) | ||
| 253 | "Find the source location where SUBR-OR-VAR is defined in FILE. | ||
| 254 | KIND should be `var' for a variable or `subr' for a subroutine." | ||
| 255 | (setq file (expand-file-name file help-C-source-directory)) | ||
| 256 | (unless (file-readable-p file) | ||
| 257 | (error "The C source file %s is not available" | ||
| 258 | (file-name-nondirectory file))) | ||
| 259 | (if (eq 'fun kind) | ||
| 260 | (setq fun-or-var (indirect-function fun-or-var))) | ||
| 261 | (with-current-buffer (find-file-noselect file) | ||
| 262 | (goto-char (point-min)) | ||
| 263 | (unless (re-search-forward | ||
| 264 | (if (eq 'fun kind) | ||
| 265 | (concat "DEFUN[ \t\n]*([ \t\n]*\"" | ||
| 266 | (regexp-quote (help-subr-name fun-or-var)) | ||
| 267 | "\"") | ||
| 268 | (concat "DEFVAR[A-Z_]*[ \t\n]*([ \t\n]*\"" | ||
| 269 | (regexp-quote (symbol-name fun-or-var)))) | ||
| 270 | nil t) | ||
| 271 | (error "Can't find source for %s" fun)) | ||
| 272 | (cons (current-buffer) (match-beginning 0)))) | ||
| 273 | |||
| 274 | ;;;###autoload | 240 | ;;;###autoload |
| 275 | (defun describe-function-1 (function) | 241 | (defun describe-function-1 (function) |
| 276 | (let* ((def (if (symbolp function) | 242 | (let* ((def (if (symbolp function) |
| @@ -336,14 +302,16 @@ KIND should be `var' for a variable or `subr' for a subroutine." | |||
| 336 | (when (re-search-backward | 302 | (when (re-search-backward |
| 337 | "^;;; Generated autoloads from \\(.*\\)" nil t) | 303 | "^;;; Generated autoloads from \\(.*\\)" nil t) |
| 338 | (setq file-name (match-string 1))))))) | 304 | (setq file-name (match-string 1))))))) |
| 339 | (when (and (null file-name) (subrp def) help-C-source-directory) | 305 | (when (and (null file-name) (subrp def)) |
| 340 | ;; Find the C source file name. | 306 | ;; Find the C source file name. |
| 341 | (setq file-name (concat "src/" (help-C-file-name def 'subr)))) | 307 | (setq file-name (if (get-buffer " *DOC*") |
| 308 | (help-C-file-name def 'subr) | ||
| 309 | 'C-source))) | ||
| 342 | (when file-name | 310 | (when file-name |
| 343 | (princ " in `") | 311 | (princ " in `") |
| 344 | ;; We used to add .el to the file name, | 312 | ;; We used to add .el to the file name, |
| 345 | ;; but that's completely wrong when the user used load-file. | 313 | ;; but that's completely wrong when the user used load-file. |
| 346 | (princ file-name) | 314 | (princ (if (eq file-name 'C-source) "C source code" file-name)) |
| 347 | (princ "'") | 315 | (princ "'") |
| 348 | ;; Make a hyperlink to the library. | 316 | ;; Make a hyperlink to the library. |
| 349 | (with-current-buffer standard-output | 317 | (with-current-buffer standard-output |
| @@ -576,13 +544,13 @@ it is displayed along with the global value." | |||
| 576 | (when (and (null file-name) | 544 | (when (and (null file-name) |
| 577 | (integerp (get variable 'variable-documentation))) | 545 | (integerp (get variable 'variable-documentation))) |
| 578 | ;; It's a variable not defined in Elisp but in C. | 546 | ;; It's a variable not defined in Elisp but in C. |
| 579 | (if help-C-source-directory | 547 | (setq file-name |
| 580 | (setq file-name | 548 | (if (get-buffer " *DOC*") |
| 581 | (concat "src/" (help-C-file-name variable 'var))) | 549 | (help-C-file-name variable 'var) |
| 582 | (princ "\n\nDefined in core C code."))) | 550 | 'C-source))) |
| 583 | (when file-name | 551 | (when file-name |
| 584 | (princ "\n\nDefined in `") | 552 | (princ "\n\nDefined in `") |
| 585 | (princ file-name) | 553 | (princ (if (eq file-name 'C-source) "C source code" file-name)) |
| 586 | (princ "'.") | 554 | (princ "'.") |
| 587 | (with-current-buffer standard-output | 555 | (with-current-buffer standard-output |
| 588 | (save-excursion | 556 | (save-excursion |