Binding Field define
The define
field accepts an arbitrary set of key-value pairs that can be referenced inside an expression or a call to "runCommands".
Examples
A common command pattern in Larkin is to allow multiple lines to be selected using a count followed by the operation to perfrom on those lines. The line selection is defined as follows
toml
[[define.selectLinesDown]]
command = "selection-utilities.shrinkToActive"
[[define.selectLinesDown]]
whenComputed = "count"
command = "cursorMove"
args = { to = "down", by = "wrappedLine", select = true }
computedArgs = { value = "count" }
[[define.selectLinesDown]]
command = "expandLineSelection"
And use of this definition is as follows
toml
[[bind]]
defaults = "edit.action.basic"
key = "c"
when = "!editorHasSelection && master-key.count > 1"
command = "runCommands"
args.commands = [
{ defined = "selectLinesDown" },
"deleteRight",
"editor.action.insertLineBefore",
"master-key.enterInsert",
]
To handle symmetric insert of brackets, Larkin uses the following definition
toml
[define.braces]
"{".before = "{"
"{".after = "}"
"}".before = "{"
"}".after = "}"
"[".before = "["
"[".after = "]"
"]".before = "["
"]".after = "]"
"(".before = "("
"(".after = ")"
")".before = "("
")".after = ")"
"<".before = "<"
"<".after = ">"
">".before = "<"
">".after = ">"
This is then applied when handling symmetric typing using the onType
field of [[mode]]
.
toml
[[mode]]
name = "syminsert"
highlight = "Highlight"
cursorShape = "BlockOutline"
[[mode.onType]]
command = "selection-utilities.insertAround"
computedArgs.before = "braces[captured].before || captured"
computedArgs.after = "braces[captured].after || captured"
args.followCursor = true