diff options
-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, +}) |