Skip to content

Commit

Permalink
fix(virtual indent): handle invalid buffer gracefully (#825)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Flügge <[email protected]>
  • Loading branch information
seflue and Sebastian Flügge authored Nov 15, 2024
1 parent fafb8f1 commit 1d8c9b9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lua/orgmode/org/indent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ local function indentexpr(linenr, bufnr)
query = query or vim.treesitter.query.get('org', 'org_indent')

bufnr = bufnr or vim.api.nvim_get_current_buf()

-- The buffer might be invalid, which can happen, if the function is implicitly called through
-- refile operations. In this case we fallback to autoindent.
if bufnr == -1 or not vim.api.nvim_buf_is_valid(bufnr) then
return -1
end

local indentexpr_cache = buf_indentexpr_cache[bufnr] or { prev_linenr = -1 }
if indentexpr_cache.prev_linenr ~= linenr - 1 or not mode:lower():find('n') then
indentexpr_cache.matches = get_matches(bufnr)
Expand Down

0 comments on commit 1d8c9b9

Please sign in to comment.