return early when specified block does not exist

This commit is contained in:
marshmallow 2023-06-26 00:17:58 +10:00
parent f8b41823d6
commit 406dd086a4
No known key found for this signature in database
GPG key ID: 767B8880F5AAEB9C

View file

@ -156,6 +156,7 @@ vim.api.nvim_create_user_command("OrgExecute", function(el)
local parameters = {} local parameters = {}
local blocks = M.get_blocks_in_buffer(0, line1, line2) local blocks = M.get_blocks_in_buffer(0, line1, line2)
local named_blocks = M.get_names_in_buffer(0, line1, line2)
if #blocks <= 0 then if #blocks <= 0 then
vim.notify("No blocks", vim.log.levels.INFO) vim.notify("No blocks", vim.log.levels.INFO)
@ -163,6 +164,10 @@ vim.api.nvim_create_user_command("OrgExecute", function(el)
end end
if arg ~= "" then if arg ~= "" then
if not vim.list_contains(named_blocks, arg) then
return vim.notify("Block not found (" .. arg .. ")", vim.log.levels.ERROR)
end
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)
elseif elseif
@ -184,7 +189,6 @@ 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 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.level.ERROR) vim.notify("Bailing on multiple blocks with single line range ?? (Report upstream)", vim.log.level.ERROR)