aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/eval.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/plugins/eval.lua b/plugins/eval.lua
index 1f507fb..da6e9be 100644
--- a/plugins/eval.lua
+++ b/plugins/eval.lua
@@ -1,6 +1,8 @@
-- mod-version:3
local core = require "core"
local command = require "core.command"
+local contextmenu = require "plugins.contextmenu"
+local keymap = require "core.keymap"
local function eval(str)
@@ -29,4 +31,23 @@ command.add("core.docview", {
end
})
end,
+
+ ["eval:selected"] = function(dv)
+ if dv.doc:has_selection() then
+ local text = dv.doc:get_text(dv.doc:get_selection())
+ dv.doc:text_input(eval(text))
+ else
+ local line = dv.doc:get_selection()
+ local text = dv.doc.lines[line]
+ dv.doc:insert(line+1, 0, "= " .. eval(text) .. "\n")
+ end
+ end,
})
+
+
+contextmenu:register("core.docview", {
+ { text = "Evaluate Selected", command = "eval:selected" }
+})
+
+
+keymap.add { ["ctrl+alt+return"] = "eval:selected" }