diff --git a/lua/orgmode-babel/init.lua b/lua/orgmode-babel/init.lua index a0da0f7..33d7cc0 100644 --- a/lua/orgmode-babel/init.lua +++ b/lua/orgmode-babel/init.lua @@ -156,6 +156,13 @@ vim.api.nvim_create_user_command("OrgExecute", function(el) local script = M._run_all 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 el.bang then 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 elseif range == 1 then 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) - if #blocks ~= 1 then - if #blocks > 1 then - 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 + if #blocks > 1 then + vim.notify("Bailing on multiple blocks with single line range ?? (Report upstream)", vim.log.level.ERROR) return end @@ -211,13 +213,8 @@ vim.api.nvim_create_user_command("OrgExecute", function(el) parameters = blocks elseif range == 2 then 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) - if #blocks <= 0 then - return - end - local names_string = #names > 0 and table.concat(names, ", ") or "" local sep = #blocks > #names and #names > 0 and ", " 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 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 el.bang then vim.notify("Tangling whole file", vim.log.levels.INFO) @@ -286,15 +290,10 @@ vim.api.nvim_create_user_command("OrgTangle", function(el) end elseif range == 1 then 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) - if #blocks ~= 1 then - if #blocks > 1 then - 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 + if #blocks > 1 then + vim.notify("Bailing on multiple blocks with single line range ?? (Report upstream)", vim.log.levinitOR) return end @@ -319,13 +318,8 @@ vim.api.nvim_create_user_command("OrgTangle", function(el) parameters = blocks elseif range == 2 then 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) - if #blocks <= 0 then - return - end - local names_string = #names > 0 and table.concat(names, ", ") or "" local sep = #blocks > #names and #names > 0 and ", " or "" local unnamed_string = #blocks > #names and #blocks - #names .. " unnamed" or ""