Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add onAnyEvent callback #3244

Merged
merged 1 commit into from May 14, 2024
Merged

Add onAnyEvent callback #3244

merged 1 commit into from May 14, 2024

Conversation

dmaluka
Copy link
Collaborator

@dmaluka dmaluka commented Apr 11, 2024

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.

This may be a crazy idea, but maybe let's try it.

Some examples of such events that can be detected with onAnyEvent but not with other callbacks:

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
Comment on lines +75 to +77
* `onAnyEvent()`: runs when literally anything happens. It is useful for
detecting various changes of micro's state that cannot be detected
using other callbacks.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's worth mentioning, that the indication takes place before the update of the display is done.
Hopefully this doesn't lead to redraw-loops in the moment someone reacts to such an event, triggering an action, which then creates the next event and so on. 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the same situation as with other callbacks, right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of drawing...yes, I think so. Then it's common sense...
In case of possible cb-event-ping-pong the possible frequency could be higher, but it's up to the plugin (developer) to not shoot his self.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, this should never happen, assuming that any events received by DoEvent() can be only triggered by other goroutines (and thus cannot be triggered by lua callbacks, since they run in the main goroutine).

I've briefly looked through the code to check if this is actually true... Looks like there actually is a couple of cases when the main goroutine may send an event to itself:

  1. UpdateDiff() calls its callback which sends a redraw event regardless of its synchronous param value, e.g. even if this callback is running in the main goroutine.
  2. Terminal.Close() (which is called from the main goroutine e.g. when the user closes a termpane via Ctrl-q + Ctrl-q) may send a job event to the shell.Jobs channel.

The 1st case probably only causes unneeded redraws. Even if the drawChan gets overfull with those extra redraw events, it will not cause a deadlock, since screen.Redraw() doesn't block but simply drops events in such case.

But the 2nd case, it seems, may cause a deadlock (very unlikely to happen in practice though), if the main goroutine is closing many termpanes (100+ termpanes) fast enough, causing the shell.Jobs channel overfull and thus blocking forever.

Both these cases seem to be worth fixing (especially the 2nd one), even though they are rather minor, - just to feel safe and clean, by guaranteeing no ping-pong ever, no deadlocks ever, no redundant events.

@dmaluka dmaluka merged commit b70f0eb into zyedidia:master May 14, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants