82444f5013
CI / editor tests (push) Successful in 44s
Mirrors the Lua util refactor. Pulls the copy-pasted VimL helpers into
autoload/nuwiki/util.vim and points the per-file s: stubs at it:
- heading_level (commands/folding/textobjects) — commands.vim's copy was
missing the >6 level cap the others had (a 7+ `=` line returned 7). The
unified version caps at 6 AND accepts spaceless headings (==Heading==),
matching the server lexer + the Lua client (so fold fallback, text
objects, and ]] navigation recognize spaceless headings too).
- is_table_row (commands/textobjects) — identical copies.
- wiki_cfg (commands/diary) — these had DRIFTED: commands.vim's included a
`space` (links_space_char) key diary.vim's lacked. Unified to the superset
so callers reading `.space` keep working; diary callers ignore the extra key.
Also refreshes the stale plugin/nuwiki.vim header ("all logic lives in the
Rust language server" → thin client; server is nuwiki-rs, downloaded).
Verified: 18-case heading battery in headless vim + full editor harness 10/10.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
36 lines
1.2 KiB
VimL
36 lines
1.2 KiB
VimL
" autoload/nuwiki/folding.vim — `foldexpr` for vimwiki buffers.
|
|
"
|
|
" Mirrors lua/nuwiki/folding.lua. Pure regex over `getline()`, so works
|
|
" without a language server. Activated in `ftplugin/vimwiki.vim`:
|
|
"
|
|
" setlocal foldmethod=expr
|
|
" setlocal foldexpr=nuwiki#folding#expr()
|
|
" setlocal foldtext=nuwiki#folding#foldtext()
|
|
"
|
|
" Fold structure mirrors the document outline: each `= H1 =` opens a
|
|
" level-1 fold, each `== H2 ==` opens a level-2 fold, etc., and folds
|
|
" close implicitly at the next heading of same-or-shallower level (or
|
|
" end of buffer).
|
|
|
|
function! s:heading_level(line) abort
|
|
return nuwiki#util#heading_level(a:line)
|
|
endfunction
|
|
|
|
function! nuwiki#folding#expr() abort
|
|
let l:line = getline(v:lnum)
|
|
let l:lvl = s:heading_level(l:line)
|
|
if l:lvl > 0
|
|
return '>' . l:lvl
|
|
endif
|
|
return '='
|
|
endfunction
|
|
|
|
function! nuwiki#folding#foldtext() abort
|
|
let l:line = getline(v:foldstart)
|
|
let l:title = substitute(l:line, '=', '', 'g')
|
|
let l:title = substitute(l:title, '^\s\+', '', '')
|
|
let l:title = substitute(l:title, '\s\+$', '', '')
|
|
let l:count = v:foldend - v:foldstart + 1
|
|
return '▸ ' . l:title . ' … (' . l:count . ' lines)'
|
|
endfunction
|