1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 17:40:06 +08:00

Update key binding guide (#3753)

This commit is contained in:
Wang Shidong 2020-09-02 22:56:53 +08:00 committed by GitHub
parent 61452f00ae
commit 3e58a7efdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 86 additions and 53 deletions

View File

@ -5,6 +5,7 @@
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================
scriptencoding utf-8
let s:AUTODOC = SpaceVim#api#import('dev#autodoc')
@ -68,7 +69,7 @@ endfunction
function! SpaceVim#dev#roadmap#updateCompletedItems(lang) abort
let s:AUTODOC.begin = '^<!-- SpaceVim roadmap completed items start -->$'
let s:AUTODOC.end = '^<!-- SpaceVim roadmap completed items end -->$'
if a:lang == 'cn'
if a:lang ==# 'cn'
let s:AUTODOC.content_func = function('s:generate_content_cn')
else
let s:AUTODOC.content_func = function('s:generate_content')

View File

@ -8,6 +8,7 @@ if [ "$TRAVIS_PULL_REQUEST" != "false" ] ; then
rm -rf build/GitHub.vim
fi
VIMLINT_LOG=`cat build_log`
echo $VIMLINT_LOG
git clone https://github.com/wsdjeg/GitHub.vim.git build/GitHub.vim
docker run \
-it --rm \
@ -19,12 +20,25 @@ if [ "$TRAVIS_PULL_REQUEST" != "false" ] ; then
spacevim/vims vim8 -u /.ci/common/github_commenter.vim
rm build_log
fi
elif [ "$LINT" = "vimlint" ] ; then
if [[ -f build_log ]]; then
VIMLINT_LOG=`cat build_log`
echo $VIMLINT_LOG
rm build_log
fi
elif [ "$LINT" = "vint" ] ; then
if [[ -f build_log ]]; then
VIMLINT_LOG=`cat build_log`
echo $VIMLINT_LOG
rm build_log
fi
elif [ "$LINT" = "vint-errors" ] ; then
if [[ -f build_log ]]; then
if [[ -d build/GitHub.vim ]]; then
rm -rf build/GitHub.vim
fi
VIMLINT_LOG=`cat build_log`
echo $VIMLINT_LOG
git clone https://github.com/wsdjeg/GitHub.vim.git build/GitHub.vim
docker run -it --rm \
-e TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST} \

View File

@ -3,10 +3,16 @@
set -ex
export TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST}
if [ "$LINT" = "vimlint" ]; then
if [[ -f build_log ]]; then
rm build_log
fi
for file in $(git ls-files | grep SpaceVim.*.vim);
do
sh /tmp/vimlint/bin/vimlint.sh -l /tmp/vimlint -p /tmp/vimlparser $file;
/tmp/vimlint/bin/vimlint.sh -l /tmp/vimlint -p /tmp/vimlparser $file >> build_log 2>&1;
done
if [[ -s build_log ]]; then
exit 2
fi
elif [ "$LINT" = "vimlint-errors" ]; then
if [[ -f build_log ]]; then
rm build_log
@ -16,13 +22,11 @@ elif [ "$LINT" = "vimlint-errors" ]; then
/tmp/vimlint/bin/vimlint.sh -E -l /tmp/vimlint -p /tmp/vimlparser $file >> build_log 2>&1;
done
if [[ -s build_log ]]; then
VIMLINT_LOG=`cat build_log`
echo "$VIMLINT_LOG"
exit 2
fi
elif [ "$LINT" = "file-encoding" ]; then
if [[ -f encoding_log ]]; then
rm encoding_log
if [[ -f build_log ]]; then
rm build_log
fi
for file in $(git diff --name-only HEAD master);
do
@ -32,12 +36,10 @@ elif [ "$LINT" = "file-encoding" ]; then
encoding=`file -b --mime-encoding $file`
if [ $encoding != "utf-8" ] && [ $encoding != "us-ascii" ];
then
echo $file " " $encoding >> encoding_log
echo $file " " $encoding >> build_log
fi
done
if [[ -s encoding_log ]]; then
VIMLINT_LOG=`cat encoding_log`
echo "$VIMLINT_LOG"
if [[ -s build_log ]]; then
exit 2
fi
elif [ "$LINT" = "vint" ]; then
@ -49,8 +51,6 @@ elif [ "$LINT" = "vint" ]; then
vint --enable-neovim $file >> build_log 2>&1;
done
if [[ -s build_log ]]; then
VIMLINT_LOG=`cat build_log`
echo "$VIMLINT_LOG"
exit 2
fi
elif [ "$LINT" = "vint-errors" ]; then
@ -62,8 +62,6 @@ elif [ "$LINT" = "vint-errors" ]; then
vint --enable-neovim --error $file >> build_log 2>&1;
done
if [[ -s build_log ]]; then
VIMLINT_LOG=`cat build_log`
echo "$VIMLINT_LOG"
exit 2
fi
elif [ "$LINT" = "vader" ]; then

