Add more internal links and precisions on command arguments
This commit is contained in:
parent
0494574c36
commit
b01dfdb992
4 changed files with 53 additions and 30 deletions
|
|
@ -69,7 +69,7 @@ in Vim Mode `vim.zig`, `q` corresponds to (quit), the most famous one.
|
|||
|
||||
```zig
|
||||
pub fn q(_: *void, _: Ctx) Result {
|
||||
try cmd("quit", .{});
|
||||
try command.cmd("quit", .{});
|
||||
}
|
||||
pub const q_meta: Meta = .{ .description = "q (quit)" };
|
||||
```
|
||||
|
|
@ -122,14 +122,14 @@ pub fn select_to_char_left_helix(_: *void, ctx: Ctx) Result {
|
|||
|
||||
`goto_line` (in the case of vim and helix mode, you first type the
|
||||
number and then the action, `gg`) is a command that exemplifies
|
||||
receiving an integer parameter as stated in its meta:
|
||||
receiving an integer parameter. As stated in its meta:
|
||||
|
||||
```zig
|
||||
pub const goto_line_meta: Meta = .{ .arguments = &.{.integer} };
|
||||
```
|
||||
|
||||
and to actually receiving the integer parameter, `goto_line` will
|
||||
extract it like this:
|
||||
extract from the context like this:
|
||||
|
||||
```zig
|
||||
pub fn goto_line(self: *Self, ctx: Context) Result {
|
||||
|
|
@ -140,9 +140,17 @@ pub fn goto_line(self: *Self, ctx: Context) Result {
|
|||
```
|
||||
|
||||
To send a parameter to a command, make sure that the type is exactly
|
||||
the same when retrieving it. We will refer as encode and decode. Hence
|
||||
for our terminology to send an integer parameter to a command, we
|
||||
will encode it using `command.fmt` like in
|
||||
the same when retrieving it. We will refer as encode and decode when
|
||||
packing parameters in the context. To pack the `command.fmt` we will
|
||||
encode it like this, when invoking `goto_line`.
|
||||
|
||||
```zig
|
||||
var the_line: usize = 43;
|
||||
try command.cmd("goto_line", command.fmt(.{the_line - 1}));
|
||||
```
|
||||
|
||||
Or calling the command directly, if we have a reference to the object
|
||||
that holds the command.
|
||||
|
||||
```zig
|
||||
var the_line: usize = 43;
|
||||
|
|
@ -150,10 +158,12 @@ try ed.goto_line(command.fmt(.{the_line - 1}));
|
|||
```
|
||||
|
||||
It's possible to pass multiple parameters to commands, including arrays
|
||||
and json, they all will be packed in Command.Context.
|
||||
and json, packing all of them in Command.Context.
|
||||
|
||||
A deeper explanation of the rules about parameter passing is exposed in
|
||||
[inner data exchange](/docs/architecture/inner_data_exchange).
|
||||
[inner data exchange](/docs/architecture/inner_data_exchange), given
|
||||
that parameters can be sent not only to commands, but other broather
|
||||
use cases.
|
||||
|
||||
[]($section.id('next'))
|
||||
## Next steps
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue