feat(calendar): diary into the current wiki, not always the first
The VimL calendar-vim callbacks (nuwiki#diary#calendar_action / calendar_sign) hardcoded wiki 0, so opening the calendar while editing ifood_wiki still created/marked diary entries under the first wiki. (The LSP-driven diary commands already follow the current buffer via its URI; this brings the calendar in line.) Track the wiki of the active buffer (nuwiki#diary#track_wiki, driven by FileType/BufEnter autocmds in plugin/nuwiki.vim) and resolve the calendar diary path against it, falling back to the first wiki. Verified the calendar marker/open switch between wikis as you move between their buffers. test-calendar-vim gains 4 multi-wiki tracking checks (16). All keymap/config/calendar harnesses green on both clients. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,33 @@
|
||||
|
||||
" ===== Calendar-Vim Integration =====
|
||||
|
||||
" The wiki index (0-based) of the most recently entered wiki buffer. The
|
||||
" calendar shows / creates diary entries for this wiki, so opening the calendar
|
||||
" while editing `ifood_wiki` diaries into ifood_wiki — not always the first
|
||||
" wiki. Updated by the BufEnter autocmd in plugin/nuwiki.vim; defaults to 0.
|
||||
" (The LSP-driven diary commands already follow the current buffer via its URI;
|
||||
" this mirrors that for the VimL calendar-vim callbacks.)
|
||||
let s:current_wiki_idx = 0
|
||||
|
||||
" Record the wiki that owns `file` as the current one. Called on entering a
|
||||
" wiki buffer. No-op when the file is under no configured wiki.
|
||||
function! nuwiki#diary#track_wiki(file) abort
|
||||
let l:file = fnamemodify(a:file, ':p')
|
||||
if empty(l:file)
|
||||
return
|
||||
endif
|
||||
let l:n = 0
|
||||
for l:w in nuwiki#commands#wiki_list()
|
||||
let l:root = fnamemodify(expand(l:w.root), ':p')
|
||||
if l:root[len(l:root) - 1:] !=# '/' | let l:root .= '/' | endif
|
||||
if l:file[: len(l:root) - 1] ==# l:root
|
||||
let s:current_wiki_idx = l:n
|
||||
return
|
||||
endif
|
||||
let l:n += 1
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
" Function: nuwiki#diary#calendar_action(day, month, year, week, dir)
|
||||
" Called by calendar-vim when user presses Enter on a date.
|
||||
" day/month/year are numeric integers; dir is 'V' for a vertical split (any
|
||||
@@ -12,8 +39,8 @@ function! nuwiki#diary#calendar_action(day, month, year, week, dir) abort
|
||||
" Build YYYY-MM-DD from the parts passed by calendar-vim
|
||||
let l:date_str = printf('%04d-%02d-%02d', a:year, a:month, a:day)
|
||||
|
||||
" Get wiki configuration for the first wiki (index 0)
|
||||
let l:c = s:wiki_cfg(0)
|
||||
" Wiki of the buffer the calendar was opened from (falls back to the first).
|
||||
let l:c = s:wiki_cfg(s:current_wiki_idx)
|
||||
|
||||
" Construct file path: {root}/{diary_rel}/{YYYY-MM-DD}.{ext}
|
||||
let l:file_path = l:c.root . '/' . l:c.diary_rel . '/' . l:date_str . l:c.ext
|
||||
@@ -62,8 +89,8 @@ function! nuwiki#diary#calendar_sign(day, month, year) abort
|
||||
" Build YYYY-MM-DD from the parts passed by calendar-vim
|
||||
let l:date_str = printf('%04d-%02d-%02d', a:year, a:month, a:day)
|
||||
|
||||
" Get wiki configuration for the first wiki (index 0)
|
||||
let l:c = s:wiki_cfg(0)
|
||||
" Wiki of the buffer the calendar was opened from (falls back to the first).
|
||||
let l:c = s:wiki_cfg(s:current_wiki_idx)
|
||||
|
||||
" Construct expected file path
|
||||
let l:file_path = l:c.root . '/' . l:c.diary_rel . '/' . l:date_str . l:c.ext
|
||||
|
||||
Reference in New Issue
Block a user