Skip to content

Commit 7492195

Browse files
authored
Merge pull request zyedidia#3799 from dmaluka/doc-update
Some documentation improvements
2 parents 3a7705a + 0694cd2 commit 7492195

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed

runtime/help/keybindings.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ will execute `InsertTab`. To use `,`, `|` or `&` in an action (as an argument
7070
to a command, for example), escape it with `\` or wrap it in single or double
7171
quotes.
7272

73+
If the action has an `onAction` lua callback, for example `onAutocomplete` (see
74+
`> help plugins`), then the action is only considered successful if the action
75+
itself succeeded *and* the callback returned true. If there are multiple
76+
`onAction` callbacks for this action, registered by multiple plugins, then the
77+
action is only considered successful if the action itself succeeded and all the
78+
callbacks returned true.
79+
7380
## Binding commands
7481

7582
You can also bind a key to execute a command in command mode (see
@@ -105,6 +112,48 @@ Now when you press `Ctrl-g`, `help` will appear in the command bar and your
105112
cursor will be placed after it (note the space in the json that controls the
106113
cursor placement).
107114

115+
## Binding Lua functions
116+
117+
You can also bind a key to a Lua function provided by a plugin, or by your own
118+
`~/.config/micro/init.lua`. For example:
119+
120+
```json
121+
{
122+
"Alt-q": "lua:foo.bar"
123+
}
124+
```
125+
126+
where `foo` is the name of the plugin and `bar` is the name of the lua function
127+
in it, e.g.:
128+
129+
```lua
130+
local micro = import("micro")
131+
132+
function bar(bp)
133+
micro.InfoBar():Message("Bar action triggered")
134+
return true
135+
end
136+
```
137+
138+
See `> help plugins` for more informations on how to write lua functions.
139+
140+
For `~/.config/micro/init.lua` the plugin name is `initlua` (so the keybinding
141+
in this example would be `"Alt-q": "lua:initlua.bar"`).
142+
143+
The currently active bufpane is passed to the lua function as the argument. If
144+
the key is a mouse button, e.g. `MouseLeft` or `MouseWheelUp`, the mouse event
145+
info is passed to the lua function as the second argument, of type
146+
`*tcell.EventMouse`. See https://pkg.go.dev/github.com/micro-editor/tcell/v2#EventMouse
147+
for the description of this type and its methods.
148+
149+
The return value of the lua function defines whether the action has succeeded.
150+
This is used when chaining lua functions with other actions. They can be chained
151+
the same way as regular actions as described above, for example:
152+
153+
```
154+
"Alt-q": "lua:initlua.bar|Quit"
155+
```
156+
108157
## Binding raw escape sequences
109158

110159
Only read this section if you are interested in binding keys that aren't on the
@@ -309,6 +358,8 @@ You can also bind some mouse actions (these must be bound to mouse buttons)
309358

310359
```
311360
MousePress
361+
MouseDrag
362+
MouseRelease
312363
MouseMultiCursor
313364
```
314365

runtime/help/plugins.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,24 @@ that micro defines:
7171

7272
* `onAction(bufpane)`: runs when `Action` is triggered by the user, where
7373
`Action` is a bindable action (see `> help keybindings`). A bufpane
74-
is passed as input and the function should return a boolean defining
75-
whether the view should be relocated after this action is performed.
74+
is passed as input. The function should return a boolean defining
75+
whether the action was successful, which is used when the action is
76+
chained with other actions (see `> help keybindings`) to determine whether
77+
the next actions in the chain should be executed or not.
78+
79+
If the action is a mouse action, e.g. `MousePress`, the mouse event info
80+
is passed to the callback as an extra argument of type `*tcell.EventMouse`.
81+
See https://pkg.go.dev/github.com/micro-editor/tcell/v2#EventMouse for the
82+
description of this type and its methods.
7683

7784
* `preAction(bufpane)`: runs immediately before `Action` is triggered
7885
by the user. Returns a boolean which defines whether the action should
7986
be canceled.
8087

88+
Similarly to `onAction`, if the action is a mouse action, the mouse event
89+
info is passed to the callback as an extra argument of type
90+
`*tcell.EventMouse`.
91+
8192
* `onRune(bufpane, rune)`: runs when the composed rune has been inserted
8293

8394
* `preRune(bufpane, rune)`: runs before the composed rune will be inserted
@@ -101,9 +112,6 @@ within. This is almost always the current bufpane.
101112

102113
All available actions are listed in the keybindings section of the help.
103114

104-
These functions should also return a boolean specifying whether the bufpane
105-
should be relocated to the cursor or not after the action is complete.
106-
107115
## Accessing micro functions
108116

109117
Some of micro's internal information is exposed in the form of packages, which

0 commit comments

Comments
 (0)