Fix problems with commands not taking a count and mapping behavior.

Commands such as :VimwikiIndex and :VimwikiDiaryIndex did not previously
take a count and the doucmentation was inconsistent/incorrect for the
behavior of these commands. Fixes #543.
This commit is contained in:
Rane Brown 2019-03-30 19:12:56 -06:00 committed by Henry Qin
parent 1ba99ae135
commit 3396e87dbe
4 changed files with 100 additions and 75 deletions

View File

@ -1287,19 +1287,23 @@ endfunction
function! vimwiki#base#goto_index(wnum, ...) function! vimwiki#base#goto_index(wnum, ...)
" if wnum = 0 the current wiki is used
if a:wnum == 0
let idx = vimwiki#vars#get_bufferlocal('wiki_nr')
echom idx
if idx < 0 " not in a wiki
let idx = 0
endif
else
let idx = a:wnum - 1 " convert to 0 based counting
endif
if a:wnum > vimwiki#vars#number_of_wikis() if a:wnum > vimwiki#vars#number_of_wikis()
echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in your Vimwiki settings!' echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in your Vimwiki settings!'
return return
endif endif
" usually a:wnum is greater then 0 but with the following command it is == 0:
" vim -n -c ":VimwikiIndex"
if a:wnum > 0
let idx = a:wnum - 1
else
let idx = 0
endif
if a:0 if a:0
if a:1 == 1 if a:1 == 1
let cmd = 'tabedit' let cmd = 'tabedit'

View File

@ -220,8 +220,6 @@ function! vimwiki#diary#make_note(wnum, ...)
return return
endif endif
" TODO: refactor it. base#goto_index uses the same
call vimwiki#path#mkdir(vimwiki#vars#get_wikilocal('path', wiki_nr). call vimwiki#path#mkdir(vimwiki#vars#get_wikilocal('path', wiki_nr).
\ vimwiki#vars#get_wikilocal('diary_rel_path', wiki_nr)) \ vimwiki#vars#get_wikilocal('diary_rel_path', wiki_nr))
@ -244,20 +242,23 @@ function! vimwiki#diary#make_note(wnum, ...)
call vimwiki#base#open_link(cmd, link, s:diary_index(wiki_nr)) call vimwiki#base#open_link(cmd, link, s:diary_index(wiki_nr))
endfunction endfunction
function! vimwiki#diary#goto_diary_index(wnum) function! vimwiki#diary#goto_diary_index(wnum)
" if wnum = 0 the current wiki is used
if a:wnum == 0
let idx = vimwiki#vars#get_bufferlocal('wiki_nr')
if idx < 0 " not in a wiki
let idx = 0
endif
else
let idx = a:wnum - 1 " convert to 0 based counting
endif
if a:wnum > vimwiki#vars#number_of_wikis() if a:wnum > vimwiki#vars#number_of_wikis()
echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in g:vimwiki_list!' echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in g:vimwiki_list!'
return return
endif 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#base#edit_file('e', s:diary_index(idx), '') call vimwiki#base#edit_file('e', s:diary_index(idx), '')
if vimwiki#vars#get_wikilocal('auto_diary_index') if vimwiki#vars#get_wikilocal('auto_diary_index')

View File

