bail early when no blocks in file
This commit is contained in:
parent
c5c1e4ca2b
commit
3022690342
1 changed files with 18 additions and 24 deletions
|
|
@ -156,6 +156,13 @@ vim.api.nvim_create_user_command("OrgExecute", function(el)
|
||||||
local script = M._run_all
|
local script = M._run_all
|
||||||
local parameters = {}
|
local parameters = {}
|
||||||
|
|
||||||
|
local blocks = M.get_blocks_in_buffer(0, line1, line2)
|
||||||
|
|
||||||
|
if #blocks <= 0 then
|
||||||
|
vim.notify("No blocks", vim.log.levels.INFO)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if arg ~= "" then
|
if arg ~= "" then
|
||||||
if el.bang then
|
if el.bang then
|
||||||
vim.notify("Evaulating code block (" .. arg .. ") on your system", vim.log.levels.INFO)
|
vim.notify("Evaulating code block (" .. arg .. ") on your system", vim.log.levels.INFO)
|
||||||
|
|
@ -178,15 +185,10 @@ vim.api.nvim_create_user_command("OrgExecute", function(el)
|
||||||
end
|
end
|
||||||
elseif range == 1 then
|
elseif range == 1 then
|
||||||
script = M._run_by_number
|
script = M._run_by_number
|
||||||
local blocks = M.get_blocks_in_buffer(0, line1, line2)
|
|
||||||
local named_blocks = M.get_names_in_buffer(0, line1, line2)
|
local named_blocks = M.get_names_in_buffer(0, line1, line2)
|
||||||
|
|
||||||
if #blocks ~= 1 then
|
if #blocks > 1 then
|
||||||
if #blocks > 1 then
|
vim.notify("Bailing on multiple blocks with single line range ?? (Report upstream)", vim.log.level.ERROR)
|
||||||
vim.notify("Bailing on multiple blocks with single line range ?? (Report upstream)", vim.log.levinitOR)
|
|
||||||
else
|
|
||||||
vim.notify("No blocks", vim.log.levels.ERROR)
|
|
||||||
end
|
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
@ -211,13 +213,8 @@ vim.api.nvim_create_user_command("OrgExecute", function(el)
|
||||||
parameters = blocks
|
parameters = blocks
|
||||||
elseif range == 2 then
|
elseif range == 2 then
|
||||||
script = M._run_by_number
|
script = M._run_by_number
|
||||||
local blocks = M.get_blocks_in_buffer(0, line1, line2)
|
|
||||||
local names = M.get_names_in_buffer(0, line1, line2)
|
local names = M.get_names_in_buffer(0, line1, line2)
|
||||||
|
|
||||||
if #blocks <= 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local names_string = #names > 0 and table.concat(names, ", ") or ""
|
local names_string = #names > 0 and table.concat(names, ", ") or ""
|
||||||
local sep = #blocks > #names and #names > 0 and ", " or ""
|
local sep = #blocks > #names and #names > 0 and ", " or ""
|
||||||
local unnamed_string = #blocks > #names and #blocks - #names .. " unnamed" or ""
|
local unnamed_string = #blocks > #names and #blocks - #names .. " unnamed" or ""
|
||||||
|
|
@ -278,6 +275,13 @@ vim.api.nvim_create_user_command("OrgTangle", function(el)
|
||||||
local script = M._tangle_all
|
local script = M._tangle_all
|
||||||
local parameters = {}
|
local parameters = {}
|
||||||
|
|
||||||
|
local blocks = M.get_blocks_in_buffer(0, line1, line2)
|
||||||
|
|
||||||
|
if #blocks <= 0 then
|
||||||
|
vim.notify("No blocks", vim.log.levels.INFO)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if line1 == 1 and line2 == total_lines then
|
if line1 == 1 and line2 == total_lines then
|
||||||
if el.bang then
|
if el.bang then
|
||||||
vim.notify("Tangling whole file", vim.log.levels.INFO)
|
vim.notify("Tangling whole file", vim.log.levels.INFO)
|
||||||
|
|
@ -286,15 +290,10 @@ vim.api.nvim_create_user_command("OrgTangle", function(el)
|
||||||
end
|
end
|
||||||
elseif range == 1 then
|
elseif range == 1 then
|
||||||
script = M._tangle_by_number
|
script = M._tangle_by_number
|
||||||
local blocks = M.get_blocks_in_buffer(0, line1, line2)
|
|
||||||
local named_blocks = M.get_names_in_buffer(0, line1, line2)
|
local named_blocks = M.get_names_in_buffer(0, line1, line2)
|
||||||
|
|
||||||
if #blocks ~= 1 then
|
if #blocks > 1 then
|
||||||
if #blocks > 1 then
|
vim.notify("Bailing on multiple blocks with single line range ?? (Report upstream)", vim.log.levinitOR)
|
||||||
vim.notify("Bailing on multiple blocks with single line range ?? (Report upstream)", vim.log.levinitOR)
|
|
||||||
else
|
|
||||||
vim.notify("No blocks", vim.log.levels.ERROR)
|
|
||||||
end
|
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
@ -319,13 +318,8 @@ vim.api.nvim_create_user_command("OrgTangle", function(el)
|
||||||
parameters = blocks
|
parameters = blocks
|
||||||
elseif range == 2 then
|
elseif range == 2 then
|
||||||
script = M._tangle_by_number
|
script = M._tangle_by_number
|
||||||
local blocks = M.get_blocks_in_buffer(0, line1, line2)
|
|
||||||
local names = M.get_names_in_buffer(0, line1, line2)
|
local names = M.get_names_in_buffer(0, line1, line2)
|
||||||
|
|
||||||
if #blocks <= 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local names_string = #names > 0 and table.concat(names, ", ") or ""
|
local names_string = #names > 0 and table.concat(names, ", ") or ""
|
||||||
local sep = #blocks > #names and #names > 0 and ", " or ""
|
local sep = #blocks > #names and #names > 0 and ", " or ""
|
||||||
local unnamed_string = #blocks > #names and #blocks - #names .. " unnamed" or ""
|
local unnamed_string = #blocks > #names and #blocks - #names .. " unnamed" or ""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue