diff --git a/development/tests/test-global-shorthand.lua b/development/tests/test-global-shorthand.lua index 240eb08..65bd54b 100644 --- a/development/tests/test-global-shorthand.lua +++ b/development/tests/test-global-shorthand.lua @@ -71,6 +71,16 @@ vim.g.nuwiki_wikis = nil vim.g.vimwiki_list = nil vim.g.vimwiki_toc_header_level = nil +-- ----- setup({ wikis }) bridges the Lua config to VimL (g:nuwiki_wikis) ----- +-- So buffer-side VimL helpers + the vimwiki-sync compat shim see the same +-- wikis as the LSP, even though setup() config lives only in Lua. +require('nuwiki').setup({ wikis = { { root = '/tmp/a', name = 'A' }, { root = '/tmp/b' } } }) +check('setup() bridges to g:nuwiki_wikis', + vim.g.nuwiki_wikis ~= nil and #vim.g.nuwiki_wikis == 2) +check('bridged wiki root visible to VimL', + vim.g.nuwiki_wikis and vim.g.nuwiki_wikis[1].root == '/tmp/a') +vim.g.nuwiki_wikis = nil + local f = assert(io.open(os.getenv('NUWIKI_GS_OUT'), 'w')) f:write(table.concat(out, '\n') .. '\n') f:close() diff --git a/lua/nuwiki/init.lua b/lua/nuwiki/init.lua index 9443799..015d1e9 100644 --- a/lua/nuwiki/init.lua +++ b/lua/nuwiki/init.lua @@ -93,6 +93,17 @@ end function M.setup(opts) config.apply(opts or {}) + -- Bridge a Lua-only `setup({ wikis = … })` config to VimL. The buffer-side + -- VimL helpers (autoload/nuwiki/config.vim) and the vimwiki compat shim + -- (autoload/vimwiki/vars.vim — used by third-party plugins such as + -- vimwiki-sync) read `g:nuwiki_wikis`, which can't see a config that only + -- lives in Lua. Publishing the resolved list keeps both worlds in sync. (A + -- `g:nuwiki_wikis` / `g:vimwiki_list` config is already VimL-visible, so this + -- only fires for the pure-`setup()` case.) + if type(config.options.wikis) == 'table' and #config.options.wikis > 0 then + vim.g.nuwiki_wikis = config.wikis() + end + -- Neovim 0.7+ resolves filetypes via `vim.filetype.match` before any -- `ftdetect/*.vim` autocmd fires, and its bundled rule for `*.wiki` -- returns `mediawiki`. Register an authoritative rule here so this