Skip to content

Commit b6907d5

Browse files
fix(formatting): Prevent infinite loop on formatting closed folds
1 parent 12da42e commit b6907d5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lua/orgmode/org/format.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ local function format()
4545
return 1
4646
end
4747

48+
-- When closed folds are being formatted, fallback formatting can
49+
-- happen with multiple lines instead of a single line due to some side effects.
50+
-- When we encounter that we need to return 0 to avoid infinite loop.
51+
-- This will prevent some of the lines of being formatted correctly,
52+
-- but there's no way to exit the infinite loop otherwise.
53+
for linenr = start_line, end_line do
54+
if formatexpr_cache[linenr] and vim.fn.foldclosed(linenr) > -1 then
55+
return 0
56+
end
57+
end
58+
4859
for linenr = start_line, end_line do
4960
local line_formatted = format_line(linenr)
5061
if not line_formatted then

0 commit comments

Comments
 (0)