Skip to content

Commit b406da5

Browse files
committed
CHANGED: bindings groups documentation
1 parent 8db0343 commit b406da5

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

documentation/mdbook_asciio/src/config/binding_format.md

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,72 @@ register_action_handlers
118118
'group_other_group_name' => GROUP ( ...), # note that 'group_' is needed in the declaration of groups referred to by USE_GROUP
119119
```
120120

121-
#### Macros
121+
### Navigating groups programatically
122+
123+
There are two possibilities:
124+
125+
- run_actions
126+
- run_actions_by name
127+
128+
*run_actions* runs actions in the current binding (it is used by *Asciio* to handle keyboard events).
129+
130+
*run_actions_by_name* executes one of more named functions (with optional arguments); the functions are registered in the default config.
131+
132+
*Asciio* looks up keyboard events and run the correxponding function in the current binding group.
133+
134+
Groups are also registered functions, functions that manipulates the current binding group.
135+
136+
We can programmatically manipulate the current bindings but it's much easier to define a group of bindings that we can make the active binding group; that's exactly what GROUP does.
137+
138+
To change the current keyboard bindings, we just need to run the right GROUP.
139+
140+
```perl
141+
$self->run_actions_by_name("the GROUP name") ;
142+
```
143+
144+
That's available anywhere but the right way to do it is in the config so we get a keyboard driven flow rather than a code driven flow with if-then-else.
145+
146+
The configuration below is to get in group 'x' from group 'Insert ->' and back.
147+
148+
Two solutions are presented, the difference is explained below.
149+
150+
Note: the normal behavior when exiting a GROUP, is to reset to the default keyboard bindings.
151+
152+
```perl
153+
154+
'Insert ->' => GROUP
155+
(
156+
SHORTCUTS => '000-i',
157+
'X ->' => ['000-x', USE_GROUP('x')] ,
158+
),
159+
160+
'group_x' => GROUP
161+
(
162+
SHORTCUTS => 'group_x',
163+
ESCAPE_KEYS => '000-Escape',
164+
165+
# solution 1
166+
ESCAPE_GROUP => sub { $_[0]->run_actions_by_name("Insert ->") ;},
167+
168+
#solution 2
169+
'return to Insert' => ['000-Escape', sub{ $_[0]->run_actions_by_name("Insert ->") ; }, undef , {HIDE => 1}],
170+
),
171+
```
172+
173+
174+
- if you decide to use *solution 1*, the code for *solution 2* is not needed
175+
- if you decide to use *solution 2*, the code for *solution 1* is not needed
176+
- you can use *solution 1* and *solution 2* together but in this case there is no gain
177+
178+
Difference:
179+
- *solution 1* will change the current bindings but the bindings help
180+
- *solution 2* will change the current bindings and display the bindings help
181+
182+
Note:
183+
- we stop capturing keyboard input to GROUP(X) bindings because both solutions use '000-Escape'.
184+
- we're not forced to jump "back" to the previous group, we could jump anywhere, that's what USE_GROUP does.
185+
186+
### Macros
122187

123188
Macros allows ***Single Action Definition*** to run multiple commands.
124189

0 commit comments

Comments
 (0)