diff options
author | rxi <rxi@users.noreply.github.com> | 2020-05-06 20:29:25 +0100 |
---|---|---|
committer | rxi <rxi@users.noreply.github.com> | 2020-05-06 20:29:25 +0100 |
commit | 953426062d06a950a42f58896c41ba5ff008ed98 (patch) | |
tree | 086ff4846758e6423a6ceeb0d8958d2cec0c9342 /plugins/lfautoinsert.lua | |
parent | 985747d1e31ff14f1066b40ab079a45f239e6117 (diff) | |
download | lite-xl-plugins-953426062d06a950a42f58896c41ba5ff008ed98.tar.gz lite-xl-plugins-953426062d06a950a42f58896c41ba5ff008ed98.zip |
More lfautoinsert tweaks
Diffstat (limited to 'plugins/lfautoinsert.lua')
-rw-r--r-- | plugins/lfautoinsert.lua | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/plugins/lfautoinsert.lua b/plugins/lfautoinsert.lua index 4104cb4..10b418f 100644 --- a/plugins/lfautoinsert.lua +++ b/plugins/lfautoinsert.lua @@ -4,19 +4,19 @@ local config = require "core.config" local keymap = require "core.keymap" config.autoinsert_map = { - ["{\n"] = "}", - ["%(\n"] = ")", - ["%f[[]%[\n"] = "]", - ["%[%[\n"] = "]]", - ["=\n"] = false, - [":\n"] = false, - ["^#if"] = "#endif", - ["^#else"] = "#endif", - ["%f[%w]do\n"] = "end", - ["%f[%w]then\n"] = "end", - ["%f[%w]else\n"] = "end", - ["%f[%w]repeat\n"] = "until", - ["%f[%w]function.*%)\n"] = "end", + ["{%s*\n"] = "}", + ["%(%s*\n"] = ")", + ["%f[[]%[%s*\n"] = "]", + ["%[%[%s*\n"] = "]]", + ["=%s*\n"] = false, + [":%s*\n"] = false, + ["^#if%s*\n"] = "#endif", + ["^#else%s*\n"] = "#endif", + ["%f[%w]do%s*\n"] = "end", + ["%f[%w]then%s*\n"] = "end", + ["%f[%w]else%s*\n"] = "end", + ["%f[%w]repeat%s*\n"] = "until", + ["%f[%w]function.*%)%s*\n"] = "end", } @@ -28,16 +28,17 @@ end command.add("core.docview", { ["autoinsert:newline"] = function() - local doc = core.active_view.doc - local line = doc:get_selection() - local text = doc.lines[line] - command.perform("doc:newline") + local doc = core.active_view.doc + local line, col = doc:get_selection() + local text = doc.lines[line - 1] + for ptn, close in pairs(config.autoinsert_map) do if text:find(ptn) then if close - and indent_size(doc, line + 2) <= indent_size(doc, line) + and col == #doc.lines[line] + and indent_size(doc, line + 1) <= indent_size(doc, line - 1) then command.perform("doc:newline") core.active_view:on_text_input(close) |