diff options
author | jgmdev <jgmdev@gmail.com> | 2022-05-24 19:29:50 -0400 |
---|---|---|
committer | jgmdev <jgmdev@gmail.com> | 2022-05-24 19:29:50 -0400 |
commit | 35e947d1933613bb0b5a1488bf0fa4587f98ef7d (patch) | |
tree | 07d2515f44db03b1e865f6aef6adfd12b118890b /plugins/rainbowparen.lua | |
parent | c1f3671e2a8defbc67d1e77c72d5866f2825cdb5 (diff) | |
download | lite-xl-plugins-35e947d1933613bb0b5a1488bf0fa4587f98ef7d.tar.gz lite-xl-plugins-35e947d1933613bb0b5a1488bf0fa4587f98ef7d.zip |
added config_spec and other plugin compatibility fixes.
Diffstat (limited to 'plugins/rainbowparen.lua')
-rw-r--r-- | plugins/rainbowparen.lua | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/plugins/rainbowparen.lua b/plugins/rainbowparen.lua index 0f63473..1df56ed 100644 --- a/plugins/rainbowparen.lua +++ b/plugins/rainbowparen.lua @@ -11,15 +11,24 @@ config.plugins.rainbowparen = common.merge({ enable = true }, config.plugins.rainbowparen) +style.syntax.paren_unbalanced = style.syntax.paren_unbalanced or { common.color "#DC0408" } +style.syntax.paren1 = style.syntax.paren1 or { common.color "#FC6F71"} +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"} + local tokenize = tokenizer.tokenize local closers = { ["("] = ")", ["["] = "]", ["{"] = "}" } + 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) @@ -62,20 +71,31 @@ function tokenizer.tokenize(syntax, text, state) return newres, { parenstack = parenstack, istate = istate } end -style.syntax.paren_unbalanced = style.syntax.paren_unbalanced or { common.color "#DC0408" } -style.syntax.paren1 = style.syntax.paren1 or { common.color "#FC6F71"} -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"} +local function toggle_rainbowparen(enabled) + config.plugins.rainbowparen.enable = enabled + for _, doc in ipairs(core.docs) do + doc.highlighter = Highlighter(doc) + doc:reset_syntax() + end +end +-- The config specification used by the settings gui +config.plugins.rainbowparen.config_spec = { + name = "Rainbow Parentheses", + { + label = "Enable", + description = "Activates rainbow parenthesis coloring by default.", + path = "enable", + type = "toggle", + default = true, + on_apply = function(enabled) + toggle_rainbowparen(enabled) + end + } +} 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 + toggle_rainbowparen(not config.plugins.rainbowparen.enable) end }) |