Skip to content

config: hot-reload config files when changed on disk#4056

Closed
KonTy wants to merge 1 commit intomicro-editor:masterfrom
KonTy:config-watch
Closed

config: hot-reload config files when changed on disk#4056
KonTy wants to merge 1 commit intomicro-editor:masterfrom
KonTy:config-watch

Conversation

@KonTy
Copy link
Copy Markdown

@KonTy KonTy commented Mar 26, 2026

Add `StartConfigWatcher` in `internal/config/watch.go`. It accepts a slice of `WatchedFile` values — each with a `Path` func and an `OnChange` callback — and polls them once per second. When a file is modified or the resolved path changes, the callback fires on a background goroutine. Callers dispatch to the main thread via `timerChan`.

Wire up three watchers in `cmd/micro/micro.go`:

File Action
`colorschemes/.micro` `InitColorscheme` + `Redraw`
`settings.json` `ReadSettings` + `InitGlobalSettings` + `Redraw`
`bindings.json` `InitBindings`

Why: Any external tool (theme managers, dotfile syncing, live config editors) can now update micro's config files while the editor is running and have the changes applied immediately — no restart required. The `Path` func is re-evaluated each tick, so switching colorschemes mid-session is also handled correctly.

Threading: all callbacks run on a background goroutine and post to `timerChan`, keeping every UI mutation on the main thread.

No new dependencies.

Add StartConfigWatcher in internal/config/watch.go. It takes a slice of
WatchedFile values, each with a Path func and an OnChange callback, and
polls them once per second. When a file is modified or the resolved path
changes the callback fires. Callbacks run on a background goroutine —
callers dispatch to the main thread via timerChan.

Wire up three watchers in cmd/micro/micro.go:
- colorschemes/<name>.micro  → InitColorscheme + Redraw
- settings.json              → ReadSettings + InitGlobalSettings + Redraw
- bindings.json              → InitBindings

This lets any external tool (theme managers, dotfile syncing, etc.)
update micro's config files while the editor is open and have the
changes applied immediately without a restart. No new dependencies.
@JoeKar
Copy link
Copy Markdown
Member

JoeKar commented Mar 26, 2026

AI slop and same as #4054 and #4053.
What a waste of time...

@JoeKar JoeKar closed this Mar 26, 2026
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.

2 participants