unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* pushed to master: extensibility to (ice-9 session)
@ 2009-01-27 12:50 Andy Wingo
  2009-01-27 20:30 ` Ludovic Courtès
  2009-01-27 22:10 ` Neil Jerram
  0 siblings, 2 replies; 13+ messages in thread
From: Andy Wingo @ 2009-01-27 12:50 UTC (permalink / raw)
  To: guile-devel

Hi,

I pushed the following patch to master. Is it OK to push to 1.8 as well?
That way I could drop some modules from guile-lib, and make guile-lib
depend on guile >= 1.8.x.

(Perhaps we can set up a list for patches that get pushed to Guile ?)

Andy

commit 4f7a0504aac215832e99290e31c9944795c5d206
Author: Andy Wingo <wingo@pobox.com>
Date:   Tue Jan 27 13:43:07 2009 +0100

    merge in from guile-lib: add some extensibility to `help'
    
    * ice-9/session.scm (add-value-help-handler!)
      (remove-value-help-handler!, add-name-help-handler!)
      (remove-name-help-handler!): New public interfaces, to allow some basic
      extensibility of the help interface. Merged in from guile-lib's (scheme
      session).

diff --git a/ice-9/session.scm b/ice-9/session.scm
index 1c9f480..6971a78 100644
--- a/ice-9/session.scm
+++ b/ice-9/session.scm
@@ -20,12 +20,61 @@
   :use-module (ice-9 documentation)
   :use-module (ice-9 regex)
   :use-module (ice-9 rdelim)
-  :export (help apropos apropos-internal apropos-fold
-	   apropos-fold-accessible apropos-fold-exported apropos-fold-all
-	   source arity system-module))
+  :export (help
+           add-value-help-handler! remove-value-help-handler!
+           add-name-help-handler! remove-name-help-handler!
+           apropos apropos-internal apropos-fold apropos-fold-accessible
+           apropos-fold-exported apropos-fold-all source arity
+           system-module module-commentary))
 
 \f
 
+(define *value-help-handlers* '())
+
+(define (add-value-help-handler! proc)
+  "Adds a handler for performing `help' on a value.
+
+`proc' will be called as (PROC NAME VALUE). `proc' should return #t to
+indicate that it has performed help, a string to override the default
+object documentation, or #f to try the other handlers, potentially
+falling back on the normal behavior for `help'."
+  (set! *value-help-handlers* (cons proc *value-help-handlers*)))
+
+(define (remove-value-help-handler! proc)
+  "Removes a handler for performing `help' on a value.
+
+See the documentation for `add-value-help-handler' for more
+information."
+  (set! *value-help-handlers* (delete! proc *value-help-handlers*)))
+
+(define (try-value-help name value)
+  (or-map (lambda (proc) (proc name value)) *value-help-handlers*))
+
+
+(define *name-help-handlers* '())
+
+(define (add-name-help-handler! proc)
+  "Adds a handler for performing `help' on a name.
+
+`proc' will be called with the unevaluated name as its argument. That is
+to say, when the user calls `(help FOO)', the name is FOO, exactly as
+the user types it.
+
+The return value of `proc' is as specified in
+`add-value-help-handler!'."
+  (set! *name-help-handlers* (cons proc *name-help-handlers*)))
+
+(define (remove-name-help-handler! proc)
+  "Removes a handler for performing `help' on a name.
+
+See the documentation for `add-name-help-handler' for more
+information."
+  (set! *name-help-handlers* (delete! proc *name-help-handlers*)))
+
+(define (try-name-help name)
+  (or-map (lambda (proc) (proc name)) *name-help-handlers*))
+
+
 ;;; Documentation
 ;;;
 (define help
@@ -45,6 +94,10 @@ You don't seem to have regular expressions installed.\n"))
                                                type x))))
                (cond
 
+                ;; User-specified
+                ((try-name-help name)
+                 => (lambda (x) (if (not (eq? x #t)) (display x))))
+
                 ;; SYMBOL
                 ((symbol? name)
                  (help-doc name
@@ -60,10 +113,12 @@ You don't seem to have regular expressions installed.\n"))
                 ((and (list? name)
                       (= (length name) 2)
                       (eq? (car name) 'unquote))
-                 (cond ((object-documentation
-                         (local-eval (cadr name) env))
-                        => write-line)
-                       (else (not-found 'documentation (cadr name)))))
+                 (let ((value (local-eval (cadr name) env)))
+                   (cond ((try-value-help (cadr name) value)
+                          => noop)
+                         ((object-documentation value)
+                          => write-line)
+                         (else (not-found 'documentation (cadr name))))))
 
                 ;; (quote SYMBOL)
                 ((and (list? name)
@@ -109,7 +164,8 @@ You don't seem to have regular expressions installed.\n"))
   (let ((entries (apropos-fold (lambda (module name object data)
 				 (cons (list module
 					     name
-					     (object-documentation object)
+					     (or (try-value-help name object)
+                                                 (object-documentation object))
 					     (cond ((closure? object)
 						    "a procedure")
 						   ((procedure? object)

-- 
http://wingolog.org/




^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2009-02-04  8:13 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-27 12:50 pushed to master: extensibility to (ice-9 session) Andy Wingo
2009-01-27 20:30 ` Ludovic Courtès
2009-01-27 22:02   ` Neil Jerram
2009-01-27 23:31     ` Ludovic Courtès
2009-01-28  0:33     ` Clinton Ebadi
2009-01-28  8:31       ` Ludovic Courtès
2009-01-28 10:29   ` Andy Wingo
2009-01-28 12:26     ` Ludovic Courtès
2009-01-28 15:03       ` Andy Wingo
2009-01-27 22:10 ` Neil Jerram
2009-01-28 11:16   ` Andy Wingo
2009-02-03 23:25     ` Neil Jerram
2009-02-04  8:13     ` szgyg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).