mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-02 22:30:04 +08:00
fix(core): fix major mode cache support
This commit is contained in:
parent
f61fc738f0
commit
f97e3e9f94
@ -16,6 +16,9 @@
|
||||
" name = 'core#statusline'
|
||||
" enable = false
|
||||
" <
|
||||
" @subsection Layer options
|
||||
"
|
||||
" - `major_mode_cache`: Enable/disable major mode cache, enabled by default.
|
||||
|
||||
scriptencoding utf-8
|
||||
|
||||
@ -109,6 +112,10 @@ let s:modes = {
|
||||
\ },
|
||||
\ }
|
||||
|
||||
" the major_mode will be cached by default.
|
||||
|
||||
let s:major_mode_cache = 1
|
||||
|
||||
if SpaceVim#layers#isLoaded('checkers')
|
||||
call add(s:loaded_modes, 'syntax-checking')
|
||||
endif
|
||||
@ -733,9 +740,9 @@ endfunction
|
||||
" \ 'desc' : 'centered-cursor mode',
|
||||
" \ },
|
||||
function! SpaceVim#layers#core#statusline#register_mode(mode) abort
|
||||
if has_key(s:modes, a:mode.key)
|
||||
if has_key(s:modes, a:mode.key) && has_key(a:mode, 'func')
|
||||
let s:modes[a:mode.key]['func'] = a:mode.func
|
||||
call SpaceVim#logger#info('the func has been added to mode:' . a:mode.key)
|
||||
call SpaceVim#logger#debug('register major mode function:' . a:mode.key)
|
||||
else
|
||||
let s:modes[a:mode.key] = a:mode
|
||||
endif
|
||||
@ -744,15 +751,17 @@ endfunction
|
||||
|
||||
|
||||
" This func is used to toggle major mode in statusline
|
||||
|
||||
function! SpaceVim#layers#core#statusline#toggle_mode(name) abort
|
||||
call SpaceVim#logger#debug('toggle major mode: ' . a:name)
|
||||
let mode = get(s:modes, a:name, {})
|
||||
call SpaceVim#logger#info('try to call func of mode:' . a:name)
|
||||
if empty(mode)
|
||||
call SpaceVim#logger#debug('can not find major mode: ' . a:name)
|
||||
return
|
||||
endif
|
||||
if has_key(mode, 'func')
|
||||
let done = call(mode.func, [])
|
||||
else
|
||||
let done = 1
|
||||
call SpaceVim#logger#info('no func found for mode:' . a:name)
|
||||
endif
|
||||
if index(s:loaded_modes, a:name) != -1
|
||||
call remove(s:loaded_modes, index(s:loaded_modes, a:name))
|
||||
@ -762,7 +771,9 @@ function! SpaceVim#layers#core#statusline#toggle_mode(name) abort
|
||||
endif
|
||||
endif
|
||||
let &l:statusline = SpaceVim#layers#core#statusline#get(1)
|
||||
call s:update_conf()
|
||||
if s:major_mode_cache
|
||||
call s:update_conf()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let s:section_old_pos = {
|
||||
@ -797,6 +808,10 @@ function! SpaceVim#layers#core#statusline#rsep() abort
|
||||
return get(s:separators, g:spacevim_statusline_separator, s:separators['arrow'])
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#layers#core#statusline#set_variable(var) abort
|
||||
let s:major_mode_cache = get(a:var, 'major_mode_cache', s:major_mode_cache)
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#layers#core#statusline#config() abort
|
||||
let [s:lsep , s:rsep] = get(s:separators, g:spacevim_statusline_separator, s:separators['arrow'])
|
||||
let [s:ilsep , s:irsep] = get(s:i_separators, g:spacevim_statusline_iseparator, s:i_separators['arrow'])
|
||||
@ -828,11 +843,14 @@ function! SpaceVim#layers#core#statusline#config() abort
|
||||
\ 'main': 'SpaceVim#layers#core#statusline#ctrlp',
|
||||
\ 'prog': 'SpaceVim#layers#core#statusline#ctrlp_status',
|
||||
\ }
|
||||
if filereadable(expand(g:spacevim_data_dir . 'SpaceVim/major_mode.json'))
|
||||
if filereadable(expand(g:spacevim_data_dir . 'SpaceVim/major_mode.json')) && s:major_mode_cache
|
||||
" the major mode is cashed in: ~\.cache\SpaceVim\major_mode.json
|
||||
call SpaceVim#logger#debug('load cache from major_mode.json')
|
||||
let conf = s:JSON.json_decode(join(readfile(expand(g:spacevim_data_dir . 'SpaceVim/major_mode.json'), ''), ''))
|
||||
for key in keys(conf)
|
||||
if conf[key]
|
||||
" this function should be called silent.
|
||||
call SpaceVim#logger#debug('cached major mode: ' . key)
|
||||
silent! call SpaceVim#layers#core#statusline#toggle_mode(key)
|
||||
endif
|
||||
endfor
|
||||
@ -840,11 +858,16 @@ function! SpaceVim#layers#core#statusline#config() abort
|
||||
endfunction
|
||||
|
||||
function! s:update_conf() abort
|
||||
call SpaceVim#logger#debug('write major mode to major_mode.json')
|
||||
let conf = {}
|
||||
for key in keys(s:modes)
|
||||
call extend(conf, {key : (index(s:loaded_modes, key) > -1 ? 1 : 0)})
|
||||
endfor
|
||||
call writefile([s:JSON.json_encode(conf)], expand(g:spacevim_data_dir . 'SpaceVim/major_mode.json'))
|
||||
if writefile([s:JSON.json_encode(conf)], expand(g:spacevim_data_dir . 'SpaceVim/major_mode.json')) == 0
|
||||
call SpaceVim#logger#debug('update major_mode.json done')
|
||||
else
|
||||
call SpaceVim#logger#debug('failed to update major_mode.json')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Arguments:
|
||||
|
@ -117,6 +117,8 @@ function! SpaceVim#layers#ui#plugins() abort
|
||||
|
||||
endfunction
|
||||
|
||||
let s:file = expand('<sfile>:~')
|
||||
let s:funcbeginline = expand('<slnum>') + 1
|
||||
function! SpaceVim#layers#ui#config() abort
|
||||
if g:spacevim_colorscheme_bg ==# 'dark'
|
||||
let g:indentLine_color_term = get(g:, 'indentLine_color_term', 239)
|
||||
@ -195,8 +197,8 @@ function! SpaceVim#layers#ui#config() abort
|
||||
\ 'call SpaceVim#mapping#SmartClose()')
|
||||
endif
|
||||
" Ui toggles
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['t', '8'], 'call call('
|
||||
\ . string(s:_function('s:toggle_fill_column')) . ', [])',
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['t', '8'],
|
||||
\ 'call SpaceVim#layers#core#statusline#toggle_mode("hi-characters-for-long-lines")',
|
||||
\ 'highlight-long-lines', 1)
|
||||
if g:spacevim_autocomplete_method ==# 'deoplete'
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['t', 'a'], 'call SpaceVim#layers#autocomplete#toggle_deoplete()',
|
||||
@ -213,8 +215,7 @@ function! SpaceVim#layers#ui#config() abort
|
||||
\ 'toggle conceallevel', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['t', 't'], 'call SpaceVim#plugins#tabmanager#open()',
|
||||
\ 'open-tabs-manager', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['t', 'f'], 'call call('
|
||||
\ . string(s:_function('s:toggle_colorcolumn')) . ', [])',
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['t', 'f'], 'call SpaceVim#layers#core#statusline#toggle_mode("fill-column-indicator")',
|
||||
\ 'fill-column-indicator', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['t', 'h', 'h'], 'call call('
|
||||
\ . string(s:_function('s:toggle_cursorline')) . ', [])',
|
||||
@ -257,6 +258,35 @@ function! SpaceVim#layers#ui#config() abort
|
||||
\ 'func' : s:_function('s:toggle_spell_check'),
|
||||
\ }
|
||||
\ )
|
||||
call SpaceVim#layers#core#statusline#register_mode(
|
||||
\ {
|
||||
\ 'key' : 'hi-characters-for-long-lines',
|
||||
\ 'func' : s:_function('s:toggle_fill_column'),
|
||||
\ }
|
||||
\ )
|
||||
call SpaceVim#layers#core#statusline#register_mode(
|
||||
\ {
|
||||
\ 'key' : 'fill-column-indicator',
|
||||
\ 'func' : s:_function('s:toggle_colorcolumn'),
|
||||
\ }
|
||||
\ )
|
||||
call SpaceVim#layers#core#statusline#register_mode(
|
||||
\ {
|
||||
\ 'key' : 'whitespace',
|
||||
\ 'func' : s:_function('s:toggle_whitespace'),
|
||||
\ }
|
||||
\ )
|
||||
let s:lnum = expand('<slnum>') + s:funcbeginline
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['t', 'w'],
|
||||
\ 'call SpaceVim#layers#core#statusline#toggle_mode("whitespace")',
|
||||
\ ['toggle-highlight-tail-spaces',
|
||||
\ [
|
||||
\ '[SPC t w] will toggle white space highlighting',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:file . ':' . s:lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
\ , 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['t', 'S'],
|
||||
\ 'call SpaceVim#layers#core#statusline#toggle_mode("spell-checking")',
|
||||
\ 'toggle-spell-checker', 1)
|
||||
@ -275,12 +305,15 @@ function! SpaceVim#layers#ui#config() abort
|
||||
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['t', 'l'], 'setlocal list!',
|
||||
\ 'toggle-hidden-listchars', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['t', 'W'], 'call call('
|
||||
\ . string(s:_function('s:toggle_wrap_line')) . ', [])',
|
||||
call SpaceVim#layers#core#statusline#register_mode(
|
||||
\ {
|
||||
\ 'key' : 'wrapline',
|
||||
\ 'func' : s:_function('s:toggle_wrap_line'),
|
||||
\ }
|
||||
\ )
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['t', 'W'],
|
||||
\ 'call SpaceVim#layers#core#statusline#toggle_mode("wrapline")',
|
||||
\ 'toggle-wrap-line', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['t', 'w'], 'call call('
|
||||
\ . string(s:_function('s:toggle_whitespace')) . ', [])',
|
||||
\ 'toggle-highlight-tail-spaces', 1)
|
||||
|
||||
nnoremap <silent> <F11> :call <SID>toggle_full_screen()<Cr>
|
||||
let g:_spacevim_mappings_space.z = get(g:_spacevim_mappings_space, 'z', {'name' : '+Fonts'})
|
||||
@ -355,7 +388,7 @@ function! s:toggle_colorcolumn() abort
|
||||
set cc=
|
||||
let s:ccflag = 0
|
||||
endif
|
||||
call SpaceVim#layers#core#statusline#toggle_mode('fill-column-indicator')
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
let s:fcflag = 0
|
||||
@ -372,7 +405,7 @@ function! s:toggle_fill_column() abort
|
||||
set cc=
|
||||
let s:fcflag = 0
|
||||
endif
|
||||
call SpaceVim#layers#core#statusline#toggle_mode('hi-characters-for-long-lines')
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! s:toggle_indentline() abort
|
||||
@ -478,12 +511,12 @@ function! s:toggle_whitespace() abort
|
||||
let s:whitespace_enable = 1
|
||||
endif
|
||||
call SpaceVim#layers#core#statusline#toggle_section('whitespace')
|
||||
call SpaceVim#layers#core#statusline#toggle_mode('whitespace')
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! s:toggle_wrap_line() abort
|
||||
setlocal wrap!
|
||||
call SpaceVim#layers#core#statusline#toggle_mode('wrapline')
|
||||
set wrap!
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! s:toggle_conceallevel() abort
|
||||
|
@ -1918,6 +1918,9 @@ airline's statusline, just disable this layer
|
||||
name = 'core#statusline'
|
||||
enable = false
|
||||
<
|
||||
LAYER OPTIONS
|
||||
|
||||
`major_mode_cache`: Enable/disable major mode cache, enabled by default.
|
||||
|
||||
==============================================================================
|
||||
CORE#TABLINE *SpaceVim-layers-core-tabline*
|
||||
|
@ -639,7 +639,7 @@ The `core#statusline` layer provides a heavily customized powerline with the fol
|
||||
- show the index of search results
|
||||
- toggle syntax checking info
|
||||
- toggle battery info
|
||||
- toggle minor mode lighters
|
||||
- toggle major mode lighters
|
||||
- show VCS information (branch, hunk summary) (requires `git` and `VersionControl` layers)
|
||||
|
||||
| Key Bindings | Descriptions |
|
||||
@ -664,8 +664,8 @@ Some elements can be dynamically toggled:
|
||||
| `SPC t m b` | toggle the battery status (need to install acpi) |
|
||||
| `SPC t m c` | toggle the org task clock (available in org layer)(TODO) |
|
||||
| `SPC t m i` | toggle the input method |
|
||||
| `SPC t m m` | toggle the minor mode lighters |
|
||||
| `SPC t m M` | toggle the major mode |
|
||||
| `SPC t m m` | toggle the major mode lighters |
|
||||
| `SPC t m M` | toggle the filetype section |
|
||||
| `SPC t m n` | toggle the cat! (If colors layer is declared in your dotfile)(TODO) |
|
||||
| `SPC t m p` | toggle the cursor position |
|
||||
| `SPC t m t` | toggle the time |
|
||||
@ -679,7 +679,7 @@ By default SpaceVim uses nerd-fonts, which can be downloaded from their [website
|
||||
|
||||
**syntax checking integration:**
|
||||
|
||||
When syntax checking minor mode is enabled, a new element appears showing the number of errors and warnings.
|
||||
When syntax checking major mode is enabled, a new element appears showing the number of errors and warnings.
|
||||
|
||||
**Search index integration:**
|
||||
|
||||
@ -729,9 +729,9 @@ Here is an exhaustive set of screenshots for all the available separators:
|
||||
| `nil` | ![separator-nil](https://cloud.githubusercontent.com/assets/13142418/26249776/645a5a96-3cda-11e7-9655-0aa1f76714f4.png) |
|
||||
| `fire` | ![separator-fire](https://cloud.githubusercontent.com/assets/13142418/26274142/434cdd10-3d75-11e7-811b-e44cebfdca58.png) |
|
||||
|
||||
**Minor Modes:**
|
||||
**major modes:**
|
||||
|
||||
The minor mode area can be toggled on and off with `SPC t m m`.
|
||||
The major mode area can be toggled on and off with `SPC t m m`.
|
||||
|
||||
Unicode symbols are displayed by default. Add `statusline_unicode = false` to your custom configuration file to use ASCII characters instead (may be useful in the terminal if you cannot set an appropriate font).
|
||||
|
||||
@ -746,6 +746,15 @@ The letters displayed in the statusline correspond to the key bindings used to t
|
||||
| `SPC t w` | ⓦ | w | whitespace mode (highlight trailing whitespace) |
|
||||
| `SPC t W` | Ⓦ | W | wrap line mode |
|
||||
|
||||
The status of major mode will be cached, the cache will be loaded when spacevim startup.
|
||||
If you want to disable major mode cache, you need to charge the layer option of `core#statusline` layer.
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = 'core#statusline'
|
||||
major_mode_cache = false
|
||||
```
|
||||
|
||||
**colorscheme of statusline:**
|
||||
|
||||
By default SpaceVim only supports colorschemes included in [colorscheme layer](../layers/colorscheme/).
|
||||
@ -2552,5 +2561,3 @@ export PATH=$PATH:$HOME/.SpaceVim/bin
|
||||
Use `svc` to open a file in the existing Vim server, or use `nsvc` to open a file in the existing Neovim server.
|
||||
|
||||
![server-and-client](https://user-images.githubusercontent.com/13142418/32554968-7164fe9c-c4d6-11e7-95f7-f6a6ea75e05b.gif)
|
||||
|
||||
<!-- vim:set nowrap: -->
|
||||
|
Loading…
Reference in New Issue
Block a user