orbitalquark / textadept

Textadept is a fast, minimalist, and remarkably extensible cross-platform text editor for programmers.
https://orbitalquark.github.io/textadept
MIT License
640 stars 38 forks source link

Add a TICK event for sockets #405

Closed GreedyTactician closed 1 year ago

GreedyTactician commented 1 year ago

Essentially, an event that calls a function periodically. I don't think there is any other events that did this (or a way to do it without events). I want this because I want to scan sockets. How could I scan sockets without a function that is always being called periodically? I can't, right?

I have already added this on my own version of textadept.

I only added it in the GTK version since that is what I use but I am sure there's a way to add it in QT and curses.

For GTK, I just had to add guint timeout_id = g_timeout_add(100, tick, NULL); where

gboolean tick(gpointer data) {
    emit("tick", -1);
    return G_SOURCE_CONTINUE;
}

Then just add the definition of tick in event.lua I suppose you can call the function faster than every 100ms. But 100ms seems to work for my use case.

I am aware there is pull requests to add features, but I have never used it and I am not sure you'd even approve of this addition. I am also not sure if 'issues' is the best place to post this or if I should write this in 'discussions'.

orbitalquark commented 1 year ago

I believe you are looking for the timeout() function? https://orbitalquark.github.io/textadept/api.html#timeout

Issues for requests is fine. Discussions is more for questions.

GreedyTactician commented 1 year ago

Ah yes! I will try it at home but timeout seems to be exactly what I needed. I do feel it would be more consistent to add it as an event and to give it a bit of a different name (timer, tick, ...) or somehow make the existence of this function easier to find in the documentation.

GreedyTactician commented 1 year ago

In hindsight, I feel like I should have been able to find the timeout function in the documentation even with a name slightly different than I expected. The gtk function is named timeout and I found that.I see that without a hardcorded set interval, you can't really make this an event.A minor improvement would maybe be to just add timeout as a sort of honorary mention in the events documentation.Otherwise, I think I just had to be more diligent 🙂