From 7a0cec4920fa6f330ca62a9991fc6e8a304cb8e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Fr=C3=B3es=20Franco?= Date: Thu, 14 May 2026 15:01:21 +0000 Subject: [PATCH] fix(lists): skip own indent in smart_return when auto-indent is active MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nvim defaults autoindent=on, so the indent inserted by Vim/Nvim after the we return was being doubled by our own indent prefix — pressing Enter on a sub-item produced a deeper-nested item instead of a same-level one. Detect any auto-indent mechanism (autoindent, smartindent, cindent, indentexpr) and let it own the indentation; otherwise add it ourselves so vim's noautoindent default still works. Co-Authored-By: Claude Opus 4.7 (1M context) --- autoload/nuwiki/commands.vim | 7 ++++++- lua/nuwiki/commands.lua | 10 +++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/autoload/nuwiki/commands.vim b/autoload/nuwiki/commands.vim index 21e2ee6..ab627fe 100644 --- a/autoload/nuwiki/commands.vim +++ b/autoload/nuwiki/commands.vim @@ -881,7 +881,12 @@ function! nuwiki#commands#smart_return() abort " newline. Indent gets dropped (matches vimwiki's break-out). return "\0DA\" endif - let l:cont = l:indent . l:marker . ' ' + " If any auto-indent mechanism is active (autoindent, smartindent, + " cindent, or indentexpr), Vim already inserts the previous line's + " indent after ``. Skipping our own indent in that case avoids + " doubling it and pushing the new bullet one level deeper. + let l:auto = &autoindent || &smartindent || &cindent || !empty(&indentexpr) + let l:cont = (l:auto ? '' : l:indent) . l:marker . ' ' if l:has_cb let l:cont .= '[ ] ' endif diff --git a/lua/nuwiki/commands.lua b/lua/nuwiki/commands.lua index 14de31c..0134d52 100644 --- a/lua/nuwiki/commands.lua +++ b/lua/nuwiki/commands.lua @@ -790,7 +790,15 @@ function M.smart_return() -- "break out of the list" behaviour on an empty bullet). return esc .. '0DA' .. cr end - return cr .. indent .. marker .. ' ' .. (cb and '[ ] ' or '') + -- nvim defaults `autoindent=on`, which inserts the previous line's + -- indent right after the `` we return. If we then add our own + -- `indent`, the new bullet is pushed one level deeper than the one + -- the user is continuing. Skip our copy whenever any auto-indent + -- mechanism is active and let Vim/Nvim insert the indent for us. + local auto = vim.bo.autoindent or vim.bo.smartindent or vim.bo.cindent + or (vim.bo.indentexpr ~= nil and vim.bo.indentexpr ~= '') + local effective_indent = auto and '' or indent + return cr .. effective_indent .. marker .. ' ' .. (cb and '[ ] ' or '') end return cr end