Ensure key mappings defined in ftplugin are buffer specific.

The changes made with #686 did not ensure the ftplugin mappings were
specific to the buffer containing a Vimwiki file. This resulted in
undesired keymappings with no defined behavior since the <Plug>
definition was buffer specific.
This commit is contained in:
Rane Brown 2019-04-29 23:03:00 -06:00
parent bb15cd1aff
commit 50a3c78c87
2 changed files with 21 additions and 13 deletions

View File

@ -73,19 +73,27 @@ endif
" a:mode single character indicating the mode as defined by :h maparg
" a:key the key sequence to map
" a:plug the plug command the key sequence should be mapped to
" a:1 optional argument to override the uniqueness checks
" a:1 optional argument with the following functionality:
" if a:1==1 then the hasmapto(<Plug>) check is skipped.
" this can be used to map different keys to the same <Plug> definition
" if a:1==2 then the mapping is not <buffer> specific
" This function maps a key sequence to a <Plug> command using the arguments
" described above. If there is already a mapping to the <Plug> command or
" the assigned keys are already mapped then nothing is done.
function vimwiki#u#map_key(mode, key, plug, ...)
if a:0 > 0 && a:1 == 1
if a:0 && a:1 == 2
let l:bo = ''
else
let l:bo = '<buffer> '
endif
if a:0 && a:1 == 1
if maparg(a:key, a:mode) ==# ''
exe a:mode . 'map ' . a:key . ' ' . a:plug
exe a:mode . 'map ' . l:bo . a:key . ' ' . a:plug
endif
else
if !hasmapto(a:plug) && maparg(a:key, a:mode) ==# ''
exe a:mode . 'map ' . a:key . ' ' . a:plug
exe a:mode . 'map ' . l:bo . a:key . ' ' . a:plug
endif
endif
endfunction

View File

@ -399,15 +399,15 @@ let s:map_prefix = vimwiki#vars#get_global('map_prefix')
" default global key mappings
if str2nr(vimwiki#vars#get_global('key_mappings').global)
call vimwiki#u#map_key('n', s:map_prefix . 'w', '<Plug>VimwikiIndex')
call vimwiki#u#map_key('n', s:map_prefix . 't', '<Plug>VimwikiTabIndex')
call vimwiki#u#map_key('n', s:map_prefix . 's', '<Plug>VimwikiUISelect')
call vimwiki#u#map_key('n', s:map_prefix . 'i', '<Plug>VimwikiDiaryIndex')
call vimwiki#u#map_key('n', s:map_prefix . '<Leader>i', '<Plug>VimwikiDiaryGenerateLinks')
call vimwiki#u#map_key('n', s:map_prefix . '<Leader>w', '<Plug>VimwikiMakeDiaryNote')
call vimwiki#u#map_key('n', s:map_prefix . '<Leader>t', '<Plug>VimwikiTabMakeDiaryNote')
call vimwiki#u#map_key('n', s:map_prefix . '<Leader>y', '<Plug>VimwikiMakeYesterdayDiaryNote')
call vimwiki#u#map_key('n', s:map_prefix . '<Leader>m', '<Plug>VimwikiMakeTomorrowDiaryNote')
call vimwiki#u#map_key('n', s:map_prefix . 'w', '<Plug>VimwikiIndex', 2)
call vimwiki#u#map_key('n', s:map_prefix . 't', '<Plug>VimwikiTabIndex', 2)
call vimwiki#u#map_key('n', s:map_prefix . 's', '<Plug>VimwikiUISelect', 2)
call vimwiki#u#map_key('n', s:map_prefix . 'i', '<Plug>VimwikiDiaryIndex', 2)
call vimwiki#u#map_key('n', s:map_prefix . '<Leader>i', '<Plug>VimwikiDiaryGenerateLinks', 2)
call vimwiki#u#map_key('n', s:map_prefix . '<Leader>w', '<Plug>VimwikiMakeDiaryNote', 2)
call vimwiki#u#map_key('n', s:map_prefix . '<Leader>t', '<Plug>VimwikiTabMakeDiaryNote', 2)
call vimwiki#u#map_key('n', s:map_prefix . '<Leader>y', '<Plug>VimwikiMakeYesterdayDiaryNote', 2)
call vimwiki#u#map_key('n', s:map_prefix . '<Leader>m', '<Plug>VimwikiMakeTomorrowDiaryNote', 2)
endif