View File

@ -185,6 +185,29 @@ function! s:self.is_blob(var) abort
return type(a:var) ==# 10
endfunction
if has('nvim')
function! s:self.getchar(...) abort
if !empty(get(g:, '_spacevim_input_list', []))
sleep 1000m
return remove(g:_spacevim_input_list, 0)
endif
let ret = call('getchar', a:000)
return (type(ret) == type(0) ? nr2char(ret) : ret)
endfunction
else
function! s:self.getchar(...) abort
if !empty(get(g:, '_spacevim_input_list', []))
sleep 1000m
return remove(g:_spacevim_input_list, 0)
endif
let ret = call('getchar', a:000)
while ret ==# "\x80\xfd\d"
let ret = call('getchar', a:000)
endwhile
return (type(ret) == type(0) ? nr2char(ret) : ret)
endfunction
endif
function! SpaceVim#api#vim#get() abort
return deepcopy(s:self)
endfunction

View File

@ -30,6 +30,10 @@ let s:SL = SpaceVim#api#import('vim#statusline')
let s:winid = -1
let s:bufnr = -1
let s:prefix_key_inp = []
let s:lmap = {}
" this should be the history of s:lmap and s:guide_group
let s:undo_history = []
function! SpaceVim#mapping#guide#has_configuration() abort "{{{
return exists('s:desc_lookup')
@ -436,10 +440,9 @@ function! s:handle_input(input) abort " {{{
call s:winclose()
if type(a:input) ==? type({})
let s:lmap = a:input
let s:guide_group = a:input
call s:start_buffer()
else
let s:prefix_key_inp = ''
let s:prefix_key_inp = []
call feedkeys(s:vis.s:reg.s:count, 'ti')
redraw!
try
@ -450,29 +453,13 @@ function! s:handle_input(input) abort " {{{
endif
endfunction " }}}
if has('nvim')
function! s:getchar(...) abort
let ret = call('getchar', a:000)
return (type(ret) == type(0) ? nr2char(ret) : ret)
endfunction
else
function! s:getchar(...) abort
let ret = call('getchar', a:000)
while ret ==# "\x80\xfd\d"
let ret = call('getchar', a:000)
endwhile
return (type(ret) == type(0) ? nr2char(ret) : ret)
endfunction
endif
" wait for in input sub function should be not block vim
function! s:wait_for_input() abort " {{{
redraw!
let inp = s:getchar()
let inp = s:VIM.getchar()
if inp ==# "\<Esc>"
let s:prefix_key_inp = ''
let s:prefix_key_inp = []
let s:undo_history = []
let s:guide_help_mode = 0
call s:winclose()
doautocmd WinEnter
@ -492,20 +479,21 @@ function! s:wait_for_input() abort " {{{
endif
let fsel = get(s:lmap, inp)
if !empty(fsel)
let s:prefix_key_inp = inp
call add(s:prefix_key_inp, inp)
call add(s:undo_history, s:lmap)
call s:handle_input(fsel)
else
call s:winclose()
doautocmd WinEnter
let keys = get(s:, 'prefix_key_inp', '')
let keys = get(s:, 'prefix_key_inp', [])
let name = SpaceVim#mapping#leader#getName(s:prefix_key)
let _keys = join(s:STR.string2chars(keys), '-')
let _keys = join(keys, '')
if empty(_keys)
call s:build_mpt(['key bindings is not defined: ', name . '-' . inp])
else
call s:build_mpt(['key bindings is not defined: ', name . '-' . _keys . '-' . inp])
endif
let s:prefix_key_inp = ''
let s:prefix_key_inp = []
let s:guide_help_mode = 0
endif
endif
@ -603,13 +591,13 @@ if s:SL.support_float()
let gname = ' - ' . gname[1:]
" let gname = substitute(gname,' ', '\\ ', 'g')
endif
let keys = get(s:, 'prefix_key_inp', '')
let keys = get(s:, 'prefix_key_inp', [])
" let keys = substitute(keys, '\', '\\\', 'g')
noautocmd let winid = s:SL.open_float([
\ ['Guide: ', 'LeaderGuiderPrompt'],
\ [' ', 'LeaderGuiderSep1'],
\ [SpaceVim#mapping#leader#getName(s:prefix_key)
\ . keys . gname, 'LeaderGuiderName'],
\ . join(keys, '') . gname, 'LeaderGuiderName'],
\ [' ', 'LeaderGuiderSep2'],
\ [s:guide_help_msg(0), 'LeaderGuiderFill'],
\ [repeat(' ', 999), 'LeaderGuiderFill'],
@ -627,12 +615,12 @@ else
if !empty(gname)
let gname = ' - ' . gname[1:]
endif
let keys = get(s:, 'prefix_key_inp', '')
let keys = get(s:, 'prefix_key_inp', [])
call setbufvar(s:bufnr, '&statusline', '%#LeaderGuiderPrompt# Guide: ' .
\ '%#LeaderGuiderSep1#' . s:lsep .
\ '%#LeaderGuiderName# ' .
\ SpaceVim#mapping#leader#getName(s:prefix_key)
\ . keys . gname
\ . join(keys, '') . gname
\ . ' %#LeaderGuiderSep2#' . s:lsep . '%#LeaderGuiderFill#'
\ . s:guide_help_msg(0))
endfunction
@ -690,9 +678,12 @@ function! s:page_down() abort " {{{
endfunction " }}}
function! s:page_undo() abort " {{{
call s:winclose()
let s:guide_group = {}
let s:prefix_key_inp = ''
let s:lmap = s:lmap_undo
if len(s:prefix_key_inp) > 0
call remove(s:prefix_key_inp, -1)
endif
if len(s:undo_history) > 0
let s:lmap = remove(s:undo_history, -1)
endif
call s:start_buffer()
endfunction " }}}
function! s:page_up() abort " {{{
@ -767,7 +758,6 @@ function! SpaceVim#mapping#guide#start_by_prefix(vis, key) abort " {{{
let rundict = s:cached_dicts[a:key]
endif
let s:lmap = rundict
let s:lmap_undo = rundict
call s:start_buffer()
endfunction " }}}
function! SpaceVim#mapping#guide#start(vis, dict) abort " {{{
@ -787,7 +777,7 @@ if !exists('g:leaderGuide_displayfunc')
endif
let s:registered_name = {}
function! SpaceVim#mapping#guide#register_displayname(lhs, name)
function! SpaceVim#mapping#guide#register_displayname(lhs, name) abort
call extend(s:registered_name, {a:lhs : a:name})
endfunction

View File

@ -7,6 +7,7 @@
"=============================================================================
let s:KEY = SpaceVim#api#import('vim#key')
let s:VIM = SpaceVim#api#import('vim')
let s:TABs = SpaceVim#api#import('vim#tab')
let s:key_describ = {}
@ -27,8 +28,8 @@ function! SpaceVim#plugins#help#describe_key() abort
let prompt = 'Describe key:'
let keys = []
call s:build_mpt(prompt)
let key = getchar()
let char = s:KEY.nr2name(key)
let key = s:VIM.getchar()
let char = s:KEY.nr2name(char2nr(key))
if index(keys(g:_spacevim_mappings_prefixs), char) != -1
let name = SpaceVim#mapping#leader#getName(nr2char(key))
else
@ -56,8 +57,8 @@ function! SpaceVim#plugins#help#describe_key() abort
let defined = 0
endif
while defined
let key = getchar()
let name = s:KEY.nr2name(key)
let key = s:VIM.getchar()
let name = s:KEY.nr2name(char2nr(key))
call add(keys, name)
if has_key(root, name)
let root = root[name]

5
test/plugin/guide.vader Normal file
View File

@ -0,0 +1,5 @@
Execute ( SpaceVim key binding guide ):
let g:_spacevim_input_list = ['h', 'd', 'k', ' ', 'b', 'n']
LeaderGuide " "
AssertEqual &ft, 'HelpDescribe'

View File

@ -1,4 +1,5 @@
Execute ( SpaceVim plugin: a.vim ):
Execute ( SpaceVim plugin: tabmanager.vim ):
call SpaceVim#plugins#tabmanager#open()
LeaderGuide " "
AssertEqual &ft, 'SpaceVimTabsManager'