-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcat_colorschemes.lua
107 lines (90 loc) · 3.8 KB
/
concat_colorschemes.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
VERSION = "0.0.1"
--BUG: The plugin does not let you change `settings.json` if the plugin is active.
--or at least this happened to me (I did not investigate further).
--Remove it and use ENABLE_FOR_MICRO.sh to re-enable it again.
-- TODO: add your Colorschemes here. Example:
-- local extraColorSchemes = { "your-colorscheme-here", "another-one" }
local extraColorSchemes = {}
local micro = import("micro")
local config = import("micro/config")
local plugName = "ColorSchemeConcat"
local concatColorSchemeName = "colorscheme-concat"
local internal = plugName..".INTERNAL_READONLY"
local function log(...)
-- micro.Log("[" .. plugName .. "]", unpack(arg))
end
log("config.GetGlobalOption(internal)", config.GetGlobalOption(internal))
log("select default repl internal",
select(1, (config.GetGlobalOption("colorscheme"):gsub("default", config.GetGlobalOption(internal)))))
config.SetGlobalOption(
"colorscheme",
select(1, (config.GetGlobalOption("colorscheme"):gsub("default", config.GetGlobalOption(internal))))
)
local userColorScheme = nil
local hasExtra = false
---@param table<string> Colorschemes names to concat to your actual colorscheme.
local function ColorSchemeConcat(colorSchemes)
log("ColorSchemeConcat::entry")
local linesCS = {}
local fmt = "include \"%s\""
if not userColorScheme then -- avoid overwrite it (should not happen but...)
userColorScheme = config.GetGlobalOption("colorscheme")
end
log("ColorSchemeConcat::userColorScheme", userColorScheme)
table.insert(linesCS, fmt:format(userColorScheme))
for _, cs in ipairs(colorSchemes) do table.insert(linesCS, fmt:format(cs)) end
local concatColorScheme = table.concat(linesCS, "\n")
log("ColorSchemeConcat::concatColorScheme", concatColorScheme)
config.AddRuntimeFileFromMemory(
config.RTColorscheme, concatColorSchemeName, concatColorScheme
)
config.SetGlobalOption("colorscheme", concatColorSchemeName)
log("ColorSchemeConcat::exit")
end
function postinit()
--If empty dont use the plugin
if not next(extraColorSchemes) then
micro.Log("["..plugName.."::WARN] extraColorSchemes is empty.")
micro.Log("["..plugName.."::INFO] Leaving the user colorscheme...")
return
end
hasExtra = true
log("preinit::entry")
if not userColorScheme then
userColorScheme = config.GetGlobalOption("colorscheme")
config.SetGlobalOptionNative(internal, userColorScheme)
log("preinit::userColorScheme set to", userColorScheme)
end
ColorSchemeConcat(extraColorSchemes)
log("preinit::exit")
end
function deinit()
if not hasExtra then return end
log("deinit::entry")
micro.Log("ColorSchemeConcat::deinit::userColorScheme", userColorScheme)
if config.GetGlobalOption("colorscheme") == concatColorSchemeName then
config.SetGlobalOption("colorscheme", userColorScheme)
end
log("deinit::config.GetGlobalOption(\"colorscheme\")", config.GetGlobalOption("colorscheme"))
userColorScheme = nil
log("deinit::exit")
end
function preQuit(_)
if not hasExtra then return true end
log("preQuit::entry")
if #micro.Tabs().List == 1 and #micro.CurTab().Panes == 1 then
log("preQuit::reset_colorscheme")
-- if config.GetGlobalOption("colorscheme") == userColorScheme.."CONCAT" then
if config.GetGlobalOption("colorscheme") == concatColorSchemeName then
log("preQuit::replacing_concatColorScheme")
config.SetGlobalOption("colorscheme", userColorScheme)
else
log("preQuit::colorscheme was changed, ignore...")
log("userColorScheme, concatColorSchemeName",
userColorScheme, concatColorSchemeName)
-- userColorScheme, userColorScheme.."CONCAT")
end
end
log("preQuit::exit")
return true
end