Skip to content

Commit 5e3533e

Browse files
committed
Do indent lines below blank lines if the line below is indented.
This seems like better behavior for the case of: ``` lemma foo : ... := have : stuff := ... -- inserting an additional line *here* from below have : otherstuff := ... ```
1 parent b94de51 commit 5e3533e

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

lua/lean/indent.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function M.indentexpr(linenr)
142142
-- repetaedly over lines backwards, so we cheat and just check whether the
143143
-- previous line looks like it has a binder on it.
144144
local is_end_of_binders = dedent_one > 0 and last:find '^%s*[({[]'
145-
return is_end_of_binders and dedent_one or last_indent
145+
return is_end_of_binders and dedent_one or last_indent == 0 and current_indent or last_indent
146146
end
147147

148148
return current_indent ---@type integer

spec/indent_spec.lua

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,51 @@ describe('indent', function()
209209
)
210210
)
211211

212+
it(
213+
'does not indent after blank lines with no indent below',
214+
helpers.clean_buffer(
215+
[[
216+
theorem foo : 37 = 37 := by
217+
rfl
218+
219+
]],
220+
function()
221+
helpers.feed 'G'
222+
assert.current_line.is ''
223+
224+
helpers.feed 'o#check 37'
225+
assert.contents.are [[
226+
theorem foo : 37 = 37 := by
227+
rfl
228+
229+
#check 37
230+
]]
231+
end
232+
)
233+
)
234+
235+
it(
236+
'does indent after blank lines with indent below',
237+
helpers.clean_buffer(
238+
[[
239+
theorem foo : 37 = 37 := by
240+
have : 1 = 1 := rfl
241+
242+
have : 38 = 38 := rfl
243+
]],
244+
function()
245+
helpers.feed 'GOhave : 37 = 37 := rfl'
246+
assert.contents.are [[
247+
theorem foo : 37 = 37 := by
248+
have : 1 = 1 := rfl
249+
250+
have : 37 = 37 := rfl
251+
have : 38 = 38 := rfl
252+
]]
253+
end
254+
)
255+
)
256+
212257
for each in fixtures.indent() do
213258
it(each.description, function()
214259
vim.cmd.edit { each.unindented, bang = true }

0 commit comments

Comments
 (0)