Skip to content

Commit

Permalink
Don't mess with comments again.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Dec 18, 2024
1 parent f70e4ed commit c7b2681
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lua/lean/indent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,23 @@ end
function M.indentexpr(linenr)
linenr = linenr or vim.v.lnum

if linenr == 1 or NEVER_INDENT:match_line(0, linenr - 1) then
if linenr == 1 then
return 0 -- Don't indent the first line, and now we can subtract from linenr.
elseif is_comment(linenr - 1) then
return vim.fn.indent(linenr)
end

local last, current = unpack(vim.api.nvim_buf_get_lines(0, linenr - 2, linenr, true))
local shiftwidth = vim.bo.shiftwidth

local _, current_indent = current:find '^%s*'
if
is_comment(linenr - 1)
or current == '}'
current == '}'
or (current_indent > 0 and current_indent < #current and current_indent % shiftwidth == 0)
then
return current_indent ---@type integer
elseif NEVER_INDENT:match_str(current) then
return 0
end

if last:find ':%s*$' then
Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/indent/comment.in.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
-- please then
-- thanks :=
-- !

/- same here
even if I say
attribute in
this
-/

0 comments on commit c7b2681

Please sign in to comment.