aboutsummaryrefslogtreecommitdiff
path: root/plugins/rainbowparen.lua
diff options
context:
space:
mode:
authorjgmdev <jgmdev@gmail.com>2022-03-13 04:36:41 -0400
committerjgmdev <jgmdev@gmail.com>2022-05-22 13:16:10 -0400
commit33d43f46caca1a8b4948c0582a3562f6ed05626d (patch)
treeda60bcad8bdf1c3e7a7d09478d89229bd1e465a0 /plugins/rainbowparen.lua
parent169c778d568fd44017861e0a7e6f310ccc6799c5 (diff)
downloadlite-xl-plugins-33d43f46caca1a8b4948c0582a3562f6ed05626d.tar.gz
lite-xl-plugins-33d43f46caca1a8b4948c0582a3562f6ed05626d.zip
rainbowparen: added ability to toggle.
Diffstat (limited to 'plugins/rainbowparen.lua')
-rw-r--r--plugins/rainbowparen.lua24
1 files changed, 23 insertions, 1 deletions
diff --git a/plugins/rainbowparen.lua b/plugins/rainbowparen.lua
index 6ddda13..0f63473 100644
--- a/plugins/rainbowparen.lua
+++ b/plugins/rainbowparen.lua
@@ -1,7 +1,15 @@
-- mod-version:3 --lite-xl 2.1
-local tokenizer = require "core.tokenizer"
+local core = require "core"
local style = require "core.style"
+local config = require "core.config"
local common = require "core.common"
+local command = require "core.command"
+local tokenizer = require "core.tokenizer"
+local Highlighter = require "core.doc.highlighter"
+
+config.plugins.rainbowparen = common.merge({
+ enable = true
+}, config.plugins.rainbowparen)
local tokenize = tokenizer.tokenize
local closers = {
@@ -13,6 +21,9 @@ local function parenstyle(parenstack)
return "paren" .. ((#parenstack % 5) + 1)
end
function tokenizer.tokenize(syntax, text, state)
+ if not config.plugins.rainbowparen.enable then
+ return tokenize(syntax, text, state)
+ end
state = state or {}
local res, istate = tokenize(syntax, text, state.istate)
local parenstack = state.parenstack or ""
@@ -57,3 +68,14 @@ style.syntax.paren2 = style.syntax.paren2 or { common.color "#fcb053"}
style.syntax.paren3 = style.syntax.paren3 or { common.color "#fcd476"}
style.syntax.paren4 = style.syntax.paren4 or { common.color "#52dab2"}
style.syntax.paren5 = style.syntax.paren5 or { common.color "#5a98cf"}
+
+
+command.add(nil, {
+ ["rainbow-parentheses:toggle"] = function()
+ config.plugins.rainbowparen.enable = not config.plugins.rainbowparen.enable
+ for _, doc in ipairs(core.docs) do
+ doc.highlighter = Highlighter(doc)
+ doc:reset_syntax()
+ end
+ end
+})