Jwno commands are code actions associated with a name (usually a Janet keyword). They can be bound to a certain key spec, and will be triggered when the corresponding keys are pressed. You can also call them directly in your config file or in the REPL.
Some Commands can accept arguments, but the syntaxes to pass arguments to them differ, depending on how the commands are called.
Binding a Command to a Key Spec
Just call the :define-key
method from a keymap object, and pass the command's name with its arguments in a tuple:
(def keymap (:new-keymap (in jwno/context :key-manager))) # Create a new keymap
(:define-key keymap "Win + ," [:split-frame :horizontal 2]
"Split current frame horizontally")
Here :split-frame
is the name of our command. :horizontal
and 2
are its arguments. If a command takes no argument, you can pass only the name, without putting it in a tuple:
(:define-key keymap "Win + Shift + Q" :quit
"Tell Jwno to exit")
The code above is equivalent to:
(:define-key keymap "Win + Shift + Q" [:quit]
"Tell Jwno to exit")
Calling a Command Directly
To directly call a command in your Janet code, use the :call-command
method from the command manager object, and pass the command's name and its arguments separately. Take the :split-frame
command from the previous section as an example again:
(:call-command (in jwno/context :command-manager)
:split-frame :horizontal 2)
Defining a Command
You can add a custom command like this:
(:add-command (in jwno/context :command-manager) :brew-coffee
(fn [strength extraction amount]
# Do the actual brewing here
))
Here :brew-coffee
is the name of our new command. strength
, extraction
and amount
are the parameters our command can accept. This will overwrite the command registered under the same name, if there's any.
When the command is not needed anymore, you can remove it by passing its name to the :remove-command
method from the command manager object:
(:remove-command (in jwno/context :command-manager) :brew-coffee)
Disclaimer: Jwno can not brew your coffee yet. Maybe we can have that in a future version.