feat(generate): insert links/tags sections at the cursor line too
Extend the cursor-line insertion from :NuwikiTOC to the other buffer list generators: :NuwikiGenerateLinks and :NuwikiGenerateTagLinks. They appended at end-of-file; a fresh section now goes at the cursor line (with a leading blank), matching :NuwikiTOC. An existing section is still refreshed in place, and the auto_generate_*-on-save hooks are unaffected (they only ever replace). Shared section_insert() helper computes the insert position/block for all three (cursor line clamped to the document, else the per-command fallback: top of file for TOC, EOF for links/tags). Clients send the 0-based cursor line; handlers parse it via parse_uri_line_arg and thread it through links_edit / tag_links_edit. Rebuild variants pass None. Tests: links_edit_inserts_at_cursor_line + tag_links_edit_inserts_at_cursor_line. 577 passed, clippy clean, keymap harnesses green. Docs updated. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -734,11 +734,14 @@ endfunction
|
||||
" `generateForPath`). Matches upstream's optional path argument.
|
||||
function! nuwiki#commands#links_generate(...) abort
|
||||
let l:path = a:0 >= 1 ? a:1 : ''
|
||||
" Cursor line (0-based) so a fresh section is inserted there.
|
||||
let l:line = line('.') - 1
|
||||
if l:path !=# ''
|
||||
call s:exec('nuwiki.links.generateForPath',
|
||||
\ [{'uri': s:buf_uri(), 'path': l:path}])
|
||||
\ [{'uri': s:buf_uri(), 'path': l:path, 'line': l:line}])
|
||||
else
|
||||
call s:exec('nuwiki.links.generate', [{'uri': s:buf_uri()}])
|
||||
call s:exec('nuwiki.links.generate',
|
||||
\ [{'uri': s:buf_uri(), 'line': l:line}])
|
||||
endif
|
||||
endfunction
|
||||
function! nuwiki#commands#check_links(...) abort
|
||||
@@ -800,7 +803,8 @@ function! nuwiki#commands#tags_search(query) abort
|
||||
endfunction
|
||||
|
||||
function! nuwiki#commands#tags_generate_links(tag) abort
|
||||
let l:args = { 'uri': s:buf_uri() }
|
||||
" Cursor line (0-based) so a fresh section is inserted there.
|
||||
let l:args = { 'uri': s:buf_uri(), 'line': line('.') - 1 }
|
||||
if a:tag !=# ''
|
||||
let l:args['tag'] = a:tag
|
||||
endif
|
||||
|
||||
Reference in New Issue
Block a user