From 944572995bc820ae59a8725c0f83b519543a6f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Linse?= Date: Sun, 11 Nov 2018 09:43:16 +0100 Subject: [PATCH] nodoeval --- lua/luadev.lua | 14 +++++++------- plugin/luadev.vim | 3 +-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lua/luadev.lua b/lua/luadev.lua index a51ea52..bd215fe 100644 --- a/lua/luadev.lua +++ b/lua/luadev.lua @@ -91,20 +91,19 @@ local function dedent(str, leave_indent) return str end -local function exec(str,doeval) - local code = str - if doeval then - code = "return \n"..str +local function exec(str) + local chunk, err = loadstring("return \n"..str,"e") + if chunk == nil then + chunk, err = loadstring(str,"x") end - local chunk, err = loadstring(code,"g") local inlines = splitlines(dedent(str)) if inlines[#inlines] == "" then inlines[#inlines] = nil end for i,l in ipairs(inlines) do - inlines[i] = "> "..l + local marker = ((i == 1) and ">") or "." + inlines[i] = marker.." "..l end - append_buf({""}) local start = append_buf(inlines) for i,_ in ipairs(inlines) do a.nvim_buf_add_highlight(s.buf, -1, "Question", start+i-1, 0, 2) @@ -122,6 +121,7 @@ local function exec(str,doeval) append_buf(require'inspect'(res)) end end + append_buf({""}) end local function start() diff --git a/plugin/luadev.vim b/plugin/luadev.vim index 1aaf28b..9093956 100644 --- a/plugin/luadev.vim +++ b/plugin/luadev.vim @@ -2,8 +2,7 @@ command! Luadev lua require'luadev'.start() noremap (Luadev-RunLine) lua require'luadev'.exec(vim.api.nvim_get_current_line()) vnoremap (Luadev-Run) :call luaeval("require'luadev'.exec(_A)", get_visual_selection()) -vnoremap (Luadev-Eval) :call luaeval("require'luadev'.exec(_A,true)", get_visual_selection()) -noremap (Luadev-EvalWord) :call luaeval("require'luadev'.exec(_A,true)", get_current_word()) +noremap (Luadev-RunWord) :call luaeval("require'luadev'.exec(_A)", get_current_word()) " thanks to @xolox on stackoverflow function! s:get_visual_selection()