mirror of
https://github.com/zyedidia/micro
synced 2024-09-30 05:06:02 +00:00
Add onAnyEvent callback (#3244)
Implement a radical approach to improving abilities of plugins to detect and handle various changes of micro's state: add onAnyEvent callback which is called, literally, after any event. A plugin can use this callback to compare a state after the previous event and after the current event, and thus is able to catch various events that cannot be detected using other callbacks. Some examples of such events: - change of current working directory - switching cursor focus between a bufpane and the command bar - change of message text in the status bar
This commit is contained in:
parent
1f51d0b9e2
commit
b70f0eb113
|
@ -450,10 +450,6 @@ func DoEvent() {
|
|||
os.Exit(0)
|
||||
}
|
||||
|
||||
if event == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if e, ok := event.(*tcell.EventError); ok {
|
||||
log.Println("tcell event error: ", e.Error())
|
||||
|
||||
|
@ -473,6 +469,7 @@ func DoEvent() {
|
|||
return
|
||||
}
|
||||
|
||||
if event != nil {
|
||||
_, resize := event.(*tcell.EventResize)
|
||||
if resize {
|
||||
action.InfoBar.HandleEvent(event)
|
||||
|
@ -482,4 +479,10 @@ func DoEvent() {
|
|||
} else {
|
||||
action.Tabs.HandleEvent(event)
|
||||
}
|
||||
}
|
||||
|
||||
err := config.RunPluginFn("onAnyEvent")
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,6 +72,10 @@ which micro defines:
|
|||
|
||||
* `preRune(bufpane, rune)`: runs before the composed rune will be inserted
|
||||
|
||||
* `onAnyEvent()`: runs when literally anything happens. It is useful for
|
||||
detecting various changes of micro's state that cannot be detected
|
||||
using other callbacks.
|
||||
|
||||
For example a function which is run every time the user saves the buffer
|
||||
would be:
|
||||
|
||||
|
|
Loading…
Reference in a new issue