diff options
author | rxi <rxi@users.noreply.github.com> | 2020-04-23 20:46:44 +0100 |
---|---|---|
committer | rxi <rxi@users.noreply.github.com> | 2020-04-23 20:46:44 +0100 |
commit | 9049e189d49440939192874d54af15a21eebbafb (patch) | |
tree | cdf26ae3ccc771c34fe2671359cd636a15c3c5ad | |
parent | d9d1a20f33989fbeab78e5f695f3537b3911d360 (diff) | |
download | lite-xl-plugins-9049e189d49440939192874d54af15a21eebbafb.tar.gz lite-xl-plugins-9049e189d49440939192874d54af15a21eebbafb.zip |
Added plugin `eval`
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | eval.lua | 23 |
2 files changed, 24 insertions, 0 deletions
@@ -11,6 +11,7 @@ Plugin | Description -------|----------------------------------------- [`autowrap`](autowrap.lua?raw=1) | Automatically hardwraps lines when typing [`bracketmatch`](bracketmatch.lua?raw=1) | [Underlines](https://user-images.githubusercontent.com/3920290/80132745-0c863f00-8594-11ea-8875-c455c6fd7eae.png) matching right-bracket of left-bracket under caret +[`eval`](eval.lua?raw=1) | Replaces selected Lua code with its evaluated result [`gofmt`](gofmt.lua?raw=1) | Auto-formats the current go file, adds the missing imports and the missing return cases [`indentguide`](indentguide.lua?raw=1) | Adds [indent guides](https://user-images.githubusercontent.com/3920290/79640716-f9860000-818a-11ea-9c3b-26d10dd0e0c0.png) [`language_fe`](language_fe.lua?raw=1) | Syntax for the [fe](https://github.com/rxi/fe) programming language diff --git a/eval.lua b/eval.lua new file mode 100644 index 0000000..54e08ba --- /dev/null +++ b/eval.lua @@ -0,0 +1,23 @@ +local core = require "core" +local command = require "core.command" + + +local function eval(str) + local fn, err = load("return " .. str) + if not fn then fn, err = load(str) end + assert(fn, err) + return tostring(fn()) +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) + end, + + ["eval:replace"] = function() + core.active_view.doc:replace(eval) + end, +}) |