diff --git a/symlinks/vim/plugin/vimwiki_reviews.vim b/symlinks/vim/plugin/vimwiki_reviews.vim index 6322e30..1be8e66 100644 --- a/symlinks/vim/plugin/vimwiki_reviews.vim +++ b/symlinks/vim/plugin/vimwiki_reviews.vim @@ -5,37 +5,42 @@ " ----------------------------------------------------------------------------- " Gets path to reviews dir of provided vimwiki (by index) -function! s:GetReviewsDir(...) - if a:0 == 0 - let l:vimwiki = g:vimwiki_list[0] +function! GetReviewsDir(vimwiki_index) + if a:vimwiki_index == 0 + let l:current_index = vimwiki#vars#get_bufferlocal('wiki_nr') + if (l:current_index < 0) + let l:current_index = 0 + end + + let l:vimwiki = g:vimwiki_list[l:current_index] else - let l:vimwiki = g:vimwiki_list[str2nr(a:1) - 1] + let l:vimwiki = g:vimwiki_list[a:vimwiki_index - 1] endif return l:vimwiki.path . 'reviews/' endfunction " Finds review template path for provided review type -function! s:GetReviewTemplatePath(vimwiki_reviews_path, review_type) +function! GetReviewTemplatePath(vimwiki_reviews_path, review_type) return a:vimwiki_reviews_path . 'template-' . a:review_type . '.md' endfunction " Edits weekly review template -function! s:OpenReviewWeeklyTemplate(...) - let reviews_dir = call('s:GetReviewsDir', a:000) - execute 'edit ' . s:GetReviewTemplatePath(l:reviews_dir, 'week') +function! OpenReviewWeeklyTemplate(vimwiki_index) + let reviews_dir = GetReviewsDir(a:vimwiki_index) + execute 'edit ' . GetReviewTemplatePath(l:reviews_dir, 'week') endfunction " Edits monthly review template -function! s:OpenReviewMonthlyTemplate(...) - let reviews_dir = call('s:GetReviewsDir', a:000) - execute 'edit ' . s:GetReviewTemplatePath(l:reviews_dir, 'month') +function! OpenReviewMonthlyTemplate(vimwiki_index) + let reviews_dir = GetReviewsDir(a:vimwiki_index) + execute 'edit ' . GetReviewTemplatePath(l:reviews_dir, 'month') endfunction " Edits yearly review template -function! s:OpenReviewYearlyTemplate(...) - let reviews_dir = call('s:GetReviewsDir', a:000) - execute 'edit ' . s:GetReviewTemplatePath(l:reviews_dir, 'year') +function! OpenReviewYearlyTemplate(vimwiki_index) + let reviews_dir = GetReviewsDir(a:vimwiki_index) + execute 'edit ' . GetReviewTemplatePath(l:reviews_dir, 'year') endfunction " Reads template for provided review type into current buffer @@ -47,8 +52,8 @@ endfunction " Templates can use variables using %variable% syntax " Currently supported variables are: " - %date% (Puts different date based on review type) -function! s:ReadReviewTemplateIntoBuffer(vimwiki_reviews_path, review_type) - let template_path = s:GetReviewTemplatePath(a:vimwiki_reviews_path, a:review_type) +function! ReadReviewTemplateIntoBuffer(vimwiki_reviews_path, review_type) + let template_path = GetReviewTemplatePath(a:vimwiki_reviews_path, a:review_type) if filereadable(glob(l:template_path)) execute 'read ' . l:template_path else @@ -65,15 +70,15 @@ endfunction " Open current week weekly review file " Created buffer is dated to Sunday of current week " Opens current week because Sunday is good time to do this review -function! s:VimwikiWeeklyReview(...) - let reviews_dir = call('s:GetReviewsDir', a:000) +function! VimwikiWeeklyReview(vimwiki_index) + let reviews_dir = GetReviewsDir(a:vimwiki_index) let days_to_sunday = 7 - str2nr(strftime('%u')) let week_date = strftime('%Y-%m-%d', localtime() + l:days_to_sunday * 24 * 60 * 60) let file_name = l:reviews_dir . l:week_date . '-week.md' let exists = filereadable(glob(l:file_name)) execute 'edit ' . l:file_name if exists == v:false - call s:ReadReviewTemplateIntoBuffer(l:reviews_dir, 'week') + call ReadReviewTemplateIntoBuffer(l:reviews_dir, 'week') execute '%substitute/%date%/' . l:week_date endif endfunction @@ -83,51 +88,52 @@ endfunction " Created buffer is dated to previous month " Previous month is calculated in an erroneous way " 28 days are subtracted from current time to get previous month -function! s:VimwikiMonthlyReview(...) - let reviews_dir = call('s:GetReviewsDir', a:000) +function! VimwikiMonthlyReview(vimwiki_index) + let reviews_dir = GetReviewsDir(a:vimwiki_index) let month_time = localtime() - 28 * 24 * 60 * 60 let month_date = strftime('%Y-%m', l:month_time) let file_name = l:reviews_dir . l:month_date .'-month.md' let exists = filereadable(glob(l:file_name)) execute 'edit ' . l:file_name if exists == v:false - call s:ReadReviewTemplateIntoBuffer(l:reviews_dir, 'month') + call ReadReviewTemplateIntoBuffer(l:reviews_dir, 'month') execute '%substitute/%date%/' . strftime('%Y %B', l:month_time) endif endfunction " Open past year yearly review file " Created buffer is dated to previous year -function! s:VimwikiYearlyReview(...) - let reviews_dir = call('s:GetReviewsDir', a:000) +function! VimwikiYearlyReview(vimwiki_index) + let reviews_dir = GetReviewsDir(a:vimwiki_index) let year_date = (str2nr(strftime('%Y')) - 1) let file_name = l:reviews_dir . l:year_date .'-year.md' let exists = filereadable(glob(l:file_name)) execute 'edit ' . l:file_name if exists == v:false - call s:ReadReviewTemplateIntoBuffer(l:reviews_dir, 'year') + call ReadReviewTemplateIntoBuffer(l:reviews_dir, 'year') execute '%substitute/%date%/' . l:year_date endif endfunction " Open reviews index file -function! s:VimwikiReviewIndex(...) - let reviews_dir = call('s:GetReviewsDir', a:000) +function! VimwikiReviewIndex(vimwiki_index) + let reviews_dir = GetReviewsDir(a:vimwiki_index) execute 'edit ' . l:reviews_dir . 'reviews.md' endfunction -command! -nargs=? VimwikiWeeklyReview :call s:VimwikiWeeklyReview() -command! -nargs=? VimwikiWeeklyTemplate :call s:OpenReviewWeeklyTemplate() -command! -nargs=? VimwikiMonthlyReview :call s:VimwikiMonthlyReview() -command! -nargs=? VimwikiMonthlyTemplate :call s:OpenReviewMonthlyTemplate() -command! -nargs=? VimwikiYearlyReview :call s:VimwikiYearlyReview() -command! -nargs=? VimwikiYearlyTemplate :call s:OpenReviewYearlyTemplate() -command! -nargs=? VimwikiReviewIndex :call s:VimwikiReviewIndex() +command! -count=0 VimwikiWeeklyReview :call VimwikiWeeklyReview() +command! -count=0 VimwikiWeeklyTemplate :call OpenReviewWeeklyTemplate() +command! -count=0 VimwikiMonthlyReview :call VimwikiMonthlyReview() +command! -count=0 VimwikiMonthlyTemplate :call OpenReviewMonthlyTemplate() +command! -count=0 VimwikiYearlyReview :call VimwikiYearlyReview() +command! -count=0 VimwikiYearlyTemplate :call OpenReviewYearlyTemplate() +command! -count=0 VimwikiReviewIndex :call VimwikiReviewIndex() -nnoremap wrw :VimwikiWeeklyReview -nnoremap wrtw :VimwikiWeeklyTemplate -nnoremap wrm :VimwikiMonthlyReview -nnoremap wrtm :VimwikiMonthlyTemplate -nnoremap wry :VimwikiYearlyReview -nnoremap wrty :VimwikiYearlyTemplate -nnoremap wri :VimwikiReviewIndex +" TODO - Move functions to autoload +nnoremap wrw call VimwikiWeeklyReview(v:count) +nnoremap wrtw call OpenReviewWeeklyTemplate(v:count) +nnoremap wrm call VimwikiMonthlyReview(v:count) +nnoremap wrtm call OpenReviewMonthlyTemplate(v:count) +nnoremap wry call VimwikiYearlyReview(v:count) +nnoremap wrty call OpenReviewYearlyTemplate(v:count) +nnoremap wri call VimwikiReviewIndex(v:count)