From 72a07c59f3abddb9fe3fe6722a1c6691c79fdd5f Mon Sep 17 00:00:00 2001 From: Caleb Foust Date: Sun, 4 Aug 2024 08:56:10 +0800 Subject: [PATCH] fix: use table for actions so no repeats --- pkg/cy/boot/actions.janet | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/cy/boot/actions.janet b/pkg/cy/boot/actions.janet index a7cc168c..988b1d2f 100644 --- a/pkg/cy/boot/actions.janet +++ b/pkg/cy/boot/actions.janet @@ -1,18 +1,17 @@ -(def- actions @[]) +(def- actions @{}) (defmacro key/action - ````Register an action. Equivalent to the Janet built-in `(defn`), but requires a docstring. + ````Register an action. Equivalent to the Janet built-in `(defn)`, but requires a docstring. An action is just a Janet function that is registered to the cy server with a short human-readable string description. It provides a convenient method for making some functionality you use often more discoverable. -In a similar way to other modern applications, cy has a command palette (invoked by default with {{bind :root ctrl+a ctrl+p}}, see [`(action/command-palette) -`](/api.md#actioncommand-palette)) in which all registered actions will appear. +In a similar way to other modern applications, cy has a command palette (invoked by default with {{bind :root ctrl+a ctrl+p}}, see {{api action/command-palette}}) in which all registered actions will appear. ```` [name docstring & body] (def func-name (string name)) ~(upscope (defn ,name ,docstring [] ,;body) - (,array/push actions [,func-name ,docstring ,name]))) + (,put actions ,func-name [,docstring ,name]))) (defmacro key/bind-many ````Bind many bindings at once in the same scope. @@ -60,14 +59,14 @@ For example: (def bound-actions (map |(do - (def [name desc func] $) + (def [name [desc func]] $) (def sequence (as?-> binds x (find |(= func ($ :function)) x) (get x :sequence) (string/join x " ") (string " " x " "))) (tuple [desc name (string sequence)] func)) - actions)) + (pairs actions))) (as?-> bound-actions _ (input/find _