From b7d2a6c61a22bececb58cca31432642b1b25c3fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Fr=C3=B3es=20Franco?= Date: Thu, 21 May 2026 22:21:50 -0300 Subject: [PATCH] fix(install): resolve plugin root at source time to fix NuwikiInstall E484 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit inside a command! body is evaluated at execution time, not at definition time. When :NuwikiInstall is run interactively there is no sourcing context, so expands to nothing and the path collapses to ./scripts/download_bin.vim — producing E484. Fix: capture the path in s:plugin_root immediately while the script is being sourced, then reference that variable from the command body. Also hoist :NuwikiInstall above the early `finish` for Neovim so the command is available in both editors (Neovim routes to require('nuwiki.install').install(), Vim sources the download script). Co-Authored-By: Claude Sonnet 4.6 --- plugin/nuwiki.vim | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/plugin/nuwiki.vim b/plugin/nuwiki.vim index 78f6aff..793e0f0 100644 --- a/plugin/nuwiki.vim +++ b/plugin/nuwiki.vim @@ -12,6 +12,21 @@ if exists('g:loaded_nuwiki') endif let g:loaded_nuwiki = 1 +" Resolve the plugin root NOW, while this script is being sourced and +" is still valid. Commands that need this path must reference +" s:plugin_root — re-expanding inside a command body evaluates +" at execution time when there is no sourcing context, producing an +" empty path (hence the E484 "Cannot open ./scripts/…" error). +let s:plugin_root = fnamemodify(resolve(expand(':p')), ':h:h') + +" :NuwikiInstall — install the nuwiki-ls binary without needing a +" plugin-manager build hook. Available for both Vim and Neovim. +if has('nvim') + command! -nargs=0 NuwikiInstall lua require('nuwiki.install').install() +else + command! -nargs=0 NuwikiInstall execute 'source' fnameescape(s:plugin_root . '/scripts/download_bin.vim') +endif + if has('nvim') " Neovim path is initialised by `require('nuwiki').setup()`. Nothing else " to do at vimscript boot — wait until the user runs setup. @@ -24,10 +39,6 @@ augroup nuwiki_vim_lsp_start autocmd FileType vimwiki call nuwiki#lsp#start() augroup END -" :NuwikiInstall — convenience wrapper around scripts/download_bin.vim, so -" users don't have to invoke a plugin-manager build hook by hand. -command! -nargs=0 NuwikiInstall execute 'source' fnamemodify(resolve(expand(':p')), ':h:h') . '/scripts/download_bin.vim' - " Global entry-point mappings — work from any buffer, not just .wiki files. " Files are opened directly from config (no LSP required); the server " auto-starts via the FileType autocmd once the vimwiki buffer loads.