1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-09 14:30:06 +08:00

Add toggle whitespace mappings SPC t w

This commit is contained in:
wsdjeg 2017-05-23 22:56:31 +08:00
parent 529b482b40
commit 0a914e2b92
4 changed files with 28 additions and 4 deletions

View File

@ -5,7 +5,7 @@ function! s:self.build(left_sections, right_sections, lsep, rsep, hi_a, hi_b, hi
let l = '%#' . a:hi_a . '#' . a:left_sections[0] let l = '%#' . a:hi_a . '#' . a:left_sections[0]
let l .= '%#' . a:hi_a . '_' . a:hi_b . '#' . a:lsep let l .= '%#' . a:hi_a . '_' . a:hi_b . '#' . a:lsep
let flag = 1 let flag = 1
for sec in a:left_sections[1:] for sec in filter(a:left_sections[1:], '!empty(v:val)')
if flag == 1 if flag == 1
let l .= '%#' . a:hi_b . '#' . sec let l .= '%#' . a:hi_b . '#' . sec
let l .= '%#' . a:hi_b . '_' . a:hi_c . '#' . a:lsep let l .= '%#' . a:hi_b . '_' . a:hi_c . '#' . a:lsep
@ -30,7 +30,7 @@ function! s:self.build(left_sections, right_sections, lsep, rsep, hi_a, hi_b, hi
endif endif
let l .= '%#' . a:hi_b . '_' . a:hi_z . '#' . a:rsep let l .= '%#' . a:hi_b . '_' . a:hi_z . '#' . a:rsep
let flag = 1 let flag = 1
for sec in a:right_sections for sec in filter(a:right_sections, '!empty(v:val)')
if flag == 1 if flag == 1
let l .= '%#' . a:hi_b . '#' . sec let l .= '%#' . a:hi_b . '#' . sec
let l .= '%#' . a:hi_c . '_' . a:hi_b . '#' . a:rsep let l .= '%#' . a:hi_c . '_' . a:hi_b . '#' . a:rsep

View File

@ -47,6 +47,10 @@ let s:modes = {
\ 'icon' : s:MESSLETTERS.circled_letter('S'), \ 'icon' : s:MESSLETTERS.circled_letter('S'),
\ 'desc' : 'spell-checking mode', \ 'desc' : 'spell-checking mode',
\ }, \ },
\ 'whitespace' :{
\ 'icon' : s:MESSLETTERS.circled_letter('w'),
\ 'desc' : 'whitespace mode',
\ },
\ } \ }
let s:loaded_sections = ['syntax checking', 'major mode', 'minor mode lighters', 'version control info'] let s:loaded_sections = ['syntax checking', 'major mode', 'minor mode lighters', 'version control info']
@ -109,13 +113,22 @@ function! s:git_branch() abort
return '' return ''
endfunction endfunction
function! s:whitespace() abort
let ln = search('\s\+$', 'n')
if ln != 0
return ' trailing[' . ln . '] '
else
return ''
endif
endfunction
function! s:modes() abort function! s:modes() abort
let m = ' ❖ ' let m = ' ❖ '
for mode in s:loaded_modes for mode in s:loaded_modes
let m .= s:modes[mode].icon . ' ' let m .= s:modes[mode].icon . ' '
endfor endfor
return m return m . ' '
endfunction endfunction
function! s:filesize() abort function! s:filesize() abort
@ -179,6 +192,9 @@ function! s:active() abort
call add(rsec, s:time()) call add(rsec, s:time())
endif endif
if index(s:loaded_sections, 'whitespace') != -1
call add(rsec, s:whitespace())
endif
return s:STATUSLINE.build(lsec, rsec, s:lsep, s:rsep, return s:STATUSLINE.build(lsec, rsec, s:lsep, s:rsep,
\ 'SpaceVim_statusline_a', 'SpaceVim_statusline_b', 'SpaceVim_statusline_c', 'SpaceVim_statusline_z') \ 'SpaceVim_statusline_a', 'SpaceVim_statusline_b', 'SpaceVim_statusline_c', 'SpaceVim_statusline_z')
endfunction endfunction

View File

@ -70,6 +70,9 @@ function! SpaceVim#layers#ui#config() abort
call SpaceVim#mapping#space#def('nnoremap', ['t', 'S'], 'call call(' call SpaceVim#mapping#space#def('nnoremap', ['t', 'S'], 'call call('
\ . string(s:_function('s:toggle_spell_check')) . ', [])', \ . string(s:_function('s:toggle_spell_check')) . ', [])',
\ 'toggle syntax checker', 1) \ 'toggle syntax checker', 1)
call SpaceVim#mapping#space#def('nnoremap', ['t', 'w'], 'call call('
\ . string(s:_function('s:toggle_whitespace')) . ', [])',
\ 'toggle the whitespace', 1)
endfunction endfunction
" function() wrapper " function() wrapper
if v:version > 703 || v:version == 703 && has('patch1170') if v:version > 703 || v:version == 703 && has('patch1170')
@ -201,3 +204,8 @@ function! s:toggle_spell_check() abort
endif endif
call SpaceVim#layers#core#statusline#toggle_mode('spell-checking') call SpaceVim#layers#core#statusline#toggle_mode('spell-checking')
endfunction endfunction
function! s:toggle_whitespace() abort
call SpaceVim#layers#core#statusline#toggle_section('whitespace')
call SpaceVim#layers#core#statusline#toggle_mode('whitespace')
endfunction