1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 22:30:04 +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 " URL: https://spacevim.org
" License: GPLv3 " License: GPLv3
"============================================================================= "=============================================================================
scriptencoding utf-8
let s:AUTODOC = SpaceVim#api#import('dev#autodoc') let s:AUTODOC = SpaceVim#api#import('dev#autodoc')
@ -68,7 +69,7 @@ endfunction
function! SpaceVim#dev#roadmap#updateCompletedItems(lang) abort function! SpaceVim#dev#roadmap#updateCompletedItems(lang) abort
let s:AUTODOC.begin = '^<!-- SpaceVim roadmap completed items start -->$' let s:AUTODOC.begin = '^<!-- SpaceVim roadmap completed items start -->$'
let s:AUTODOC.end = '^<!-- SpaceVim roadmap completed items end -->$' 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') let s:AUTODOC.content_func = function('s:generate_content_cn')
else else
let s:AUTODOC.content_func = function('s:generate_content') 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 rm -rf build/GitHub.vim
fi fi
VIMLINT_LOG=`cat build_log` VIMLINT_LOG=`cat build_log`
echo $VIMLINT_LOG
git clone https://github.com/wsdjeg/GitHub.vim.git build/GitHub.vim git clone https://github.com/wsdjeg/GitHub.vim.git build/GitHub.vim
docker run \ docker run \
-it --rm \ -it --rm \
@ -19,12 +20,25 @@ if [ "$TRAVIS_PULL_REQUEST" != "false" ] ; then
spacevim/vims vim8 -u /.ci/common/github_commenter.vim spacevim/vims vim8 -u /.ci/common/github_commenter.vim
rm build_log rm build_log
fi 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 elif [ "$LINT" = "vint-errors" ] ; then
if [[ -f build_log ]]; then if [[ -f build_log ]]; then
if [[ -d build/GitHub.vim ]]; then if [[ -d build/GitHub.vim ]]; then
rm -rf build/GitHub.vim rm -rf build/GitHub.vim
fi fi
VIMLINT_LOG=`cat build_log` VIMLINT_LOG=`cat build_log`
echo $VIMLINT_LOG
git clone https://github.com/wsdjeg/GitHub.vim.git build/GitHub.vim git clone https://github.com/wsdjeg/GitHub.vim.git build/GitHub.vim
docker run -it --rm \ docker run -it --rm \
-e TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST} \ -e TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST} \

View File

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

View File

@ -185,6 +185,29 @@ function! s:self.is_blob(var) abort
return type(a:var) ==# 10 return type(a:var) ==# 10
endfunction 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 function! SpaceVim#api#vim#get() abort
return deepcopy(s:self) return deepcopy(s:self)
endfunction endfunction

View File

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

View File

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