comparison lisp/help-fns.el @ 55234:fde56fd631fc

(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.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 29 Apr 2004 18:46:13 +0000
parents 10f2535aa14e
children 8037f1969898
comparison
equal deleted inserted replaced
55233:038fab289258 55234:fde56fd631fc
214 (let ((name (symbol-name arg))) 214 (let ((name (symbol-name arg)))
215 (if (string-match "\\`&" name) arg 215 (if (string-match "\\`&" name) arg
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)
243 (insert-file-contents-literally 229 (insert-file-contents-literally
244 (expand-file-name internal-doc-file-name doc-directory))) 230 (expand-file-name internal-doc-file-name doc-directory)))
245 (search-forward (concat "" name "\n")) 231 (search-forward (concat "" name "\n"))
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
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 239
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)
277 (symbol-function function) 243 (symbol-function function)
334 (with-current-buffer (car location) 300 (with-current-buffer (car location)
335 (goto-char (cdr location)) 301 (goto-char (cdr location))
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
350 (save-excursion 318 (save-excursion
351 (re-search-backward "`\\([^`']+\\)'" nil t) 319 (re-search-backward "`\\([^`']+\\)'" nil t)
574 "^;;; Generated autoloads from \\(.*\\)" nil t) 542 "^;;; Generated autoloads from \\(.*\\)" nil t)
575 (setq file-name (match-string 1))))))) 543 (setq file-name (match-string 1)))))))
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
589 (re-search-backward "`\\([^`']+\\)'" nil t) 557 (re-search-backward "`\\([^`']+\\)'" nil t)
590 (help-xref-button 1 'help-variable-def 558 (help-xref-button 1 'help-variable-def