20
20
:use-module (ice-9 documentation)
21
21
:use-module (ice-9 regex)
22
22
:use-module (ice-9 rdelim)
23
:export (help apropos apropos-internal apropos-fold
24
apropos-fold-accessible apropos-fold-exported apropos-fold-all
25
source arity system-module))
24
add-value-help-handler! remove-value-help-handler!
25
add-name-help-handler! remove-name-help-handler!
26
apropos apropos-internal apropos-fold apropos-fold-accessible
27
apropos-fold-exported apropos-fold-all source arity
28
system-module module-commentary))
32
(define *value-help-handlers*
33
`(,(lambda (name value)
34
(object-documentation value))))
36
(define (add-value-help-handler! proc)
37
"Adds a handler for performing `help' on a value.
39
`proc' will be called as (PROC NAME VALUE). `proc' should return #t to
40
indicate that it has performed help, a string to override the default
41
object documentation, or #f to try the other handlers, potentially
42
falling back on the normal behavior for `help'."
43
(set! *value-help-handlers* (cons proc *value-help-handlers*)))
45
(define (remove-value-help-handler! proc)
46
"Removes a handler for performing `help' on a value."
47
(set! *value-help-handlers* (delete! proc *value-help-handlers*)))
49
(define (try-value-help name value)
50
(or-map (lambda (proc) (proc name value)) *value-help-handlers*))
53
(define *name-help-handlers* '())
55
(define (add-name-help-handler! proc)
56
"Adds a handler for performing `help' on a name.
58
`proc' will be called with the unevaluated name as its argument. That is
59
to say, when the user calls `(help FOO)', the name is FOO, exactly as
62
`proc' should return #t to indicate that it has performed help, a string
63
to override the default object documentation, or #f to try the other
64
handlers, potentially falling back on the normal behavior for `help'."
65
(set! *name-help-handlers* (cons proc *name-help-handlers*)))
67
(define (remove-name-help-handler! proc)
68
"Removes a handler for performing `help' on a name."
69
(set! *name-help-handlers* (delete! proc *name-help-handlers*)))
71
(define (try-name-help name)
72
(or-map (lambda (proc) (proc name)) *name-help-handlers*))
60
110
((and (list? name)
61
111
(= (length name) 2)
62
112
(eq? (car name) 'unquote))
63
(cond ((object-documentation
64
(local-eval (cadr name) env))
66
(else (not-found 'documentation (cadr name)))))
113
(let ((doc (try-value-help (cadr name)
114
(local-eval (cadr name) env))))
115
(cond ((not doc) (not-found 'documentation (cadr name)))
116
((eq? doc #t)) ;; pass
117
(else (write-line doc)))))
69
120
((and (list? name)