87ba4c1764
Add headless harnesses covering the calendar-vim integration, wired into CI alongside the existing keymap/config suites: - test-calendar-vim.sh/.vim (+ -optout.vim): pure-VimL diary hooks (calendar_sign markers, calendar_action path resolution from wiki root, calendar window close), plugin/nuwiki.vim hook auto-wiring that overrides calendar-vim's defaults, and opt-out via g:nuwiki_use_calendar and g:nuwiki_no_calendar. Uses a stub calendar-vim on the runtimepath. - test-calendar.sh/.lua: Neovim setup() wiring + window-close under the real window API, and opt-out via use_calendar = false. Fixes surfaced by the suite: - diary.vim: new diary entries set filetype 'vimwiki' (was the raw extension, e.g. 'wiki'); the stray FileType autocmd also blocked the calendar window from closing. - init.lua: drop the redundant Neovim FileType autocmd (plugin/nuwiki.vim already wires both editors) and translate use_calendar=false into g:nuwiki_no_calendar so the opt-out actually disables wiring.
96 lines
3.5 KiB
VimL
96 lines
3.5 KiB
VimL
" autoload/nuwiki/diary.vim — diary-specific functions for nuwiki
|
|
" Includes calendar-vim integration functions
|
|
|
|
" ===== Calendar-Vim Integration =====
|
|
|
|
" 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. week and dir are not used.
|
|
" Opens or creates the diary entry for the given date.
|
|
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)
|
|
|
|
" 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
|
|
|
|
" Remember the calendar window so we can close it once the diary opens.
|
|
let l:cal_winid = win_getid()
|
|
|
|
" Open the diary file in a different window. If a previous window exists go
|
|
" there; otherwise split / vsplit / new depending on a:dir.
|
|
if winnr('#') > 0
|
|
execute 'wincmd p'
|
|
if !&hidden && &modified
|
|
execute 'new'
|
|
endif
|
|
elseif a:dir ==# 'V'
|
|
execute 'vsplit'
|
|
else
|
|
execute 'split'
|
|
endif
|
|
|
|
execute 'edit ' . fnameescape(l:file_path)
|
|
" A brand-new entry has no file on disk yet, so ftdetect may not have run;
|
|
" ensure the vimwiki filetype so syntax/maps are active immediately.
|
|
if &filetype !=# 'vimwiki'
|
|
setfiletype vimwiki
|
|
endif
|
|
|
|
" Close the calendar window now that the diary is open (keep at least one).
|
|
if win_getid() != l:cal_winid && win_id2win(l:cal_winid) > 0 && winnr('$') > 1
|
|
let l:diary_winid = win_getid()
|
|
if win_gotoid(l:cal_winid)
|
|
close
|
|
endif
|
|
call win_gotoid(l:diary_winid)
|
|
endif
|
|
endfunction
|
|
|
|
" Function: nuwiki#diary#calendar_sign(day, month, year)
|
|
" Called by calendar-vim to determine which dates show markers (*)
|
|
" day, month, year are numeric integers (1-based).
|
|
" Returns a single-character string to use as marker (e.g. '*' or ''),
|
|
" or 1/0 for 1-indexed calendars.
|
|
" calendar-vim's default expects the return value to be a single character
|
|
" to display; returning any non-empty string shows a marker.
|
|
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)
|
|
|
|
" Construct expected file path
|
|
let l:file_path = l:c.root . '/' . l:c.diary_rel . '/' . l:date_str . l:c.ext
|
|
|
|
" Return a marker if the file exists, empty string otherwise
|
|
if filereadable(l:file_path)
|
|
return '*'
|
|
endif
|
|
return ''
|
|
endfunction
|
|
|
|
" Helper: get wiki configuration for wiki n (0-based).
|
|
" Mirrors the same logic used by nuwiki#commands#open_diary_path etc.
|
|
function! s:wiki_cfg(n) abort
|
|
let l:w = {}
|
|
if exists('g:nuwiki_wikis') && len(g:nuwiki_wikis) > a:n
|
|
let l:w = g:nuwiki_wikis[a:n]
|
|
endif
|
|
let l:root = expand(get(l:w, 'root',
|
|
\ get(g:, 'nuwiki_wiki_root', '~/vimwiki')))
|
|
let l:ext = get(l:w, 'file_extension',
|
|
\ get(g:, 'nuwiki_file_extension', '.wiki'))
|
|
if l:ext[0] !=# '.' | let l:ext = '.' . l:ext | endif
|
|
let l:idx = get(l:w, 'index', 'index')
|
|
let l:diary_rel = get(l:w, 'diary_rel_path',
|
|
\ get(g:, 'nuwiki_diary_rel_path', 'diary'))
|
|
let l:diary_idx = get(l:w, 'diary_index', 'diary')
|
|
return { 'root': l:root, 'ext': l:ext, 'idx': l:idx,
|
|
\ 'diary_rel': l:diary_rel, 'diary_idx': l:diary_idx }
|
|
endfunction
|