From c7b6637b62fe4b682100efb8a44a17ab026c86da Mon Sep 17 00:00:00 2001 From: Georgi Kirilov <> Date: Sat, 31 Oct 2020 11:50:51 +0200 Subject: [PATCH] newline before a margin comment preserves it M-) reuses the same code thus is handled the same way --- edit.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/edit.lua b/edit.lua index 12898e1..ba8bda8 100644 --- a/edit.lua +++ b/edit.lua @@ -607,15 +607,18 @@ function M.new(parser, walker, fmt, write, delete, eol_at) end local last_nonblank_in_list = not parent.is_empty and parent[#parent].finish - (line_comment and 1 or 0) local nxt = parent.after(range.start, startof) - local last_on_line = not nxt or nxt.indent and nxt.start > range.start + local last_on_line = not nxt or nxt and nxt.indent and nxt.start > range.start + local margin = nxt and not nxt.indent and nxt.is_comment and parser.opposite[nxt.d] == "\n" and nxt.finish local after_last = last_nonblank_in_list and range.start > last_nonblank_in_list local placeholder = "asdf" + local newpos = margin or range.start if not parent.is_empty then - write(range.start, "\n"..((after_last or last_on_line) and placeholder or "")) + write(newpos, "\n"..((after_last or last_on_line or margin) and placeholder or "")) end - parser.tree.rewind(parent.start or range.start) + parser.tree.rewind(parent.start or newpos) -- move the cursor onto the placeholder, so refmt_at can restore the position: - local newpos = walker.start_after(range) or range.start + local r = {start = newpos, finish = newpos} + newpos = walker.start_after(r) or newpos local rangeng = {start = newpos, finish = newpos} newpos = refmt_at(parent, rangeng) or rangeng.start if after_last then @@ -623,7 +626,7 @@ function M.new(parser, walker, fmt, write, delete, eol_at) local autoindent = parentng[#parentng].indent write(parentng.finish, "\n"..string.rep(" ", autoindent or 0)) end - if after_last or last_on_line then + if after_last or last_on_line or margin then delete(newpos, #placeholder) end parser.tree.rewind(newpos) -- 2.11.4.GIT