Skip to content

Commit

Permalink
Don't be indent-confused by from sorry.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Dec 27, 2024
1 parent 44cd9c2 commit 25530cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lua/lean/indent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ function M.indentexpr(linenr)
end

local sorry = sorry_at(linenr - 2, #last - 1)
if sorry and not last:find ':=' then
return math.max(0, sorry - shiftwidth - 1)
if sorry then
local before = last:sub(1, sorry)
if not before:find ':=%s*' and not before:find 'from%s*' then
return math.max(0, sorry - shiftwidth - 1)
end
end

local _, last_indent = last:find '^%s*'
Expand Down
18 changes: 18 additions & 0 deletions spec/indent_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ describe('indent', function()
)
)

it(
'is not confused by sorry after from',
helpers.clean_buffer(
[[
example : 37 = 37 := by
suffices h : 73 = 73 from sorry
]],
function()
helpers.feed 'Gorfl'
assert.contents.are [[
example : 37 = 37 := by
suffices h : 73 = 73 from sorry
rfl
]]
end
)
)

it(
'dedents after focused sorry',
helpers.clean_buffer(
Expand Down

0 comments on commit 25530cf

Please sign in to comment.