micro icon indicating copy to clipboard operation
micro copied to clipboard

dynamic reload?

Open Dreuzz opened this issue 7 months ago • 9 comments

is there a way for micro to reload dynamically or reload it via the terminal while a session is open?

I want to use matugen to dynamically change the theme but micro doesnt reload dynamically and I have to use the reload command :/

https://github.com/user-attachments/assets/8f0de403-eef1-4940-90a3-e97f3e7f504c

Dreuzz avatar May 05 '25 20:05 Dreuzz

This essentially boils down to a question how to send a command to micro remotely, via a socket or something. I don't think there is such a possibility, unfortunately.

dmaluka avatar May 05 '25 20:05 dmaluka

My knowledge of Micro is about the same as my knowledge of ricing—almost zero. Still, I had an idea you could use as a last resort.

If there's no direct way to send a command to Micro, as a final option, you might be able to make Micro reload itself—maybe through an infinite reload loop or by using a file as a socket.

I’m not sure how to implement this properly, but I had an idea. Once this https://github.com/zyedidia/micro/pull/3733. gets merged , you could create an overlay that reloads the config continuously or read the content of a file and reload with some condition. It’s definitely not a clean solution, but I tested it and it seems to work.

cutelisp avatar May 08 '25 13:05 cutelisp

At least with a Lua plugin someone could implement the necessary interface and access whatever micro exports. It is limited what micro exports, but it is much more than nothing.

JoeKar avatar May 08 '25 18:05 JoeKar

Once this #3733. gets merged , you could create an overlay that reloads the config continuously or read the content of a file and reload with some condition.

You mean, a plugin continuously calling ReloadCmd() in a busy loop? I'm not sure what overlays have to do with that, but anyway that would be a really bad idea (I hope I don't need to explain why).

Or you could do that at regular time intervals (I think you can already do that, using a timer, with After()), that would be not as bad, but still feels quite silly.

A better approach would be to use something like https://pkg.go.dev/github.com/fsnotify/fsnotify...

dmaluka avatar May 08 '25 20:05 dmaluka

You mean, a plugin continuously calling ReloadCmd() in a busy loop? I'm not sure what overlays have to do with that, but anyway that would be a really bad idea (I hope I don't need to explain why).

kinda, callingconfig.Reload()(maybe not in every iteration) I've mention overlays, because I think a plugin with a busy loop would freeze micro, right?

Or you could do that at regular time intervals (I think you can already do that, using a timer, with After()), that would be not as bad, but still feels quite silly.

Could you provide a short snippet or describe a bit more that approach by any chance? It might be silly but I got curious 😆

cutelisp avatar May 09 '25 01:05 cutelisp

Could you provide a short snippet or describe a bit more that approach by any chance?

local time = import("time")
local interval = time.ParseDuration("1s")

local function periodicReload()
    config.Reload()
    micro.After(interval, periodicReload)
end

function init()
    micro.After(interval, periodicReload)
end

BTW please ignore my above suggestion to use ReloadCmd(), it does exactly what the reload command does, so it would not just reload config files but also reinitialize all plugins, including your plugin which calls it, which is probably a bad idea, so you should use config.Reload() which just reloads config files (and it exists specifically for use by plugins).

dmaluka avatar May 09 '25 07:05 dmaluka

BTW please ignore my above suggestion to use ReloadCmd(), it does exactly what the reload command does, so it would not just reload config files but also reinitialize all plugins, including your plugin which calls it, which is probably a bad idea, so you should use config.Reload() which just reloads config files (and it exists specifically for use by plugins).

Ty, that's definitely a better approach, although I've noticed whenconfig.Reload() is called my other plugins don't really work.

cutelisp avatar May 09 '25 17:05 cutelisp

whenconfig.Reload() is called my other plugins don't really work.

Sounds like a bug.

dmaluka avatar May 09 '25 21:05 dmaluka

You could define SIGUSR1 to reload the config. That is what kitty does. I don't know however if the signals are taken yet however.

SLUCHABLUB avatar Aug 18 '25 15:08 SLUCHABLUB