Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1d8c9b9

Browse files
seflueSebastian Flügge
and
Sebastian Flügge
authored
fix(virtual indent): handle invalid buffer gracefully (#825)
Co-authored-by: Sebastian Flügge <sebastian.fluegge@dnv.com>
1 parent fafb8f1 commit 1d8c9b9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lua/orgmode/org/indent.lua

+7
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,13 @@ local function indentexpr(linenr, bufnr)
246246
query = query or vim.treesitter.query.get('org', 'org_indent')
247247

248248
bufnr = bufnr or vim.api.nvim_get_current_buf()
249+
250+
-- The buffer might be invalid, which can happen, if the function is implicitly called through
251+
-- refile operations. In this case we fallback to autoindent.
252+
if bufnr == -1 or not vim.api.nvim_buf_is_valid(bufnr) then
253+
return -1
254+
end
255+
249256
local indentexpr_cache = buf_indentexpr_cache[bufnr] or { prev_linenr = -1 }
250257
if indentexpr_cache.prev_linenr ~= linenr - 1 or not mode:lower():find('n') then
251258
indentexpr_cache.matches = get_matches(bufnr)

0 commit comments

Comments
 (0)