b7d2a6c61a
<sfile> inside a command! body is evaluated at execution time, not at
definition time. When :NuwikiInstall is run interactively there is no
sourcing context, so <sfile> 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 <noreply@anthropic.com>
55 lines
2.4 KiB
VimL
55 lines
2.4 KiB
VimL
" plugin/nuwiki.vim — universal Vim/Neovim entry point.
|
|
"
|
|
" Neovim 0.11+ users are expected to call `require('nuwiki').setup({})` from
|
|
" their config (lazy.nvim does this automatically through `opts`). On Vim
|
|
" we start the LSP client when a vimwiki buffer is loaded.
|
|
"
|
|
" Per SPEC §6.2 / §6.3 this file contains wiring only — all logic lives in
|
|
" the Rust language server.
|
|
|
|
if exists('g:loaded_nuwiki')
|
|
finish
|
|
endif
|
|
let g:loaded_nuwiki = 1
|
|
|
|
" Resolve the plugin root NOW, while this script is being sourced and
|
|
" <sfile> is still valid. Commands that need this path must reference
|
|
" s:plugin_root — re-expanding <sfile> 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('<sfile>: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.
|
|
finish
|
|
endif
|
|
|
|
" Vim path: start the LSP client the first time a vimwiki buffer is opened.
|
|
augroup nuwiki_vim_lsp_start
|
|
autocmd!
|
|
autocmd FileType vimwiki call nuwiki#lsp#start()
|
|
augroup END
|
|
|
|
" 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.
|
|
if !get(g:, 'nuwiki_no_default_mappings', 0)
|
|
nnoremap <silent> <Leader>ww :call nuwiki#commands#open_wiki_path(0)<CR>
|
|
nnoremap <silent> <Leader>wt :call nuwiki#commands#open_wiki_path(1)<CR>
|
|
nnoremap <silent> <Leader>ws :call nuwiki#commands#wiki_ui_select()<CR>
|
|
nnoremap <silent> <Leader>wi :call nuwiki#commands#open_diary_index_path()<CR>
|
|
nnoremap <silent> <Leader>w<Leader>w :call nuwiki#commands#open_diary_path(0)<CR>
|
|
nnoremap <silent> <Leader>w<Leader>y :call nuwiki#commands#open_diary_path(-1)<CR>
|
|
nnoremap <silent> <Leader>w<Leader>t :call nuwiki#commands#open_diary_path(1)<CR>
|
|
nnoremap <silent> <Leader>w<Leader>i :call nuwiki#commands#diary_generate_index()<CR>
|
|
endif
|