@ -149,9 +149,9 @@ See also |:VimwikiUISelect|
[count]<Leader>wi or <Plug>VimwikiDiaryIndex [count]<Leader>wi or <Plug>VimwikiDiaryIndex
Open diary index file of the [count]'s wiki. Open diary index file of the [count]'s wiki.
<Leader>wi opens diary index file of the first wiki from <Leader>wi opens diary index file of the current wiki.
1<Leader>wi opens diary index file of the first wiki from
|g:vimwiki_list|. |g:vimwiki_list|.
1<Leader>wi the same as above.
2<Leader>wi opens diary index file of the second wiki from 2<Leader>wi opens diary index file of the second wiki from
|g:vimwiki_list|. |g:vimwiki_list|.
etc. etc.
@ -164,10 +164,9 @@ See also |:VimwikiDiaryIndex|
[count]<Leader>w<Leader>w or <Plug>VimwikiMakeDiaryNote [count]<Leader>w<Leader>w or <Plug>VimwikiMakeDiaryNote
Open diary wiki-file for today of the [count]'s wiki. Open diary wiki-file for today of the [count]'s wiki.
<Leader>w<Leader>w opens diary wiki-file for today in the first wiki <Leader>w<Leader>w opens diary wiki-file for today in the current wiki
1<Leader>w<Leader>w opens diary wiki-file for today in the first wiki
from |g:vimwiki_list|. from |g:vimwiki_list|.
1<Leader>w<Leader>w as above opens diary wiki-file for today in the
first wiki from |g:vimwiki_list|.
2<Leader>w<Leader>w opens diary wiki-file for today in the second wiki 2<Leader>w<Leader>w opens diary wiki-file for today in the second wiki
from |g:vimwiki_list|. from |g:vimwiki_list|.
3<Leader>w<Leader>w opens diary wiki-file for today in the third wiki 3<Leader>w<Leader>w opens diary wiki-file for today in the third wiki
@ -182,9 +181,9 @@ See also |:VimwikiMakeDiaryNote|
[count]<Leader>w<Leader>t or <Plug>VimwikiTabMakeDiaryNote [count]<Leader>w<Leader>t or <Plug>VimwikiTabMakeDiaryNote
Open diary wiki-file for today of the [count]'s wiki in a new tab. Open diary wiki-file for today of the [count]'s wiki in a new tab.
<Leader>w<Leader>t tabopens diary wiki-file for today in the first <Leader>w<Leader>t tabopens diary wiki-file for today in the current
wiki from |g:vimwiki_list|. wiki
1<Leader>w<Leader>t as above tabopens diary wiki-file for today in the 1<Leader>w<Leader>t tabopens diary wiki-file for today in the
first wiki from |g:vimwiki_list|. first wiki from |g:vimwiki_list|.
2<Leader>w<Leader>t tabopens diary wiki-file for today in the second 2<Leader>w<Leader>t tabopens diary wiki-file for today in the second
wiki from |g:vimwiki_list|. wiki from |g:vimwiki_list|.
@ -200,10 +199,10 @@ See also |:VimwikiTabMakeDiaryNote|
[count]<Leader>w<Leader>y or <Plug>VimwikiMakeYesterdayDiaryNote [count]<Leader>w<Leader>y or <Plug>VimwikiMakeYesterdayDiaryNote
Open diary wiki-file for yesterday of the [count]'s wiki. Open diary wiki-file for yesterday of the [count]'s wiki.
<Leader>w<Leader>y opens diary wiki-file for yesterday in the first <Leader>w<Leader>y opens diary wiki-file for yesterday in the current
wiki
1<Leader>w<Leader>y opens diary wiki-file for yesterday in the first
wiki from |g:vimwiki_list|. wiki from |g:vimwiki_list|.
1<Leader>w<Leader>y as above opens diary wiki-file for yesterday in
the first wiki from |g:vimwiki_list|.
2<Leader>w<Leader>y opens diary wiki-file for yesterday in the second 2<Leader>w<Leader>y opens diary wiki-file for yesterday in the second
wiki from |g:vimwiki_list|. wiki from |g:vimwiki_list|.
3<Leader>w<Leader>y opens diary wiki-file for yesterday in the third 3<Leader>w<Leader>y opens diary wiki-file for yesterday in the third
@ -217,10 +216,10 @@ See also |:VimwikiMakeYesterdayDiaryNote|
[count]<Leader>w<Leader>m or <Plug>VimwikiMakeTomorrowDiaryNote [count]<Leader>w<Leader>m or <Plug>VimwikiMakeTomorrowDiaryNote
Open diary wiki-file for tomorrow of the [count]'s wiki. Open diary wiki-file for tomorrow of the [count]'s wiki.
<Leader>w<Leader>m opens diary wiki-file for tomorrow in the first <Leader>w<Leader>m opens diary wiki-file for tomorrow in the current
wiki
1<Leader>w<Leader>m opens diary wiki-file for tomorrow in the first
wiki from |g:vimwiki_list|. wiki from |g:vimwiki_list|.
1<Leader>w<Leader>m as above opens diary wiki-file for tomorrow in
the first wiki from |g:vimwiki_list|.
2<Leader>w<Leader>m opens diary wiki-file for tomorrow in the second 2<Leader>w<Leader>m opens diary wiki-file for tomorrow in the second
wiki from |g:vimwiki_list|. wiki from |g:vimwiki_list|.
3<Leader>w<Leader>m opens diary wiki-file for tomorrow in the third 3<Leader>w<Leader>m opens diary wiki-file for tomorrow in the third
@ -653,29 +652,41 @@ il A single list item.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
4.1. Global Commands *vimwiki-global-commands* 4.1. Global Commands *vimwiki-global-commands*
*:VimwikiIndex* *:VimwikiIndex* [count]
Open index file of the current wiki. Open index file of the current wiki. If a [count] is given the
corresponding wiki from |g:vimwiki_list| is opened instead.
*:VimwikiTabIndex* *:VimwikiTabIndex* [count]
Open index file of the current wiki in a new tab. Open index file of the current wiki in a new tab. If a [count] is given
the corresponding wiki from |g:vimwiki_list| is opened instead.
*:VimwikiUISelect* *:VimwikiUISelect*
Open index file of the selected wiki. Displays a list of registered wikis and opens the index file of the
selected wiki.
*:VimwikiDiaryIndex* *:VimwikiDiaryIndex* [count]
Open diary index file of the current wiki. Open diary index file of the current wiki. If a [count] is given the
corresponding wiki from |g:vimwiki_list| is opened instead.
*:VimwikiMakeDiaryNote* *:VimwikiMakeDiaryNote* [count]
Open diary wiki-file for today of the current wiki. Open diary wiki-file for today of the current wiki. If a [count] is given
a diary wiki-file for the corresponding wiki from |g:vimwiki_list| is
opened instead.
*:VimwikiTabMakeDiaryNote* *:VimwikiTabMakeDiaryNote* [count]
Open diary wiki-file for today of the current wiki in a new tab. Open diary wiki-file for today of the current wiki in a new tab. If
a [count] is given a diary wiki-file for the corresponding wiki from
|g:vimwiki_list| is opened instead.
*:VimwikiMakeYesterdayDiaryNote* *:VimwikiMakeYesterdayDiaryNote* [count]
Open diary wiki-file for yesterday of the current wiki. Open diary wiki-file for yesterday of the current wiki. If a [count] is
given a diary wiki-file for the corresponding wiki from |g:vimwiki_list|
is opened instead.
*:VimwikiMakeTomorrowDiaryNote* *:VimwikiMakeTomorrowDiaryNote* [count]
Open diary wiki-file for tomorrow of the current wiki. Open diary wiki-file for tomorrow of the current wiki. If a [count] is
given a diary wiki-file for the corresponding wiki from |g:vimwiki_list|
is opened instead.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
4.2. Local commands *vimwiki-local-commands* 4.2. Local commands *vimwiki-local-commands*

