diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/datetimestamps.lua | 8 | ||||
-rw-r--r-- | plugins/eval.lua | 20 | ||||
-rw-r--r-- | plugins/exec.lua | 26 | ||||
-rw-r--r-- | plugins/regexreplacepreview.lua | 11 | ||||
-rw-r--r-- | plugins/select_colorscheme.lua | 4 | ||||
-rw-r--r-- | plugins/spellcheck.lua | 23 |
6 files changed, 53 insertions, 39 deletions
diff --git a/plugins/datetimestamps.lua b/plugins/datetimestamps.lua index 28b07c8..f16af83 100644 --- a/plugins/datetimestamps.lua +++ b/plugins/datetimestamps.lua @@ -77,9 +77,11 @@ command.add("core.docview", { ["datetimestamps:insert-timestamp"] = timestamp, ["datetimestamps:insert-datetimestamp"] = datetimestamp, ["datetimestamps:insert-custom"] = function() - core.command_view:enter("Date format eg: %H:%M:%S", function(cmd) - core.active_view.doc:text_input(os.date(cmd) or "") - end) + core.command_view:enter("Date format eg: %H:%M:%S", { + submit = function(cmd) + core.active_view.doc:text_input(os.date(cmd) or "") + end + }) end, }) diff --git a/plugins/eval.lua b/plugins/eval.lua index 36cc714..c2eb19e 100644 --- a/plugins/eval.lua +++ b/plugins/eval.lua @@ -13,16 +13,20 @@ end command.add("core.docview", { ["eval:insert"] = function() - core.command_view:enter("Evaluate And Insert Result", function(cmd) - core.active_view.doc:text_input(eval(cmd)) - end) + core.command_view:enter("Evaluate And Insert Result", { + submit = function(cmd) + core.active_view.doc:text_input(eval(cmd)) + end + }) end, ["eval:replace"] = function() - core.command_view:enter("Evaluate And Replace With Result", function(cmd) - core.active_view.doc:replace(function(str) - return eval(cmd) - end) - end) + core.command_view:enter("Evaluate And Replace With Result", { + submit = function(cmd) + core.active_view.doc:replace(function(str) + return eval(cmd) + end) + end + }) end, }) diff --git a/plugins/exec.lua b/plugins/exec.lua index 29c8e85..b8f61c5 100644 --- a/plugins/exec.lua +++ b/plugins/exec.lua @@ -28,19 +28,23 @@ end command.add("core.docview", { ["exec:insert"] = function() - core.command_view:enter("Insert Result Of Command", function(cmd) - core.active_view.doc:text_input(exec(cmd)) - end) + core.command_view:enter("Insert Result Of Command", { + submit = function(cmd) + core.active_view.doc:text_input(exec(cmd)) + end + }) end, ["exec:replace"] = function() - core.command_view:enter("Replace With Result Of Command", function(cmd) - core.active_view.doc:replace(function(str) - return exec( - "printf %b " .. printfb_quote(str:gsub("%\n$", "") .. "\n") .. " | eval '' " .. shell_quote(cmd), - str:find("%\n$") - ) - end) - end) + core.command_view:enter("Replace With Result Of Command", { + submit = function(cmd) + core.active_view.doc:replace(function(str) + return exec( + "printf %b " .. printfb_quote(str:gsub("%\n$", "") .. "\n") .. " | eval '' " .. shell_quote(cmd), + str:find("%\n$") + ) + end) + end + }) end, }) diff --git a/plugins/regexreplacepreview.lua b/plugins/regexreplacepreview.lua index 7ca8bc1..8abd39c 100644 --- a/plugins/regexreplacepreview.lua +++ b/plugins/regexreplacepreview.lua @@ -95,12 +95,11 @@ command.add("core.docview", { local doc = view.doc local original_selection = { doc:get_selection(true) } local selection = doc:has_selection() and { doc:get_selection(true) } or {} - core.command_view:enter( - "Regex Replace (enter pattern as /old/new/)", - function(pattern) + core.command_view:enter("Regex Replace (enter pattern as /old/new/)", { + submit = function(pattern) regex_replace_file(view, pattern, {}, false, selection[1], selection[3]) end, - function(pattern) + suggest = function(pattern) local incremental, has_replacement = regex_replace_file( view, pattern, old_lines, true, selection[1], selection[3] ) @@ -111,7 +110,7 @@ command.add("core.docview", { doc:set_selection(table.unpack(original_selection)) end end, - function(pattern) + cancel = function(pattern) for k,v in pairs(old_lines) do if v then if k == #doc.lines then @@ -124,7 +123,7 @@ command.add("core.docview", { end doc:set_selection(table.unpack(original_selection)) end - ) + }) end }) diff --git a/plugins/select_colorscheme.lua b/plugins/select_colorscheme.lua index 0d60251..6fa45d4 100644 --- a/plugins/select_colorscheme.lua +++ b/plugins/select_colorscheme.lua @@ -122,7 +122,9 @@ end command.add(nil, { ["ui:color scheme"] = function() - core.command_view:enter("Select color scheme", color_scheme_submit, color_scheme_suggest) + core.command_view:enter("Select color scheme", { + submit = color_scheme_submit, suggest = color_scheme_suggest + }) end, }) -- ---------------------------------------------------------------- diff --git a/plugins/spellcheck.lua b/plugins/spellcheck.lua index 23a5fa9..cd3e0f1 100644 --- a/plugins/spellcheck.lua +++ b/plugins/spellcheck.lua @@ -214,18 +214,21 @@ command.add("core.docview", { -- select word and init replacement selector local label = string.format("Replace \"%s\" With", word) doc:set_selection(line, e + 1, line, s) - core.command_view:enter(label, function(text, item) - text = item and item.text or text - doc:replace(function() return text end) - end, function(text) - local t = {} - for _, w in ipairs(suggestions) do - if w:lower():find(text:lower(), 1, true) then - table.insert(t, w) + core.command_view:enter(label, { + submit = function(text, item) + text = item and item.text or text + doc:replace(function() return text end) + end, + suggest = function(text) + local t = {} + for _, w in ipairs(suggestions) do + if w:lower():find(text:lower(), 1, true) then + table.insert(t, w) + end end + return t end - return t - end) + }) end, }) |