aboutsummaryrefslogtreecommitdiff
path: root/plugins/themeselect.lua
diff options
context:
space:
mode:
authorTakase <20792268+takase1121@users.noreply.github.com>2021-05-31 11:18:12 +0800
committerGitHub <noreply@github.com>2021-05-31 11:18:12 +0800
commit0d87d70140b8c318ca171330658d3a7cf00f5037 (patch)
treeeb333ce5d63f7f393b61ac544124be5398496d3a /plugins/themeselect.lua
parenta07e30be3827f9444f967ba633171ea8c90cd41e (diff)
parent5b9a3bd28d937d131da5821f075952df80c14040 (diff)
downloadlite-xl-plugins-0d87d70140b8c318ca171330658d3a7cf00f5037.tar.gz
lite-xl-plugins-0d87d70140b8c318ca171330658d3a7cf00f5037.zip
Merge branch 'master' into contextmenu
Diffstat (limited to 'plugins/themeselect.lua')
-rw-r--r--plugins/themeselect.lua48
1 files changed, 48 insertions, 0 deletions
diff --git a/plugins/themeselect.lua b/plugins/themeselect.lua
new file mode 100644
index 0000000..cafc1be
--- /dev/null
+++ b/plugins/themeselect.lua
@@ -0,0 +1,48 @@
+-- mod-version:1 -- lite-xl 1.16
+local core = require "core"
+
+-- Load a specific theme when the filename of an active document does match
+-- a pattern.
+
+-- usage:
+-- require("plugins.themeselect").add_pattern("%.md$", "summer")
+
+local theme_select = { }
+
+local saved_colors_module = "core.style"
+
+local themes_patterns = {
+}
+
+local reload_module = core.reload_module
+local set_visited = core.set_visited
+
+function core.reload_module(name)
+ if name:match("^colors%.") then
+ saved_colors_module = name
+ end
+ reload_module(name)
+end
+
+function core.set_visited(filename)
+ set_visited(filename)
+ for _, select in ipairs(themes_patterns) do
+ if filename:match(select.pattern) then
+ reload_module("colors." .. select.theme)
+ return
+ end
+ end
+ if saved_colors_module then
+ reload_module(saved_colors_module)
+ end
+end
+
+function theme_select.add_pattern(pattern, theme)
+ table.insert(themes_patterns, {pattern = pattern, theme = theme})
+end
+
+function theme_select.clear_patterns()
+ themes_patterns = {}
+end
+
+return theme_select