feat(generate): insert links/tags sections at the cursor line too
CI / cargo fmt --check (push) Successful in 28s
CI / cargo clippy (push) Successful in 36s
CI / cargo test (push) Successful in 40s
CI / editor keymaps (push) Successful in 1m26s

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:
2026-06-05 01:07:18 +00:00
parent 94cb58064d
commit f0c51fbfcc
7 changed files with 180 additions and 55 deletions
+6 -5
View File
@@ -521,12 +521,12 @@ end
-- `:VimwikiGenerateLinks [rel_path]` — optional path scopes the links to a
-- subtree via the server's generateForPath; no arg = every page.
M.links_generate = function(path)
-- Cursor line (0-based) so a fresh section is inserted there.
local line = vim.api.nvim_win_get_cursor(0)[1] - 1
if path and path ~= '' then
local args = uri_args()[1]
args.path = path
exec('nuwiki.links.generateForPath', { args })
exec('nuwiki.links.generateForPath', { { uri = buf_uri(), path = path, line = line } })
else
exec('nuwiki.links.generate', uri_args())
exec('nuwiki.links.generate', { { uri = buf_uri(), line = line } })
end
end
@@ -606,7 +606,8 @@ function M.tags_search(query)
end
function M.tags_generate_links(tag)
local args = { uri = buf_uri() }
-- Cursor line (0-based) so a fresh section is inserted there.
local args = { uri = buf_uri(), line = vim.api.nvim_win_get_cursor(0)[1] - 1 }
if tag and tag ~= '' then
args.tag = tag
end