From e923640b37d0d27e53c73e191ea755cc3ddcbfdd Mon Sep 17 00:00:00 2001 From: Dmytro Maluka Date: Sun, 25 May 2025 16:48:03 +0200 Subject: [PATCH] Move loading colorschemes after initializing plugins Micro "allows" plugins to register colorschemes via config.AddRuntimeFile(). However, that has never really worked, since InitColorscheme() is called earlier than plugins init() or even preinit() callbacks are called. To work around that, plugins that use it (e.g. nord-tc [1]) are using a tricky hack: call config.AddRuntimeFile() not in init() or preinit() but directly in Lua's global scope, so that it is called earlier, when the plugin's Lua code is loaded. This hack is not guaranteed to work, and works by chance. Furthermore, it only works when starting micro, and doesn't work after the `reload` command. (The reason it doesn't work is that PluginAddRuntimeFile() calls FindPlugin() which calls IsLoaded() which returns false, since, well, the plugin is not loaded, it is only being loaded. And the reason why it works when starting micro is that in that case IsLoaded() confusingly returns true, since GlobalSettings[p.Name] has not been set yet.) So move InitColorscheme() call after calling plugins init/preinit/ postinit callbacks, to let plugins successfully register colorschemes in any of those callbacks instead of using the aforementioned hack. [1] https://github.com/KiranWells/micro-nord-tc-colors --- cmd/micro/micro.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index e43073b4..7756d588 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -374,11 +374,6 @@ func main() { action.InitBindings() action.InitCommands() - err = config.InitColorscheme() - if err != nil { - screen.TermMessage(err) - } - err = config.RunPluginFn("preinit") if err != nil { screen.TermMessage(err) @@ -407,6 +402,11 @@ func main() { screen.TermMessage(err) } + err = config.InitColorscheme() + if err != nil { + screen.TermMessage(err) + } + if clipErr != nil { log.Println(clipErr, " or change 'clipboard' option") }