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