" autoload/vimwiki/vars.vim — compatibility shim for plugins that depend on " the original vimwiki API (e.g. vimwiki-sync, vim-zettel). " " Only the subset of `vimwiki#vars#get_wikilocal` keys that third-party " plugins are known to call is implemented here; add entries as needed. " Values are read from nuwiki's own config variables so users don't have " to duplicate settings. " Resolve which wiki a `get_wikilocal` call refers to, mirroring upstream: " - an explicit numeric second argument selects that wiki (0-based); " - otherwise the wiki owning the current buffer is used " (upstream's `g:vimwiki_current_idx`); " - failing that, the first/shorthand wiki (index 0). function! s:resolve_index(...) abort if a:0 >= 1 && type(a:1) == type(0) return a:1 endif let l:file = expand('%:p') if !empty(l:file) let l:n = 0 for l:w in nuwiki#commands#wiki_list() let l:wroot = fnamemodify(expand(l:w.root), ':p') if l:wroot[len(l:wroot) - 1:] !=# '/' | let l:wroot .= '/' | endif if l:file[: len(l:wroot) - 1] ==# l:wroot return l:n endif let l:n += 1 endfor endif return 0 endfunction " Per-wiki local config values. " " Supported keys: " path — wiki root directory (with trailing slash) " is_temporary_wiki — always 0 for a configured wiki " ext / extension — file extension (default '.wiki') " syntax — syntax name (default 'vimwiki') " " The optional second argument is the wiki index (upstream's signature); " when omitted, the wiki owning the current buffer is used. Values are " pulled from the matching `g:nuwiki_wikis` entry, falling back to the " scalar `g:nuwiki_*` globals for keys that entry doesn't set. function! vimwiki#vars#get_wikilocal(key, ...) abort if a:key ==# 'is_temporary_wiki' return 0 endif let l:idx = call('s:resolve_index', a:000) let l:wikis = nuwiki#commands#wiki_list() if l:idx < 0 || l:idx >= len(l:wikis) let l:idx = 0 endif let l:w = l:wikis[l:idx] if a:key ==# 'path' let l:root = expand(l:w.root) " Ensure trailing slash to match what the original vimwiki returns. return l:root =~# '/$' ? l:root : l:root . '/' elseif a:key ==# 'ext' || a:key ==# 'extension' " wiki_list() already normalises the leading dot. return l:w.ext elseif a:key ==# 'syntax' " wiki_list() doesn't carry `syntax`; read the per-wiki entry, then the " global default. let l:cfg = (exists('g:nuwiki_wikis') && len(g:nuwiki_wikis) > l:idx) \ ? g:nuwiki_wikis[l:idx] : {} return get(l:cfg, 'syntax', get(g:, 'nuwiki_syntax', 'vimwiki')) endif return '' endfunction " Global (non-wiki-specific) config values. function! vimwiki#vars#get_global(key) abort return '' endfunction