doc::??? updates

This commit is contained in:
vaclavt
2022-06-16 17:08:36 +02:00
parent 7acab5d229
commit e6cf7aa636
3 changed files with 1146 additions and 11 deletions

View File

@@ -43,6 +43,12 @@
nil
))
(defn doc::print-entry (entry)
(do (def call (doc::strip-backticks (second entry)))
(def desc (doc::strip-backticks (third entry)))
(print (term-red (first entry)) "-" (term-green (doc::strip-backticks (second entry))) "-" (third entry))
))
(defn doc::man (what)
(do (def man (filter (lambda (x) (= (first x) what)) doc::doc_entries))
(if man
@@ -75,29 +81,54 @@
(def sorted (quick-sort-by scores (lambda (a b) (< (first a) (first b)))))
(for e (take sorted 10)
(def entry (second e))
(def call (doc::strip-backticks (second entry)))
(def desc (doc::strip-backticks (third entry)))
(print (term-red (first entry)) "-" (term-green (doc::strip-backticks (second entry))) "-" (third entry))
)
(doc::print-entry (second e))))
(if (> (len sorted) 10) (print "..."))
))
(defn doc::section (what)
(do
(def entries '())
(for entry doc::doc_entries
; ("throw-exception" "`(throw-exception exp_desc)`" "Throws an exception with exp_desc describing what happened " "" "Exceptions"
; section matches
(if (= (string-downcase (fifth entry)) (string-downcase what))
(set! entries (push entries entry)))
)
(for e (quick-sort-by entries (lambda (a b) (> (string-cmp (first a) (first b)) 0)))
(doc::print-entry e))
))
(defn doc::all ()
(for e (quick-sort-by doc::doc_entries (lambda (a b) (> (string-cmp (first a) (first b)) 0)))
(doc::print-entry e))
)
(defn doc::appropos (which)
(doc::look which))
(defn doc::lookup (which)
(doc::look which))
;(defn doc::section (which)
; (print (term-red "implement me!")))
(defn doc::doc ()
(do
(print "Usage:")
(print "\t(doc::doc) - shows this help")
(print "\t(doc::man func) - func must be a string, ie (doc::man \"for\")")
(print "\t(doc::look str) - str must be a string, ie (doc::look \"length\")")
(print "\t(doc::lookup) - alias for doc::look")
(print "\t(doc::appropos) - alias for doc::look")
(print "\t(doc::all) - show short info about all functions")
(print "\t(doc::section sec) - show help for section, sec is string one of:")
(print "\t\t\t\t\"List manipulation\" \"Language\" \"System\"")
(print "\t\t\t\t\"String manipulation\" \"Date and time\" \"IO\" \"Regex\"")
(print "\t\t\t\t\"Type casting\" \"Threading\" \"Exceptions\"")
))
(def doc::doc_entries '()) ; must be here
; read doc into memory
(doc::read-doc-file "/usr/local/var/mlisp/Doc.md")
;;example
; (doc::man "first")
; (doc::look "string pad")
; (doc::look "list flat")