@@ -70,6 +70,13 @@ will execute `InsertTab`. To use `,`, `|` or `&` in an action (as an argument
7070to a command, for example), escape it with ` \ ` or wrap it in single or double
7171quotes.
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
7582You 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
105112cursor will be placed after it (note the space in the json that controls the
106113cursor 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
110159Only 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```
311360MousePress
361+ MouseDrag
362+ MouseRelease
312363MouseMultiCursor
313364```
314365
0 commit comments