commander-s/scheme/scheme-commands.scm

45 lines
1.4 KiB
Scheme
Raw Normal View History

(define command-prefix #\,)
(define (split-scheme-command-line command-line)
(let ((tokens (string-tokenize command-line)))
(values (string-drop (car tokens) 1)
(cdr tokens))))
(define (scheme-command-line? command-line)
(char=? (string-ref (string-trim command-line) 0)
command-prefix))
(define (eval-scheme-command command args)
(case (string->symbol command)
((in)
(set-evaluation-package! (string->symbol (car args)))
(string-append "moved to package " (car args)))
((open)
(package-open!
(evaluation-environment)
(lambda ()
(environment-ref
(config-package) (string->symbol (car args)))))
(string-append "opened package " (car args)))
((user)
(set-evaluation-package! 'nuit-eval)
"moved to package nuit-eval")
((inspect)
(if (null? args)
",inspect requires an argument"
(make-inspection-object
(eval-string (string-join args)))))
((reload-package)
(if (null? args)
",reload-package requires an argument"
(let ((s (get-structure (string->symbol (car args)))))
(if (not (package-unstable? (structure-package s)))
"read-only structure"
(begin
(set-package-loaded?! (structure-package s) #f)
(ensure-loaded s)
"reloaded package")))))
((exit)
(exit))
(else (error "unknwon scheme command" command))))