honeylisp/vendor/lite-plugins/plugins/eval.lua
Jeremy Penner cb5132f393 git subrepo clone https://github.com/rxi/lite-plugins vendor/lite-plugins
subrepo:
  subdir:   "vendor/lite-plugins"
  merged:   "de4227d"
upstream:
  origin:   "https://github.com/rxi/lite-plugins"
  branch:   "master"
  commit:   "de4227d"
git-subrepo:
  version:  "0.4.2"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "65fde50"
2020-11-19 21:04:39 -05:00

24 lines
504 B
Lua

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,
})