From 7590436a514f114f139498ec5860fdc755284764 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sun, 4 Oct 2020 22:24:34 -0400 Subject: minibuffer: Store commands in a hash table. --- starling/minibuffer.scm | 18 +++++++++--------- 1 file 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 () - (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 'commands)) (define-method (add-minibuffer-command name thunk) - (class-slot-set! 'commands - (cons (cons name thunk) - (minibuffer-commands)))) + (hash-set! (minibuffer-commands) name thunk)) (define-method (open-minibuffer scene-mux) (let ((minibuffer (make @@ -68,7 +66,7 @@ (pop-scene (scene-mux minibuffer))) (define-method (run-command (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)))) -- cgit v1.2.3