[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/geiser-guile a461795 017/284: Better docstring.
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/geiser-guile a461795 017/284: Better docstring. |
Date: |
Sun, 1 Aug 2021 18:29:07 -0400 (EDT) |
branch: elpa/geiser-guile
commit a4617956ba2df89d03b1b5b9ce589fa5c79995d1
Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
Commit: Jose Antonio Ortega Ruiz <jao@gnu.org>
Better docstring.
---
geiser/introspection.scm | 69 +++++++++++++++++++++++++++++++++---------------
1 file changed, 47 insertions(+), 22 deletions(-)
diff --git a/geiser/introspection.scm b/geiser/introspection.scm
index f6bb152..aa1e388 100644
--- a/geiser/introspection.scm
+++ b/geiser/introspection.scm
@@ -33,10 +33,18 @@
(define (arguments sym . syms)
(let loop ((sym sym) (syms syms))
- (cond ((obj-args (symbol->obj sym)) => (lambda (args) (cons sym args)))
+ (cond ((obj-args (symbol->obj sym)) => (lambda (args)
+ (cons sym (apply args-alist
args))))
((null? syms) #f)
(else (loop (car syms) (cdr syms))))))
+(define (args-alist args opt module)
+ (list (cons 'required args)
+ (cons 'optional (or opt '()))
+ (cons 'module (cond ((module? module) (module-name module))
+ ((list? module) module)
+ (else '())))))
+
(define (symbol->obj sym)
(and (symbol? sym)
(module-defined? (current-module) sym)
@@ -63,9 +71,9 @@
(arg-no (first arity))
(opt (> (second arity) 0))
(args (map first (take (program-bindings program) arg-no))))
- (format-args (if opt (drop-right args 1) args)
- (and opt (last args))
- (program-module program))))
+ (list (if opt (drop-right args 1) args)
+ (and opt (last args))
+ (program-module program))))
(define (procedure-args proc)
(let ((name (procedure-name proc)))
@@ -74,34 +82,27 @@
(else (let* ((arity (procedure-property proc 'arity))
(req (first arity))
(opt (third arity)))
- (format-args (map (lambda (n)
- (string->symbol (format "arg~A" (+ 1
n))))
- (iota req))
- (and opt 'rest)
- (and name (symbol-module name))))))))
+ (list (map (lambda (n)
+ (string->symbol (format "arg~A" (+ 1 n))))
+ (iota req))
+ (and opt 'rest)
+ (and name (symbol-module name))))))))
(define (procedure-args-from-source name src)
(let ((formals (cadr src)))
- (cond ((list? formals) (format-args formals #f (symbol-module name)))
+ (cond ((list? formals) (list formals #f (symbol-module name)))
((pair? formals) (let ((req (car formals))
(opt (cdr formals)))
- (format-args (if (list? req) req (list req))
- opt
- (symbol-module name))))
+ (list (if (list? req) req (list req))
+ opt
+ (symbol-module name))))
(else #f))))
(define (macro-args macro)
(let ((prog (macro-transformer macro)))
(if prog
(obj-args prog)
- (format-args '(...) #f #f))))
-
-(define (format-args args opt module)
- (list (cons 'required args)
- (cons 'optional (or opt '()))
- (cons 'module (cond ((module? module) (module-name module))
- ((list? module) module)
- (else '())))))
+ (list '(...) #f #f))))
(define (completions prefix)
(sort! (map symbol->string
@@ -121,8 +122,32 @@
(define (make-location-from-module-name name)
(make-location (module-filename name) #f))
+(define (display-docstring sym)
+ (let ((obj (symbol->obj sym)))
+ (if obj
+ (let* ((args (obj-args obj))
+ (req (and args (car args)))
+ (opt (and args (cadr args)))
+ (signature (if args (cond ((and (not req) (not opt)) (list sym))
+ ((and (not opt) req) (cons sym req))
+ ((and (not req) opt) (cons sym opt))
+ (else `(,sym ,@req . ,opt)))
+ sym))
+ (type (cond ((macro? obj) "A macro")
+ ((procedure? obj) "A procedure")
+ ((program? obj) "A compiled program")
+ (else "An object")))
+ (modname (symbol-module sym)))
+ (display signature)
+ (newline)
+ (display type)
+ (if modname (begin (display " in module ")
+ (display modname)))
+ (newline)
+ (display (or (object-documentation obj) ""))))))
(define (docstring sym)
- (object-documentation (symbol->obj sym)))
+ (with-output-to-string
+ (lambda () (display-docstring sym))))
;;; introspection.scm ends here
- [nongnu] elpa/geiser-guile 6ff9936 052/284: They say call/cc is slow in Guile., (continued)
- [nongnu] elpa/geiser-guile 6ff9936 052/284: They say call/cc is slow in Guile., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile a96b437 053/284: turn-on/off-geiser-mode commands added and used in scheme-mode-hook., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile d71825c 058/284: Small bug fix., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile fe48642 008/284: M-. working for any symbol whose module can be located., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 75df3b1 024/284: Better symbol documentation., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 8cb76f1 045/284: Breakdown of schemeland into neat submodules., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 7b77380 054/284: New command to display generic methods (C-cC-dg) implemented., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 33b8c53 066/284: Callers/callees (C-c <, C-c >)., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 3398bc2 012/284: Inconsequential refactorings., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile af1c5a3 013/284: Small improvements., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile a461795 017/284: Better docstring.,
Philip Kaludercic <=
- [nongnu] elpa/geiser-guile 6f2ed87 018/284: Recognise empty doc string in Emacs side. Small refactorings., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 63c39be 019/284: Initial support for module name completion., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 06fabb2 020/284: Compile command adapted to new compiled-file-name behaviour., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 3432ccf 021/284: New command: module documentation., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 08ba036 023/284: Separate commands for evaluation and compilation., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile d18c35b 025/284: Fix in symbol help signature displaying., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 3655a74 026/284: (geiser eval) functionality moved to (geiser emacs)., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 8377f5e 028/284: Refactoring of the eval/compile procedures., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 2ac3f91 027/284: Play nice with (ice-9 history) by using WRITE to return values to Emacs., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 49842df 031/284: Correct stack in load/compile file retorts., Philip Kaludercic, 2021/08/01