:VimwikiMakeDiaryNote makes a new note in the current wiki

... like the doc says, instead of always using the first wiki.
Also, fix the menu entry, which always led to the wrong diary.

Fix #482
This commit is contained in:
EinfachToll 2018-05-17 20:06:27 +02:00
parent c08a9f8c71
commit 057fa39303
2 changed files with 20 additions and 17 deletions

View File

@ -170,21 +170,25 @@ function! s:format_diary()
endfunction
" The given wiki number a:wnum is 1 for the first wiki, 2 for the second and so on. This is in
" contrast to most other places, where counting starts with 0. When a:wnum is 0, the current wiki
" is used.
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!'
if a:wnum == 0
let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr')
else
let wiki_nr = a:wnum - 1
endif
if wiki_nr >= vimwiki#vars#number_of_wikis()
echomsg 'Vimwiki Error: Wiki '.wiki_nr.' is not registered in g:vimwiki_list!'
return
endif
" TODO: refactor it. base#goto_index uses the same
if a:wnum > 0
let idx = a:wnum - 1
else
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', wiki_nr).
\ vimwiki#vars#get_wikilocal('diary_rel_path', wiki_nr))
let cmd = 'edit'
if a:0
@ -202,7 +206,7 @@ function! vimwiki#diary#make_note(wnum, ...)
let link = 'diary:'.vimwiki#diary#diary_date_link()
endif
call vimwiki#base#open_link(cmd, link, s:diary_index(idx))
call vimwiki#base#open_link(cmd, link, s:diary_index(wiki_nr))
endfunction
@ -297,8 +301,7 @@ function! vimwiki#diary#calendar_action(day, month, year, week, dir)
endif
endif
" XXX: Well, +1 is for inconsistent index basing...
call vimwiki#diary#make_note(vimwiki#vars#get_bufferlocal('wiki_nr')+1, 0, link)
call vimwiki#diary#make_note(0, 0, link)
endfunction

View File

@ -266,14 +266,14 @@ command! -count=1 VimwikiTabIndex
command! -count=1 VimwikiDiaryIndex
\ call vimwiki#diary#goto_diary_index(v:count1)
command! -count=1 VimwikiMakeDiaryNote
\ call vimwiki#diary#make_note(v:count1)
\ call vimwiki#diary#make_note(v:count)
command! -count=1 VimwikiTabMakeDiaryNote
\ call vimwiki#diary#make_note(v:count1, 1)
\ call vimwiki#diary#make_note(v:count, 1)
command! -count=1 VimwikiMakeYesterdayDiaryNote
\ call vimwiki#diary#make_note(v:count1, 0,
\ call vimwiki#diary#make_note(v:count, 0,
\ vimwiki#diary#diary_date_link(localtime() - 60*60*24))
command! -count=1 VimwikiMakeTomorrowDiaryNote
\ call vimwiki#diary#make_note(v:count1, 0,
\ call vimwiki#diary#make_note(v:count, 0,
\ vimwiki#diary#diary_date_link(localtime() + 60*60*24))
command! VimwikiDiaryGenerateLinks
@ -341,7 +341,7 @@ function! s:build_menu(topmenu)
execute 'menu '.a:topmenu.'.Open\ index.'.norm_path.
\ ' :call vimwiki#base#goto_index('.idx.')<CR>'
execute 'menu '.a:topmenu.'.Open/Create\ diary\ note.'.norm_path.
\ ' :call vimwiki#diary#make_note('.idx.')<CR>'
\ ' :call vimwiki#diary#make_note('.(idx+1).')<CR>'
endfor
endfunction