Skip to content

Commit e923640

Browse files
committed
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
1 parent 73066fb commit e923640

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

cmd/micro/micro.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,6 @@ func main() {
374374
action.InitBindings()
375375
action.InitCommands()
376376

377-
err = config.InitColorscheme()
378-
if err != nil {
379-
screen.TermMessage(err)
380-
}
381-
382377
err = config.RunPluginFn("preinit")
383378
if err != nil {
384379
screen.TermMessage(err)
@@ -407,6 +402,11 @@ func main() {
407402
screen.TermMessage(err)
408403
}
409404

405+
err = config.InitColorscheme()
406+
if err != nil {
407+
screen.TermMessage(err)
408+
}
409+
410410
if clipErr != nil {
411411
log.Println(clipErr, " or change 'clipboard' option")
412412
}

0 commit comments

Comments
 (0)