Remove foldmarkers; general reformatting
This commit is contained in:
@ -1,44 +1,49 @@
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=99
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
|
||||
" Vimwiki autoload plugin file
|
||||
" Desc: Handle diary notes
|
||||
" Description: Handle diary notes
|
||||
" Home: https://github.com/vimwiki/vimwiki/
|
||||
|
||||
" Load only once {{{
|
||||
|
||||
if exists("g:loaded_vimwiki_diary_auto") || &cp
|
||||
finish
|
||||
endif
|
||||
let g:loaded_vimwiki_diary_auto = 1
|
||||
"}}}
|
||||
|
||||
|
||||
let s:vimwiki_max_scan_for_caption = 5
|
||||
|
||||
" Helpers {{{
|
||||
function! s:prefix_zero(num) "{{{
|
||||
|
||||
function! s:prefix_zero(num)
|
||||
if a:num < 10
|
||||
return '0'.a:num
|
||||
endif
|
||||
return a:num
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:diary_path(...) "{{{
|
||||
|
||||
function! s:diary_path(...)
|
||||
let idx = a:0 == 0 ? vimwiki#vars#get_bufferlocal('wiki_nr') : a:1
|
||||
return vimwiki#vars#get_wikilocal('path', idx).vimwiki#vars#get_wikilocal('diary_rel_path', idx)
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:diary_index(...) "{{{
|
||||
|
||||
function! s:diary_index(...)
|
||||
let idx = a:0 == 0 ? vimwiki#vars#get_bufferlocal('wiki_nr') : a:1
|
||||
return s:diary_path(idx).vimwiki#vars#get_wikilocal('diary_index', idx).vimwiki#vars#get_wikilocal('ext', idx)
|
||||
endfunction "}}}
|
||||
return s:diary_path(idx).vimwiki#vars#get_wikilocal('diary_index', idx).
|
||||
\ vimwiki#vars#get_wikilocal('ext', idx)
|
||||
endfunction
|
||||
|
||||
function! vimwiki#diary#diary_date_link(...) "{{{
|
||||
|
||||
function! vimwiki#diary#diary_date_link(...)
|
||||
if a:0
|
||||
return strftime('%Y-%m-%d', a:1)
|
||||
else
|
||||
return strftime('%Y-%m-%d')
|
||||
endif
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:get_position_links(link) "{{{
|
||||
|
||||
function! s:get_position_links(link)
|
||||
let idx = -1
|
||||
let links = []
|
||||
if a:link =~# '^\d\{4}-\d\d-\d\d'
|
||||
@ -51,16 +56,15 @@ function! s:get_position_links(link) "{{{
|
||||
let idx = index(links, a:link)
|
||||
endif
|
||||
return [idx, links]
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
fun! s:get_month_name(month) "{{{
|
||||
|
||||
function! s:get_month_name(month)
|
||||
return vimwiki#vars#get_global('diary_months')[str2nr(a:month)]
|
||||
endfun "}}}
|
||||
endfunction
|
||||
|
||||
" Helpers }}}
|
||||
|
||||
" Diary index stuff {{{
|
||||
fun! s:read_captions(files) "{{{
|
||||
function! s:read_captions(files)
|
||||
let result = {}
|
||||
let rx_header = vimwiki#vars#get_syntaxlocal('rxHeader')
|
||||
for fl in a:files
|
||||
@ -81,11 +85,13 @@ fun! s:read_captions(files) "{{{
|
||||
|
||||
endfor
|
||||
return result
|
||||
endfun "}}}
|
||||
endfunction
|
||||
|
||||
fun! s:get_diary_files() "{{{
|
||||
|
||||
function! s:get_diary_files()
|
||||
let rx = '^\d\{4}-\d\d-\d\d'
|
||||
let s_files = glob(vimwiki#vars#get_wikilocal('path').vimwiki#vars#get_wikilocal('diary_rel_path').'*'.vimwiki#vars#get_wikilocal('ext'))
|
||||
let s_files = glob(vimwiki#vars#get_wikilocal('path').
|
||||
\ vimwiki#vars#get_wikilocal('diary_rel_path').'*'.vimwiki#vars#get_wikilocal('ext'))
|
||||
let files = split(s_files, '\n')
|
||||
call filter(files, 'fnamemodify(v:val, ":t") =~# "'.escape(rx, '\').'"')
|
||||
|
||||
@ -93,9 +99,10 @@ fun! s:get_diary_files() "{{{
|
||||
call filter(files, 'v:val !~# ''.*\~$''')
|
||||
|
||||
return files
|
||||
endfun "}}}
|
||||
endfunction
|
||||
|
||||
fun! s:group_links(links) "{{{
|
||||
|
||||
function! s:group_links(links)
|
||||
let result = {}
|
||||
let p_year = 0
|
||||
let p_month = 0
|
||||
@ -114,38 +121,43 @@ fun! s:group_links(links) "{{{
|
||||
let p_month = month
|
||||
endfor
|
||||
return result
|
||||
endfun "}}}
|
||||
endfunction
|
||||
|
||||
function! s:sort(lst) "{{{
|
||||
|
||||
function! s:sort(lst)
|
||||
if vimwiki#vars#get_wikilocal('diary_sort') ==? 'desc'
|
||||
return reverse(sort(a:lst))
|
||||
else
|
||||
return sort(a:lst)
|
||||
endif
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:format_diary() "{{{
|
||||
|
||||
function! s:format_diary()
|
||||
let result = []
|
||||
|
||||
|
||||
let links_with_captions = s:read_captions(s:get_diary_files())
|
||||
let g_files = s:group_links(links_with_captions)
|
||||
|
||||
for year in s:sort(keys(g_files))
|
||||
call add(result, '')
|
||||
call add(result, substitute(vimwiki#vars#get_syntaxlocal('rxH2_Template'), '__Header__', year , ''))
|
||||
call add(result,
|
||||
\ substitute(vimwiki#vars#get_syntaxlocal('rxH2_Template'), '__Header__', year , ''))
|
||||
|
||||
for month in s:sort(keys(g_files[year]))
|
||||
call add(result, '')
|
||||
call add(result, substitute(vimwiki#vars#get_syntaxlocal('rxH3_Template'), '__Header__', s:get_month_name(month), ''))
|
||||
call add(result, substitute(vimwiki#vars#get_syntaxlocal('rxH3_Template'),
|
||||
\ '__Header__', s:get_month_name(month), ''))
|
||||
|
||||
for [fl, cap] in s:sort(items(g_files[year][month]))
|
||||
if empty(cap)
|
||||
let entry = substitute(vimwiki#vars#get_global('WikiLinkTemplate1'), '__LinkUrl__', fl, '')
|
||||
let entry = substitute(vimwiki#vars#get_global('WikiLinkTemplate1'),
|
||||
\ '__LinkUrl__', fl, '')
|
||||
let entry = substitute(entry, '__LinkDescription__', cap, '')
|
||||
call add(result, repeat(' ', vimwiki#lst#get_list_margin()).'* '.entry)
|
||||
else
|
||||
let entry = substitute(vimwiki#vars#get_global('WikiLinkTemplate2'), '__LinkUrl__', fl, '')
|
||||
let entry = substitute(vimwiki#vars#get_global('WikiLinkTemplate2'),
|
||||
\ '__LinkUrl__', fl, '')
|
||||
let entry = substitute(entry, '__LinkDescription__', cap, '')
|
||||
call add(result, repeat(' ', vimwiki#lst#get_list_margin()).'* '.entry)
|
||||
endif
|
||||
@ -155,11 +167,10 @@ function! s:format_diary() "{{{
|
||||
endfor
|
||||
|
||||
return result
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
" Diary index stuff }}}
|
||||
|
||||
function! vimwiki#diary#make_note(wnum, ...) "{{{
|
||||
function! vimwiki#diary#make_note(wnum, ...)
|
||||
if a:wnum > vimwiki#vars#number_of_wikis()
|
||||
echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in g:vimwiki_list!'
|
||||
return
|
||||
@ -172,7 +183,8 @@ function! vimwiki#diary#make_note(wnum, ...) "{{{
|
||||
let idx = 0
|
||||
endif
|
||||
|
||||
call vimwiki#path#mkdir(vimwiki#vars#get_wikilocal('path', idx).vimwiki#vars#get_wikilocal('diary_rel_path', idx))
|
||||
call vimwiki#path#mkdir(vimwiki#vars#get_wikilocal('path', idx).
|
||||
\ vimwiki#vars#get_wikilocal('diary_rel_path', idx))
|
||||
|
||||
let cmd = 'edit'
|
||||
if a:0
|
||||
@ -191,9 +203,10 @@ function! vimwiki#diary#make_note(wnum, ...) "{{{
|
||||
endif
|
||||
|
||||
call vimwiki#base#open_link(cmd, link, s:diary_index(idx))
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#diary#goto_diary_index(wnum) "{{{
|
||||
|
||||
function! vimwiki#diary#goto_diary_index(wnum)
|
||||
if a:wnum > vimwiki#vars#number_of_wikis()
|
||||
echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in g:vimwiki_list!'
|
||||
return
|
||||
@ -207,9 +220,10 @@ function! vimwiki#diary#goto_diary_index(wnum) "{{{
|
||||
endif
|
||||
|
||||
call vimwiki#base#edit_file('e', s:diary_index(idx), '')
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#diary#goto_next_day() "{{{
|
||||
|
||||
function! vimwiki#diary#goto_next_day()
|
||||
let link = ''
|
||||
let [idx, links] = s:get_position_links(expand('%:t:r'))
|
||||
|
||||
@ -227,9 +241,10 @@ function! vimwiki#diary#goto_next_day() "{{{
|
||||
if len(link)
|
||||
call vimwiki#base#open_link(':e ', link)
|
||||
endif
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#diary#goto_prev_day() "{{{
|
||||
|
||||
function! vimwiki#diary#goto_prev_day()
|
||||
let link = ''
|
||||
let [idx, links] = s:get_position_links(expand('%:t:r'))
|
||||
|
||||
@ -247,9 +262,10 @@ function! vimwiki#diary#goto_prev_day() "{{{
|
||||
if len(link)
|
||||
call vimwiki#base#open_link(':e ', link)
|
||||
endif
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#diary#generate_diary_section() "{{{
|
||||
|
||||
function! vimwiki#diary#generate_diary_section()
|
||||
let current_file = vimwiki#path#path_norm(expand("%:p"))
|
||||
let diary_file = vimwiki#path#path_norm(s:diary_index())
|
||||
if vimwiki#path#is_equal(current_file, diary_file)
|
||||
@ -259,11 +275,11 @@ function! vimwiki#diary#generate_diary_section() "{{{
|
||||
else
|
||||
echomsg 'Vimwiki Error: You can generate diary links only in a diary index page!'
|
||||
endif
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
" Calendar.vim {{{
|
||||
" Callback function.
|
||||
function! vimwiki#diary#calendar_action(day, month, year, week, dir) "{{{
|
||||
|
||||
" Callback function for Calendar.vim
|
||||
function! vimwiki#diary#calendar_action(day, month, year, week, dir)
|
||||
let day = s:prefix_zero(a:day)
|
||||
let month = s:prefix_zero(a:month)
|
||||
|
||||
@ -283,16 +299,14 @@ function! vimwiki#diary#calendar_action(day, month, year, week, dir) "{{{
|
||||
|
||||
" XXX: Well, +1 is for inconsistent index basing...
|
||||
call vimwiki#diary#make_note(vimwiki#vars#get_bufferlocal('wiki_nr')+1, 0, link)
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
" Sign function.
|
||||
function vimwiki#diary#calendar_sign(day, month, year) "{{{
|
||||
|
||||
function vimwiki#diary#calendar_sign(day, month, year)
|
||||
let day = s:prefix_zero(a:day)
|
||||
let month = s:prefix_zero(a:month)
|
||||
let sfile = vimwiki#vars#get_wikilocal('path').vimwiki#vars#get_wikilocal('diary_rel_path').
|
||||
\ a:year.'-'.month.'-'.day.vimwiki#vars#get_wikilocal('ext')
|
||||
return filereadable(expand(sfile))
|
||||
endfunction "}}}
|
||||
|
||||
" Calendar.vim }}}
|
||||
endfunction
|
||||
|
||||
|
Reference in New Issue
Block a user