[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/geiser-guile 4e1d945 088/284: Simpler, more correct and ef
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/geiser-guile 4e1d945 088/284: Simpler, more correct and efficient autodoc implementation. |
Date: |
Sun, 1 Aug 2021 18:29:22 -0400 (EDT) |
branch: elpa/geiser-guile
commit 4e1d945d26deb751fce01a8be4a55a6934691f96
Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
Commit: Jose Antonio Ortega Ruiz <jao@gnu.org>
Simpler, more correct and efficient autodoc implementation.
Not that it was difficult: it's replacing an ugly kludge.
---
geiser/doc.scm | 85 +++++++++++++++-------------------------------------------
1 file changed, 21 insertions(+), 64 deletions(-)
diff --git a/geiser/doc.scm b/geiser/doc.scm
index 3f060e3..d951f1c 100644
--- a/geiser/doc.scm
+++ b/geiser/doc.scm
@@ -37,76 +37,33 @@
#:use-module (oop goops)
#:use-module (srfi srfi-1))
-(define (autodoc form)
- (cond ((null? form) #f)
- ((symbol? form) (describe-application (list form)))
- ((not (pair? form)) #f)
- ((not (list? form)) (autodoc (pair->list form)))
- ((define-head? form) => autodoc)
- (else (autodoc/list form))))
-
-(define (autodoc/list form)
- (let ((lst (last form)))
- (cond ((and (symbol? lst) (describe-application (list lst))))
- ((and (pair? lst) (not (memq (car lst) '(quote))) (autodoc lst)))
- (else (describe-application form)))))
-
-(define (define-head? form)
- (define defforms '(define define* define-macro define-macro*
- define-method define-class define-generic))
- (and (= 2 (length form))
- (memq (car form) defforms)
- (car form)))
-
-(define (describe-application form)
- (let* ((fun (car form))
- (args (obj-args (symbol->object fun))))
+(define (autodoc ids)
+ (if (not (list? ids))
+ '()
+ (map (lambda (id) (or (autodoc* id) (list id))) ids)))
+
+(define (autodoc* id)
+ (let ((args (obj-args (symbol->object id))))
(and args
- (list (cons 'signature (signature fun args))
- (cons 'position (find-position args form))
- (cons 'module (symbol-module fun))))))
+ `(,@(signature id args)
+ (module . ,(symbol-module id))))))
(define (object-signature name obj)
(let ((args (obj-args obj)))
(and args (signature name args))))
-(define (signature fun args)
- (let ((req (arglst args 'required))
- (opt (arglst args 'optional))
- (key (arglst args 'keyword))
- (rest (assq-ref args 'rest)))
- (let ((sgn `(,fun ,@req
- ,@(if (not (null? opt)) (cons 'geiser-opt_marker opt)
'())
- ,@(if (not (null? key)) (cons 'geiser-key_maker key)
'()))))
- (if rest `(,@sgn geiser-rest_marker ,rest) sgn))))
-
-(define (find-position args form)
- (let* ((lf (length form))
- (lf-1 (- lf 1)))
- (if (= 1 lf) 0
- (let ((req (length (arglst args 'required)))
- (opt (length (arglst args 'optional)))
- (keys (map (lambda (k) (symbol->keyword (if (list? k) (car k)
k)))
- (arglst args 'keyword)))
- (rest (assq-ref args 'rest)))
- (cond ((<= lf (+ 1 req)) lf-1)
- ((<= lf (+ 1 req opt)) (if (> opt 0) lf lf-1))
- ((or (memq (last form) keys)
- (memq (car (take-right form 2)) keys)) =>
- (lambda (sl)
- (+ 2 req
- (if (> opt 0) (+ 1 opt) 0)
- (- (length keys) (length sl)))))
- (else (+ 1 req
- (if (> opt 0) (+ 1 opt) 0)
- (if (null? keys) 0 (+ 1 (length keys)))
- (if rest 2 0))))))))
-
-(define (arglst args kind)
- (let ((args (assq-ref args kind)))
- (cond ((or (not args) (null? args)) '())
- ((list? args) args)
- (else (list args)))))
+(define (signature id args)
+ (define (arglst kind)
+ (let ((args (assq-ref args kind)))
+ (cond ((or (not args) (null? args)) '())
+ ((list? args) args)
+ (else (list args)))))
+ `(,id
+ (required ,@(arglst 'required))
+ (optional ,@(arglst 'optional)
+ ,@(let ((rest (assq-ref args 'rest)))
+ (if rest (list "...") '())))
+ (key ,@(arglst 'keyword))))
(define (obj-args obj)
(cond ((not obj) #f)
- [nongnu] elpa/geiser-guile 63ebbc1 070/284: Using the new (system xref) interface., (continued)
- [nongnu] elpa/geiser-guile 63ebbc1 070/284: Using the new (system xref) interface., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 54484ab 075/284: Fixes for module names reading and evaluation result display., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile b14ac49 079/284: Guile: rewriting stack trace captures - not yet complete., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile b32aed7 077/284: module-children -> module-exports., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 19f55b0 097/284: New implementation registration mechanism, for the elisp side of things., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile c34d042 091/284: Yet another deklugdification: locals scanning moved to elisp., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile a329773 094/284: BSD relicensing: Guile code., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 694539c 101/284: Guile: bug fix: a macro-transformer is not a good arity info source., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 8f57a6a 034/284: Autodoc system revamped., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile f48e83f 065/284: Accept a list as Guile binary., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 4e1d945 088/284: Simpler, more correct and efficient autodoc implementation.,
Philip Kaludercic <=
- [nongnu] elpa/geiser-guile 6d3f98b 085/284: Guile: unbreaking evaluation., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 0e5a52b 090/284: Leftover removed., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 58ae3a1 100/284: Cosmetics., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 5807a76 105/284: Guile: adjustment to stack size display., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile a405f22 104/284: Guile: fix for file loading (we always compile them now)., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 134606d 102/284: Guile: Support for multiple arities in autodoc., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile c34995d 110/284: Guile: support for the REPL debugger, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 55c37c7 109/284: Guile: Minimal support for the new REPL debug mode., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile a9f26f1 115/284: Guile: slightly better compilation error regexps., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-guile 11c2d58 138/284: Guile: excluding anonymous module names from completion., Philip Kaludercic, 2021/08/01