From 0008a752ab509c6f67a746041eedd3e5120b0a7f Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Sun, 16 Sep 2018 13:54:57 +0800 Subject: [PATCH] Fix toggle cursorline (#2171) --- autoload/SpaceVim/autocmds.vim | 24 +++++++++++++++++------- autoload/SpaceVim/layers/ui.vim | 15 +++++++++++++-- config/plugins/ctrlp.vim | 2 +- test/color/SpaceVim.vader | 6 ++++-- wiki/en/Following-HEAD.md | 1 + 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/autoload/SpaceVim/autocmds.vim b/autoload/SpaceVim/autocmds.vim index 09ad4cd97..4c4808d18 100644 --- a/autoload/SpaceVim/autocmds.vim +++ b/autoload/SpaceVim/autocmds.vim @@ -20,8 +20,8 @@ function! SpaceVim#autocmds#init() abort autocmd WinEnter * call SpaceVim#plugins#windowsmanager#MarkBaseWin() autocmd BufRead,BufNewFile *.pp setfiletype puppet if g:spacevim_enable_cursorline == 1 - autocmd BufEnter,WinEnter,InsertLeave * setl cursorline - autocmd BufLeave,WinLeave,InsertEnter * setl nocursorline + autocmd BufEnter,WinEnter,InsertLeave * call s:enable_cursorline() + autocmd BufLeave,WinLeave,InsertEnter * call s:disable_cursorline() endif if g:spacevim_enable_cursorcolumn == 1 autocmd BufEnter,WinEnter,InsertLeave * setl cursorcolumn @@ -64,6 +64,16 @@ function! SpaceVim#autocmds#init() abort augroup END endfunction +function! s:enable_cursorline() abort + if g:_spacevim_cursorline_flag == -1 + setl cursorline + endif +endfunction + +function! s:disable_cursorline() abort + setl nocursorline +endfunction + function! s:reload_touchpad_status() abort if s:touchpadoff call s:disable_touchpad() @@ -147,11 +157,11 @@ function! SpaceVim#autocmds#VimEnter() abort endif call SpaceVim#plugins#projectmanager#RootchandgeCallback() if !empty(get(g:, '_spacevim_bootstrap_after', '')) - try - call call(g:_spacevim_bootstrap_after, []) - catch - call SpaceVim#logger#error('failed to call bootstrap_after function: ' . g:_spacevim_bootstrap_after) - endtry + try + call call(g:_spacevim_bootstrap_after, []) + catch + call SpaceVim#logger#error('failed to call bootstrap_after function: ' . g:_spacevim_bootstrap_after) + endtry endif endfunction diff --git a/autoload/SpaceVim/layers/ui.vim b/autoload/SpaceVim/layers/ui.vim index 38f1491e5..a46992ee8 100644 --- a/autoload/SpaceVim/layers/ui.vim +++ b/autoload/SpaceVim/layers/ui.vim @@ -60,8 +60,13 @@ function! SpaceVim#layers#ui#config() abort call SpaceVim#mapping#space#def('nnoremap', ['t', 'f'], 'call call(' \ . string(s:_function('s:toggle_colorcolumn')) . ', [])', \ 'fill-column-indicator', 1) - call SpaceVim#mapping#space#def('nnoremap', ['t', 'h', 'h'], 'set cursorline!', - \ 'toggle highlight of the current line', 1) + call SpaceVim#mapping#space#def('nnoremap', ['t', 'h', 'h'], 'call call(' + \ . string(s:_function('s:toggle_cursorline')) . ', [])', + \ ['toggle highlight of the current line', + \ [ + \ 'SPC t h h is to toggle the highlighting of cursorline' + \ ] + \ ], 1) call SpaceVim#mapping#space#def('nnoremap', ['t', 'h', 'i'], 'call call(' \ . string(s:_function('s:toggle_indentline')) . ', [])', \ ['toggle highlight indentation levels', @@ -213,6 +218,12 @@ function! s:toggle_win_fringe() abort endif endfunction +let g:_spacevim_cursorline_flag = -1 +function! s:toggle_cursorline() abort + setl cursorline! + let g:_spacevim_cursorline_flag = g:_spacevim_cursorline_flag * -1 +endfunction + function! s:toggle_spell_check() abort if &l:spell let &l:spell = 0 diff --git a/config/plugins/ctrlp.vim b/config/plugins/ctrlp.vim index 4b392678c..d57c05bbe 100644 --- a/config/plugins/ctrlp.vim +++ b/config/plugins/ctrlp.vim @@ -18,7 +18,7 @@ let g:ctrlp_custom_ignore = get(g:, 'ctrlp_custom_ignore', { \ }) if executable('rg') && !exists('g:ctrlp_user_command') let g:ctrlp_user_command = 'rg %s --no-ignore --hidden --files -g "" ' - \ . join(zvim#util#Generate_ignore(g:spacevim_wildignore,'rg', 1)) + \ . join(zvim#util#Generate_ignore(get(g:, 'spacevim_wildignore', ''),'rg', 1)) elseif executable('ag') && !exists('g:ctrlp_user_command') let g:ctrlp_user_command = 'ag --hidden -i -g "" ' . join(zvim#util#Generate_ignore(g:spacevim_wildignore,'ag')) . ' %s' endif diff --git a/test/color/SpaceVim.vader b/test/color/SpaceVim.vader index 4c5e633f9..5ceb13f3a 100644 --- a/test/color/SpaceVim.vader +++ b/test/color/SpaceVim.vader @@ -1,5 +1,7 @@ Execute ( SpaceVim colorscheme ): - let g:current_colors = g:colors_name + let g:current_colors = get(g:, 'colors_name', '') colorscheme SpaceVim AssertEqual g:colors_name, 'SpaceVim' - exe 'colorscheme ' . g:current_colors + if !empty(g:current_colors) + exe 'colorscheme ' . g:current_colors + endif diff --git a/wiki/en/Following-HEAD.md b/wiki/en/Following-HEAD.md index 13a085cc6..76db09e2a 100644 --- a/wiki/en/Following-HEAD.md +++ b/wiki/en/Following-HEAD.md @@ -82,6 +82,7 @@ The next release is v0.9.0. - Fix active statusline displaying fileformat info ([#2125](https://github.com/SpaceVim/SpaceVim/pull/2125)) - Fix unkown v:progpath ([#2169](https://github.com/SpaceVim/SpaceVim/pull/2169)) - Fix builtin statusline theme ([#2170](https://github.com/SpaceVim/SpaceVim/pull/2170)) +- Fix toggle cursorline highlighting ([#2171](https://github.com/SpaceVim/SpaceVim/pull/2171)) ### Removed