commander-s/scheme/plugins.scm

41 lines
1.1 KiB
Scheme

(define *command-plugins* '())
(define *view-plugins* '())
(define *command-completions*
(make-empty-completion-set))
(define (command-plugin-list)
*command-plugins*)
(define (view-plugin-list)
*view-plugins*)
(define (command-completions)
*command-completions*)
(define-record-type view-plugin :view-plugin
(make-view-plugin constructor type-predicate)
view-plugin?
(constructor view-plugin-constructor)
(type-predicate view-plugin-type-predicate))
(define-record-type command-plugin :command-plugin
(make-command-plugin command completer evaluater)
command-plugin?
(command command-plugin-command)
(completer command-plugin-completer)
(evaluater command-plugin-evaluater))
(define (register-plugin! plugin)
(cond
((command-plugin? plugin)
(set! *command-plugins* (cons plugin *command-plugins*))
(set! *command-completions*
(adjoin-completion-set *command-completions*
(command-plugin-command plugin))))
((view-plugin? plugin)
(set! *view-plugins* (cons plugin *view-plugins*)))
(error "unknown plugin type" plugin)))