From d634473980603509fb3fe974f2d504fe008ba0a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Fri, 15 Jan 2021 17:58:41 +0100 Subject: [PATCH] Add utility functions for editing vimwiki review templates --- symlinks/vim/plugin/vimwiki_reviews.vim | 34 +++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/symlinks/vim/plugin/vimwiki_reviews.vim b/symlinks/vim/plugin/vimwiki_reviews.vim index 31d321d..ae4e3f2 100644 --- a/symlinks/vim/plugin/vimwiki_reviews.vim +++ b/symlinks/vim/plugin/vimwiki_reviews.vim @@ -15,6 +15,29 @@ function! s:GetReviewsDir(...) return l:vimwiki.path . 'reviews/' endfunction +" Finds review template path for provided review type +function! s: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') +endfunction + +" Edits monthly review template +function! s:OpenReviewMonthlyTemplate(...) + let reviews_dir = call('s:GetReviewsDir', a:000) + execute 'edit ' . s: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') +endfunction + " Reads template for provided review type into current buffer " Uses overrides in form of files in reviews directory " Looks for file named template-{review_type}.md: @@ -25,8 +48,9 @@ endfunction " Currently supported variables are: " - %date% (Puts different date based on review type) function! s:ReadReviewTemplateIntoBuffer(vimwiki_reviews_path, review_type) - if filereadable(a:vimwiki_reviews_path + 'template-' + a:review_type . '.md') - execute 'read ' . a:vimwiki_reviews_path . 'template-' + a:review_type . '.md' + let template_path = s:GetReviewTemplatePath(a:vimwiki_reviews_path, a:review_type) + if filereadable(l:template_path) + execute 'read ' . l:template_path else if a:review_type == 'week' call setline(1, '#%date% Weekly Review') @@ -93,11 +117,17 @@ function! s:VimwikiReviewIndex(...) 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() nnoremap wrw :VimwikiWeeklyReview +nnoremap wrwt :VimwikiWeeklyTemplate nnoremap wrm :VimwikiMonthlyReview +nnoremap wrmt :VimwikiMonthlyTemplate nnoremap wry :VimwikiYearlyReview +nnoremap wryt :VimwikiYearlyTemplate nnoremap wri :VimwikiReviewIndex