summaryrefslogtreecommitdiff
path: root/starling
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@vistahigherlearning.com>2020-10-04 22:24:34 -0400
committerDavid Thompson <dthompson@vistahigherlearning.com>2020-10-04 22:24:34 -0400
commit7590436a514f114f139498ec5860fdc755284764 (patch)
tree6cb356bdde123f206edd68ea1c5909bfc261ac2f /starling
parent4eb9e07935441ec74f3c399c89d20e3b1c87006c (diff)
minibuffer: Store commands in a hash table.
Diffstat (limited to 'starling')
-rw-r--r--starling/minibuffer.scm18
1 files changed, 9 insertions, 9 deletions
diff --git a/starling/minibuffer.scm b/starling/minibuffer.scm
index ed2761b..dd8edbe 100644
--- a/starling/minibuffer.scm
+++ b/starling/minibuffer.scm
@@ -37,7 +37,7 @@
open-minibuffer))
(define-class <minibuffer> (<scene-2d>)
- (commands #:accessor commands #:allocation #:class #:init-form '())
+ (commands #:accessor commands #:allocation #:class #:init-thunk make-hash-table)
(scene-mux #:getter scene-mux #:init-keyword #:scene-mux)
(overlay-scene #:getter overlay-scene #:init-keyword #:overlay-scene)
(user-text #:accessor user-text #:init-form ""))
@@ -46,9 +46,7 @@
(class-slot-ref <minibuffer> 'commands))
(define-method (add-minibuffer-command name thunk)
- (class-slot-set! <minibuffer> 'commands
- (cons (cons name thunk)
- (minibuffer-commands))))
+ (hash-set! (minibuffer-commands) name thunk))
(define-method (open-minibuffer scene-mux)
(let ((minibuffer (make <minibuffer>
@@ -68,7 +66,7 @@
(pop-scene (scene-mux minibuffer)))
(define-method (run-command (minibuffer <minibuffer>))
- (let ((thunk (assoc-ref (minibuffer-commands) (user-text minibuffer))))
+ (let ((thunk (hash-ref (minibuffer-commands) (user-text minibuffer))))
(when (procedure? thunk)
(close-minibuffer minibuffer)
(thunk))))
@@ -87,10 +85,12 @@
(let ((prefix (user-text minibuffer)))
;; Auto-complete if there is a single command name that starts
;; with the characters the user has already typed.
- (match (filter-map (match-lambda
- ((name . _)
- (and (string-prefix? prefix name) name)))
- (minibuffer-commands))
+ (match (hash-fold (lambda (key value prev)
+ (if (string-prefix? prefix key)
+ (cons key prev)
+ prev))
+ '()
+ (minibuffer-commands))
((name)
(modify-user-text minibuffer name))
(_ #f))))