View File

@ -194,8 +194,7 @@ endfunction
function! s:get_version() function! s:get_version()
if s:plugin_vers != -1 if s:plugin_vers != -1 echo "Stable version: " . s:plugin_vers
echo "Stable version: " . s:plugin_vers
else else
let a:plugin_rev = system("git --git-dir " . s:plugin_dir . "/.git rev-parse --short HEAD") let a:plugin_rev = system("git --git-dir " . s:plugin_dir . "/.git rev-parse --short HEAD")
let a:plugin_branch = system("git --git-dir " . s:plugin_dir . "/.git rev-parse --abbrev-ref HEAD") let a:plugin_branch = system("git --git-dir " . s:plugin_dir . "/.git rev-parse --abbrev-ref HEAD")
@ -280,24 +279,31 @@ augroup END
command! VimwikiUISelect call vimwiki#base#ui_select() command! VimwikiUISelect call vimwiki#base#ui_select()
" why not using <count> instead of v:count1?
" See https://github.com/vimwiki-backup/vimwiki/issues/324
command! -count=1 VimwikiIndex
\ call vimwiki#base#goto_index(v:count1)
command! -count=1 VimwikiTabIndex
\ call vimwiki#base#goto_index(v:count1, 1)
command! -count=1 VimwikiDiaryIndex " these commands take a count e.g. :VimwikiIndex 2
\ call vimwiki#diary#goto_diary_index(v:count1) " the default behavior is to open the index, diary etc.
command! -count=1 VimwikiMakeDiaryNote " for the CURRENT wiki if no count is given
\ call vimwiki#diary#make_note(v:count) command! -count=0 VimwikiIndex
command! -count=1 VimwikiTabMakeDiaryNote \ call vimwiki#base#goto_index(<count>)
\ call vimwiki#diary#make_note(v:count, 1)
command! -count=1 VimwikiMakeYesterdayDiaryNote command! -count=0 VimwikiTabIndex
\ call vimwiki#diary#make_note(v:count, 0, \ call vimwiki#base#goto_index(<count>, 1)
command! -count=0 VimwikiDiaryIndex
\ call vimwiki#diary#goto_diary_index(<count>)
command! -count=0 VimwikiMakeDiaryNote
\ call vimwiki#diary#make_note(<count>)
command! -count=0 VimwikiTabMakeDiaryNote
\ call vimwiki#diary#make_note(<count>, 1)
command! -count=0 VimwikiMakeYesterdayDiaryNote
\ call vimwiki#diary#make_note(<count>, 0,
\ vimwiki#diary#diary_date_link(localtime() - 60*60*24)) \ vimwiki#diary#diary_date_link(localtime() - 60*60*24))
command! -count=1 VimwikiMakeTomorrowDiaryNote
\ call vimwiki#diary#make_note(v:count, 0, command! -count=0 VimwikiMakeTomorrowDiaryNote
\ call vimwiki#diary#make_note(<count>, 0,
\ vimwiki#diary#diary_date_link(localtime() + 60*60*24)) \ vimwiki#diary#diary_date_link(localtime() + 60*60*24))
command! VimwikiDiaryGenerateLinks command! VimwikiDiaryGenerateLinks
@ -305,19 +311,19 @@ command! VimwikiDiaryGenerateLinks
command! VimwikiShowVersion call s:get_version() command! VimwikiShowVersion call s:get_version()
let s:map_prefix = vimwiki#vars#get_global('map_prefix') let s:map_prefix = vimwiki#vars#get_global('map_prefix')
if !hasmapto('<Plug>VimwikiIndex') && maparg(s:map_prefix.'w', 'n') == "" if !hasmapto('<Plug>VimwikiIndex') && maparg(s:map_prefix.'w', 'n') == ""
exe 'nmap <silent><unique> '.s:map_prefix.'w <Plug>VimwikiIndex' exe 'nmap <silent><unique> '.s:map_prefix.'w <Plug>VimwikiIndex'
endif endif
nnoremap <unique><script> <Plug>VimwikiIndex :VimwikiIndex<CR> nnoremap <unique><script> <Plug>VimwikiIndex
\ :<C-U>call vimwiki#base#goto_index(v:count1)<CR>
if !hasmapto('<Plug>VimwikiTabIndex') && maparg(s:map_prefix.'t', 'n') == "" if !hasmapto('<Plug>VimwikiTabIndex') && maparg(s:map_prefix.'t', 'n') == ""
exe 'nmap <silent><unique> '.s:map_prefix.'t <Plug>VimwikiTabIndex' exe 'nmap <silent><unique> '.s:map_prefix.'t <Plug>VimwikiTabIndex'
endif endif
nnoremap <unique><script> <Plug>VimwikiTabIndex :VimwikiTabIndex<CR> nnoremap <unique><script> <Plug>VimwikiTabIndex
\ :<C-U>call vimwiki#base#goto_index(v:count1, 1)<CR>
if !hasmapto('<Plug>VimwikiUISelect') && maparg(s:map_prefix.'s', 'n') == "" if !hasmapto('<Plug>VimwikiUISelect') && maparg(s:map_prefix.'s', 'n') == ""
exe 'nmap <silent><unique> '.s:map_prefix.'s <Plug>VimwikiUISelect' exe 'nmap <silent><unique> '.s:map_prefix.'s <Plug>VimwikiUISelect'
@ -327,7 +333,8 @@ nnoremap <unique><script> <Plug>VimwikiUISelect :VimwikiUISelect<CR>
if !hasmapto('<Plug>VimwikiDiaryIndex') && maparg(s:map_prefix.'i', 'n') == "" if !hasmapto('<Plug>VimwikiDiaryIndex') && maparg(s:map_prefix.'i', 'n') == ""
exe 'nmap <silent><unique> '.s:map_prefix.'i <Plug>VimwikiDiaryIndex' exe 'nmap <silent><unique> '.s:map_prefix.'i <Plug>VimwikiDiaryIndex'
endif endif
nnoremap <unique><script> <Plug>VimwikiDiaryIndex :VimwikiDiaryIndex<CR> nnoremap <unique><script> <Plug>VimwikiDiaryIndex
\ :<C-U>call vimwiki#diary#goto_diary_index(v:count)<CR>
if !hasmapto('<Plug>VimwikiDiaryGenerateLinks') && maparg(s:map_prefix.'<Leader>i', 'n') == "" if !hasmapto('<Plug>VimwikiDiaryGenerateLinks') && maparg(s:map_prefix.'<Leader>i', 'n') == ""
exe 'nmap <silent><unique> '.s:map_prefix.'<Leader>i <Plug>VimwikiDiaryGenerateLinks' exe 'nmap <silent><unique> '.s:map_prefix.'<Leader>i <Plug>VimwikiDiaryGenerateLinks'
@ -337,26 +344,28 @@ nnoremap <unique><script> <Plug>VimwikiDiaryGenerateLinks :VimwikiDiaryGenerateL
if !hasmapto('<Plug>VimwikiMakeDiaryNote') && maparg(s:map_prefix.'<Leader>w', 'n') == "" if !hasmapto('<Plug>VimwikiMakeDiaryNote') && maparg(s:map_prefix.'<Leader>w', 'n') == ""
exe 'nmap <silent><unique> '.s:map_prefix.'<Leader>w <Plug>VimwikiMakeDiaryNote' exe 'nmap <silent><unique> '.s:map_prefix.'<Leader>w <Plug>VimwikiMakeDiaryNote'
endif endif
nnoremap <unique><script> <Plug>VimwikiMakeDiaryNote :VimwikiMakeDiaryNote<CR> nnoremap <unique><script> <Plug>VimwikiMakeDiaryNote
\ :<C-U>call vimwiki#diary#make_note(v:count)<CR>
if !hasmapto('<Plug>VimwikiTabMakeDiaryNote') && maparg(s:map_prefix.'<Leader>t', 'n') == "" if !hasmapto('<Plug>VimwikiTabMakeDiaryNote') && maparg(s:map_prefix.'<Leader>t', 'n') == ""
exe 'nmap <silent><unique> '.s:map_prefix.'<Leader>t <Plug>VimwikiTabMakeDiaryNote' exe 'nmap <silent><unique> '.s:map_prefix.'<Leader>t <Plug>VimwikiTabMakeDiaryNote'
endif endif
nnoremap <unique><script> <Plug>VimwikiTabMakeDiaryNote nnoremap <unique><script> <Plug>VimwikiTabMakeDiaryNote
\ :VimwikiTabMakeDiaryNote<CR> \ :<C-U>call vimwiki#diary#make_note(v:count, 1)<CR>
if !hasmapto('<Plug>VimwikiMakeYesterdayDiaryNote') && maparg(s:map_prefix.'<Leader>y', 'n') == "" if !hasmapto('<Plug>VimwikiMakeYesterdayDiaryNote') && maparg(s:map_prefix.'<Leader>y', 'n') == ""
exe 'nmap <silent><unique> '.s:map_prefix.'<Leader>y <Plug>VimwikiMakeYesterdayDiaryNote' exe 'nmap <silent><unique> '.s:map_prefix.'<Leader>y <Plug>VimwikiMakeYesterdayDiaryNote'
endif endif
nnoremap <unique><script> <Plug>VimwikiMakeYesterdayDiaryNote nnoremap <unique><script> <Plug>VimwikiMakeYesterdayDiaryNote
\ :VimwikiMakeYesterdayDiaryNote<CR> \ :<C-U>call vimwiki#diary#make_note(v:count, 0,
\ vimwiki#diary#diary_date_link(localtime() - 60*60*24))<CR>
if !hasmapto('<Plug>VimwikiMakeTomorrowDiaryNote') if !hasmapto('<Plug>VimwikiMakeTomorrowDiaryNote')
exe 'nmap <silent><unique> '.s:map_prefix.'<Leader>m <Plug>VimwikiMakeTomorrowDiaryNote' exe 'nmap <silent><unique> '.s:map_prefix.'<Leader>m <Plug>VimwikiMakeTomorrowDiaryNote'
endif endif
nnoremap <unique><script> <Plug>VimwikiMakeTomorrowDiaryNote nnoremap <unique><script> <Plug>VimwikiMakeTomorrowDiaryNote
\ :VimwikiMakeTomorrowDiaryNote<CR> \ :<C-U>call vimwiki#diary#make_note(v:count, 0,
\ vimwiki#diary#diary_date_link(localtime() + 60*60*24))<CR>