Merge remote-tracking branch 'origin/calendar-support' into feature-gap
# Conflicts: # development/vimwiki-gap.md
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
" 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; dir is 'V' for a vertical split (any
|
||||
" other value means a horizontal split). week is unused.
|
||||
" 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
|
||||
@@ -0,0 +1,14 @@
|
||||
" autoload/vimwiki/diary.vim — vimwiki namespace aliases for nuwiki diary functions
|
||||
" Provides drop-in compatibility for vimwiki-dependent plugins like calendar-vim
|
||||
|
||||
" vimwiki#diary#calendar_action(day, month, year, week, dir)
|
||||
" Alias to nuwiki#diary#calendar_action for calendar-vim compatibility
|
||||
function! vimwiki#diary#calendar_action(day, month, year, week, dir) abort
|
||||
return nuwiki#diary#calendar_action(a:day, a:month, a:year, a:week, a:dir)
|
||||
endfunction
|
||||
|
||||
" vimwiki#diary#calendar_sign(day, month, year)
|
||||
" Alias to nuwiki#diary#calendar_sign for calendar-vim compatibility
|
||||
function! vimwiki#diary#calendar_sign(day, month, year) abort
|
||||
return nuwiki#diary#calendar_sign(a:day, a:month, a:year)
|
||||
endfunction
|
||||
Reference in New Issue
Block a user