pull/3/head
Björn Linse 6 years ago
parent e4b6e00c1a
commit 944572995b

@ -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()

@ -2,8 +2,7 @@ command! Luadev lua require'luadev'.start()
noremap <Plug>(Luadev-RunLine) <Cmd>lua require'luadev'.exec(vim.api.nvim_get_current_line())<cr>
vnoremap <Plug>(Luadev-Run) :<c-u>call luaeval("require'luadev'.exec(_A)", <SID>get_visual_selection())<cr>
vnoremap <Plug>(Luadev-Eval) :<c-u>call luaeval("require'luadev'.exec(_A,true)", <SID>get_visual_selection())<cr>
noremap <Plug>(Luadev-EvalWord) :<c-u>call luaeval("require'luadev'.exec(_A,true)", <SID>get_current_word())<cr>
noremap <Plug>(Luadev-RunWord) :<c-u>call luaeval("require'luadev'.exec(_A)", <SID>get_current_word())<cr>
" thanks to @xolox on stackoverflow
function! s:get_visual_selection()

Loading…
Cancel
Save