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

perf(layer): lazy load layer config

This commit is contained in:
Eric Wong 2024-07-05 23:11:59 +08:00
parent 5373526997
commit 1843ad9c35
19 changed files with 158 additions and 86 deletions

View File

@ -209,6 +209,14 @@ let g:spacevim_default_indent = 2
" In Insert mode: Use the appropriate number of spaces to insert a <Tab>
let g:spacevim_expand_tab = 1
""
" @section if_ruby, options-if_ruby
" @parentsection options
" Neovim if_ruby provider is too slow, If you are sure that your nvim does not
" support ruby, set this option to false. default is true.
let g:spacevim_if_ruby = 1
""
" @section enable_list_mode, options-enable_list_mode
" @parentsection options
@ -1629,7 +1637,8 @@ endif
command! -nargs=1 LeaderGuide call SpaceVim#mapping#guide#start_by_prefix('0', <args>)
command! -range -nargs=1 LeaderGuideVisual call SpaceVim#mapping#guide#start_by_prefix('1', <args>)
function! SpaceVim#end() abort
function! s:lazy_end(...) abort
if g:spacevim_vimcompatible
let g:spacevim_windows_leader = ''
let g:spacevim_windows_smartclose = ''
@ -1691,11 +1700,6 @@ function! SpaceVim#end() abort
if !empty(g:spacevim_language)
silent exec 'lan ' . g:spacevim_language
endif
if SpaceVim#layers#isLoaded('core#statusline')
call SpaceVim#layers#core#statusline#init()
endif
" tab options:
set smarttab
let &expandtab = g:spacevim_expand_tab
@ -1728,13 +1732,49 @@ function! SpaceVim#end() abort
vnoremap <silent> <leader> :<c-u>LeaderGuideVisual get(g:, 'mapleader', '\')<CR>
endif
let g:leaderGuide_max_size = 15
call SpaceVim#plugins#load()
exe 'set wildignore+=' . g:spacevim_wildignore
" shell
if has('filterpipe')
set noshelltemp
endif
endfunction
function! SpaceVim#end() abort
let g:_spacevim_mappings_prefixs['[SPC]'] = {'name' : '+SPC prefix'}
let g:_spacevim_mappings_space.t = {'name' : '+Toggles'}
let g:_spacevim_mappings_space.t.h = {'name' : '+Toggles highlight'}
let g:_spacevim_mappings_space.t.m = {'name' : '+modeline'}
let g:_spacevim_mappings_space.T = {'name' : '+UI toggles/themes'}
let g:_spacevim_mappings_space.a = {'name' : '+Applications'}
let g:_spacevim_mappings_space.b = {'name' : '+Buffers'}
let g:_spacevim_mappings_space.f = {'name' : '+Files'}
let g:_spacevim_mappings_space.j = {'name' : '+Jump/Join/Split'}
let g:_spacevim_mappings_space.m = {'name' : '+Major-mode'}
let g:_spacevim_mappings_space.w = {'name' : '+Windows'}
let g:_spacevim_mappings_space.p = {'name' : '+Projects/Packages'}
let g:_spacevim_mappings_space.h = {'name' : '+Help'}
let g:_spacevim_mappings_space.n = {'name' : '+Narrow/Numbers'}
let g:_spacevim_mappings_space.q = {'name' : '+Quit'}
let g:_spacevim_mappings_space.l = {'name' : '+Language Specified'}
let g:_spacevim_mappings_space.s = {'name' : '+Searching/Symbol'}
let g:_spacevim_mappings_space.r = {'name' : '+Registers/rings/resume'}
let g:_spacevim_mappings_space.d = {'name' : '+Debug'}
let g:_spacevim_mappings_space.e = {'name' : '+Errors/Encoding'}
let g:_spacevim_mappings_space.B = {'name' : '+Global buffers'}
let &tabline = ' '
if has('timers')
call timer_start(300, function('s:lazy_end'))
else
call s:lazy_end()
endif
if SpaceVim#layers#isLoaded('core#statusline')
call SpaceVim#layers#core#statusline#init()
endif
call SpaceVim#plugins#load()
if g:spacevim_enable_guicolors == 1
if !has('nvim') && has('patch-7.4.1770')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
@ -1983,6 +2023,15 @@ function! SpaceVim#welcome() abort
endif
if g:spacevim_enable_vimfiler_welcome
\ && get(g:, '_spacevim_checking_flag', 0) == 0
if has('timers')
call timer_start(500, function('s:open_filetree'))
else
call s:open_filetree()
endif
endif
endfunction
function! s:open_filetree(...) abort
if exists(':VimFiler') == 2
VimFiler
wincmd p
@ -2006,7 +2055,7 @@ function! SpaceVim#welcome() abort
elseif exists(':Neotree') == 2
NeoTreeShow
endif
endif
endfunction
""

View File

@ -165,6 +165,9 @@ function! s:apply(config, type) abort
elseif value ==# 'neo-tree' && !has('nvim')
call SpaceVim#logger#warn('neo-tree requires neovim')
continue
elseif value ==# 'nvim-tree' && !has('nvim')
call SpaceVim#logger#warn('nvim-tree requires neovim')
continue
endif
" keep backward compatibility
elseif name ==# 'autocomplete_method'

View File

@ -140,6 +140,9 @@ function! SpaceVim#default#options() abort
" Do not wrap lone lines
set nowrap
" disable all bell
set belloff=all
set foldtext=SpaceVim#default#Customfoldtext()
endfunction
@ -159,7 +162,7 @@ function! SpaceVim#default#layers() abort
call SpaceVim#logger#info('layer list init done')
endfunction
function! SpaceVim#default#keyBindings() abort
function! SpaceVim#default#keyBindings(...) abort
call SpaceVim#logger#info('init default key bindings.')
xnoremap <silent> <Leader>y :<C-u>call clipboard#yank()<cr>
nnoremap <expr> <Leader>p clipboard#paste('p')

View File

@ -196,12 +196,12 @@ function! SpaceVim#layers#core#plugins() abort
\ }])
call add(plugins, [g:_spacevim_root_dir . 'bundle/vimproc.vim', {'build' : [(executable('gmake') ? 'gmake' : 'make')]}])
elseif g:spacevim_filemanager ==# 'defx'
call add(plugins, [g:_spacevim_root_dir . 'bundle/defx.nvim',{'merged' : 0, 'loadconf' : 1 , 'loadconf_before' : 1, 'on_cmd' : 'Defx'}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/defx.nvim',{'merged' : 0, 'loadconf' : 1, 'on_cmd' : 'Defx'}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/defx-git',{'merged' : 0, 'loadconf' : 1}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/defx-icons',{'merged' : 0}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/defx-sftp',{'merged' : 0}])
elseif g:spacevim_filemanager ==# 'nvim-tree'
call add(plugins, [g:_spacevim_root_dir . 'bundle/nvim-tree.lua',{'merged' : 0, 'loadconf' : 1}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/nvim-tree.lua',{'merged' : 0, 'loadconf' : 1, 'on_cmd' : ['NvimTreeOpen', 'NvimTree', 'NvimTreeToggle', 'NvimTreeFindFile']}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/nvim-web-devicons',{'merged' : 0, 'loadconf' : 1}])
elseif g:spacevim_filemanager ==# 'neo-tree'
call add(plugins, [g:_spacevim_root_dir . 'bundle/neo-tree.nvim',{'merged' : 0, 'loadconf' : 1}])
@ -252,6 +252,12 @@ function! SpaceVim#layers#core#config() abort
if g:spacevim_filemanager ==# 'nerdtree'
noremap <silent> <F3> :NERDTreeToggle<CR>
elseif g:spacevim_filemanager ==# 'defx'
nnoremap <silent> <F3> :Defx<Cr>
elseif g:spacevim_filemanager ==# 'nvim-tree'
nnoremap <silent> <F3> <cmd>NvimTreeToggle<CR>
elseif g:spacevim_filemanager ==# 'neo-tree'
nnoremap <silent> <F3> <cmd>NeoTreeFocusToggle<CR>
endif
let g:matchup_matchparen_status_offscreen = 0
let g:smoothie_no_default_mappings = !s:enable_smooth_scrolling

View File

@ -38,7 +38,7 @@ function! SpaceVim#layers#github#plugins() abort
\ [g:_spacevim_root_dir . 'bundle/github-issues.vim', {'merged' : 0, 'if' : has('python')}],
\ [g:_spacevim_root_dir . 'bundle/vim-github-dashboard', {
\ 'merged' : 0,
\ 'if' : has('ruby'),
\ 'if' : g:spacevim_if_ruby && has('ruby'),
\ 'on_cmd' : ['GHActivity', 'GHDashboard'],
\ }],
\ ['tyru/open-browser-github.vim', {
@ -82,7 +82,7 @@ function! SpaceVim#layers#github#config() abort
endif
"" }}}
if has('ruby')
if g:spacevim_if_ruby && has('ruby')
" vim-github-dashboard requires if_ruby
let g:github_dashboard = {
\ 'username': g:spacevim_github_username,

View File

@ -10,7 +10,7 @@ function! SpaceVim#layers#zettelkasten#plugins() abort
let plugins = []
call add(plugins, [g:_spacevim_root_dir . 'bundle/vim-zettelkasten',
\ {
\ 'merged' : 0,
\ 'merged' : 0, 'on_cmd' : ['ZkNew', 'ZkBrowse', 'ZkListTemplete'], 'loadconf' : 1,
\ }])
return plugins
endfunction
@ -29,7 +29,7 @@ endfunction
function! SpaceVim#layers#zettelkasten#config() abort
let g:_spacevim_mappings_space.m.z = {'name' : '+zettelkasten'}
call SpaceVim#mapping#space#def('nnoremap', ['m', 'z', 'n'], 'ZkNew', 'create-new-zettel-note', 1)
call SpaceVim#mapping#space#def('nnoremap', ['m', 'z', 't'], 'Telescope zettelkasten_template', 'zettel-template', 1)
call SpaceVim#mapping#space#def('nnoremap', ['m', 'z', 't'], 'ZkListTemplete', 'zettel-template', 1)
call SpaceVim#mapping#space#def('nnoremap', ['m', 'z', 'b'], 'ZkBrowse', 'open-zettelkasten-browse', 1)
endfunction

View File

@ -14,25 +14,6 @@ let s:file = expand('<sfile>:~')
let s:funcbeginline = expand('<slnum>') + 1
function! SpaceVim#mapping#space#init() abort
call SpaceVim#logger#debug('init SPC key bindings')
let g:_spacevim_mappings_prefixs['[SPC]'] = {'name' : '+SPC prefix'}
let g:_spacevim_mappings_space.t = {'name' : '+Toggles'}
let g:_spacevim_mappings_space.t.h = {'name' : '+Toggles highlight'}
let g:_spacevim_mappings_space.t.m = {'name' : '+modeline'}
let g:_spacevim_mappings_space.T = {'name' : '+UI toggles/themes'}
let g:_spacevim_mappings_space.a = {'name' : '+Applications'}
let g:_spacevim_mappings_space.b = {'name' : '+Buffers'}
let g:_spacevim_mappings_space.f = {'name' : '+Files'}
let g:_spacevim_mappings_space.j = {'name' : '+Jump/Join/Split'}
let g:_spacevim_mappings_space.m = {'name' : '+Major-mode'}
let g:_spacevim_mappings_space.w = {'name' : '+Windows'}
let g:_spacevim_mappings_space.p = {'name' : '+Projects/Packages'}
let g:_spacevim_mappings_space.h = {'name' : '+Help'}
let g:_spacevim_mappings_space.n = {'name' : '+Narrow/Numbers'}
let g:_spacevim_mappings_space.q = {'name' : '+Quit'}
let g:_spacevim_mappings_space.l = {'name' : '+Language Specified'}
let g:_spacevim_mappings_space.s = {'name' : '+Searching/Symbol'}
let g:_spacevim_mappings_space.r = {'name' : '+Registers/rings/resume'}
let g:_spacevim_mappings_space.d = {'name' : '+Debug'}
if s:has_map_to_spc()
return
endif
@ -371,8 +352,6 @@ function! SpaceVim#mapping#space#init() abort
\ ]
\ , 1)
let g:_spacevim_mappings_space.e = {'name' : '+Errors/Encoding'}
let g:_spacevim_mappings_space.B = {'name' : '+Global buffers'}
if g:spacevim_relativenumber
nnoremap <silent> [SPC]tn :<C-u>setlocal nonumber! norelativenumber!<CR>
let g:_spacevim_mappings_space.t.n = ['setlocal nonumber! norelativenumber!', 'toggle-line-number']

View File

@ -41,8 +41,12 @@ function! s:load_plugins() abort
call SpaceVim#plugins#add(plugin[0], {'overwrite' : 1})
endif
endfor
call s:loadLayerConfig(layer)
endfor
if has('timers')
call timer_start(500, function('s:layer_config_timer'), {'repeat' : 1})
else
call s:layer_config_timer(0)
endif
unlet g:_spacevim_plugin_layer
for plugin in g:spacevim_custom_plugins
if len(plugin) == 2
@ -63,6 +67,12 @@ function! s:getLayerPlugins(layer) abort
return p
endfunction
function! s:layer_config_timer(t) abort
for layer in SpaceVim#layers#get()
call s:loadLayerConfig(layer)
endfor
endfunction
function! s:loadLayerConfig(layer) abort
call SpaceVim#logger#debug('load ' . a:layer . ' layer config.')
try
@ -70,7 +80,6 @@ function! s:loadLayerConfig(layer) abort
catch /^Vim\%((\a\+)\)\=:E117/
call SpaceVim#logger#info(a:layer . ' layer do not implement config function')
endtry
endfunction
let s:plugins_argv = ['-update', '-openurl']

View File

@ -39,7 +39,7 @@ local function update_branch_name(pwd, ...)
if
force
or vim.fn.get(vim.fn.get(branch_info, pwd, {}), 'last_update_done', 0)
>= vim.fn.localtime() - 1
<= vim.fn.localtime() - 1
then
local jobid = job.start(cmd, {
on_stdout = on_stdout_show_branch,

View File

@ -13,6 +13,10 @@ if vim.fn.exists(":ZkBrowse") == 0 then
vim.cmd([[command ZkBrowse :lua _G.zettelkasten.zkbrowse()]])
end
if vim.fn.exists(":ZkListTemplete") == 0 then
vim.cmd([[command ZkListTemplete :Telescope zettelkasten_template]])
end
_G.zettelkasten = {
tagfunc = require("zettelkasten").tagfunc,
completefunc = require("zettelkasten").completefunc,

View File

@ -1,5 +1,4 @@
let s:WIN = SpaceVim#api#import('vim#window')
nnoremap <silent> <F3> <cmd>NeoTreeFocusToggle<CR>
augroup vfinit
au!
autocmd FileType neo-tree call s:nvim_tree_init()

View File

@ -1,5 +1,4 @@
let s:WIN = SpaceVim#api#import('vim#window')
nnoremap <silent> <F3> <cmd>NvimTreeToggle<CR>
" we can not use this option to disable default key bindings
" let g:nvim_tree_disable_default_keybindings = 1
augroup vfinit

View File

@ -5,9 +5,6 @@ lua require('telescope').load_extension('scriptnames')
lua require('telescope').load_extension('neoyank')
lua require('telescope').load_extension('task')
lua require('telescope').load_extension('neomru')
if SpaceVim#layers#isLoaded('zettelkasten')
lua require('telescope').load_extension('zettelkasten_template')
endif
if SpaceVim#layers#isLoaded('tools')
lua require('telescope').load_extension('bookmarks')
endif

View File

@ -60,6 +60,10 @@ augroup END
if !exists('g:startify_custom_header')
call s:update_logo()
endif
if !has_key(g:_spacevim_mappings_space, 'a')
let g:_spacevim_mappings_space.a = {'name' : '+Applications'}
endif
call SpaceVim#mapping#space#def('nnoremap', ['a','s'], 'call SpaceVim#plugins#history#savepos() | Startify | doautocmd WinEnter', 'fancy start screen',1)
if g:spacevim_enable_tabline_ft_icon || get(g:, 'spacevim_enable_tabline_filetype_icon', 0)

View File

@ -0,0 +1,3 @@
if SpaceVim#layers#isLoaded('zettelkasten')
lua require('telescope').load_extension('zettelkasten_template')
endif

View File

@ -1,2 +0,0 @@
nnoremap <silent> <F3> :Defx<Cr>

View File

@ -58,44 +58,45 @@ CONTENTS *SpaceVim-contents*
36. filetree_direction.............. |SpaceVim-options-filetree_direction|
37. guifont.................................... |SpaceVim-options-guifont|
38. home_files_number................ |SpaceVim-options-home_files_number|
39. info_symbol............................ |SpaceVim-options-info_symbol|
40. keep_server_alive................ |SpaceVim-options-keep_server_alive|
41. language.................................. |SpaceVim-options-language|
42. leader_guide_theme.............. |SpaceVim-options-leader_guide_theme|
43. lint_engine............................ |SpaceVim-options-lint_engine|
44. lint_on_the_fly.................... |SpaceVim-options-lint_on_the_fly|
45. max_column.............................. |SpaceVim-options-max_column|
46. plugin_bundle_dir................ |SpaceVim-options-plugin_bundle_dir|
47. plugin_manager_processes.. |SpaceVim-options-plugin_manager_processes|
48. project_auto_root................ |SpaceVim-options-project_auto_root|
49. project_non_root.................. |SpaceVim-options-project_non_root|
50. project_rooter_outermost.. |SpaceVim-options-project_rooter_outermost|
51. project_rooter_patterns.... |SpaceVim-options-project_rooter_patterns|
52. projects_cache_num.............. |SpaceVim-options-projects_cache_num|
53. realtime_leader_guide........ |SpaceVim-options-realtime_leader_guide|
54. relativenumber...................... |SpaceVim-options-relativenumber|
55. retry_cnt................................ |SpaceVim-options-retry_cnt|
56. search_tools.......................... |SpaceVim-options-search_tools|
57. sidebar_width........................ |SpaceVim-options-sidebar_width|
58. snippet_engine...................... |SpaceVim-options-snippet_engine|
59. src_root.................................. |SpaceVim-options-src_root|
60. statusline_iseparator........ |SpaceVim-options-statusline_iseparator|
61. statusline_left.................... |SpaceVim-options-statusline_left|
62. statusline_right.................. |SpaceVim-options-statusline_right|
63. statusline_separator.......... |SpaceVim-options-statusline_separator|
64. statusline_unicode.............. |SpaceVim-options-statusline_unicode|
65. terminal_cursor_shape........ |SpaceVim-options-terminal_cursor_shape|
66. todo_close_list......................... |SpaceVim-options-close_list|
67. todo_labels............................ |SpaceVim-options-todo_labels|
68. todo_prefix............................ |SpaceVim-options-todo_prefix|
69. vim_help_language................ |SpaceVim-options-vim_help_language|
70. vimcompatible........................ |SpaceVim-options-vimcompatible|
71. warning_symbol...................... |SpaceVim-options-warning_symbol|
72. wildignore.............................. |SpaceVim-options-wildignore|
73. windisk_encoding.................. |SpaceVim-options-windisk_encoding|
74. windows_index_type.............. |SpaceVim-options-windows_index_type|
75. windows_leader...................... |SpaceVim-options-windows_leader|
76. windows_smartclose.............. |SpaceVim-options-windows_smartclose|
39. if_ruby.................................... |SpaceVim-options-if_ruby|
40. info_symbol............................ |SpaceVim-options-info_symbol|
41. keep_server_alive................ |SpaceVim-options-keep_server_alive|
42. language.................................. |SpaceVim-options-language|
43. leader_guide_theme.............. |SpaceVim-options-leader_guide_theme|
44. lint_engine............................ |SpaceVim-options-lint_engine|
45. lint_on_the_fly.................... |SpaceVim-options-lint_on_the_fly|
46. max_column.............................. |SpaceVim-options-max_column|
47. plugin_bundle_dir................ |SpaceVim-options-plugin_bundle_dir|
48. plugin_manager_processes.. |SpaceVim-options-plugin_manager_processes|
49. project_auto_root................ |SpaceVim-options-project_auto_root|
50. project_non_root.................. |SpaceVim-options-project_non_root|
51. project_rooter_outermost.. |SpaceVim-options-project_rooter_outermost|
52. project_rooter_patterns.... |SpaceVim-options-project_rooter_patterns|
53. projects_cache_num.............. |SpaceVim-options-projects_cache_num|
54. realtime_leader_guide........ |SpaceVim-options-realtime_leader_guide|
55. relativenumber...................... |SpaceVim-options-relativenumber|
56. retry_cnt................................ |SpaceVim-options-retry_cnt|
57. search_tools.......................... |SpaceVim-options-search_tools|
58. sidebar_width........................ |SpaceVim-options-sidebar_width|
59. snippet_engine...................... |SpaceVim-options-snippet_engine|
60. src_root.................................. |SpaceVim-options-src_root|
61. statusline_iseparator........ |SpaceVim-options-statusline_iseparator|
62. statusline_left.................... |SpaceVim-options-statusline_left|
63. statusline_right.................. |SpaceVim-options-statusline_right|
64. statusline_separator.......... |SpaceVim-options-statusline_separator|
65. statusline_unicode.............. |SpaceVim-options-statusline_unicode|
66. terminal_cursor_shape........ |SpaceVim-options-terminal_cursor_shape|
67. todo_close_list......................... |SpaceVim-options-close_list|
68. todo_labels............................ |SpaceVim-options-todo_labels|
69. todo_prefix............................ |SpaceVim-options-todo_prefix|
70. vim_help_language................ |SpaceVim-options-vim_help_language|
71. vimcompatible........................ |SpaceVim-options-vimcompatible|
72. warning_symbol...................... |SpaceVim-options-warning_symbol|
73. wildignore.............................. |SpaceVim-options-wildignore|
74. windisk_encoding.................. |SpaceVim-options-windisk_encoding|
75. windows_index_type.............. |SpaceVim-options-windows_index_type|
76. windows_leader...................... |SpaceVim-options-windows_leader|
77. windows_smartclose.............. |SpaceVim-options-windows_smartclose|
3. Configuration............................................ |SpaceVim-config|
4. Commands............................................... |SpaceVim-commands|
5. Public functions...................................... |SpaceVim-functions|
@ -801,6 +802,12 @@ Change the list number of files for SpaceVim home. Default is 6.
home_files_number = 6
<
==============================================================================
IF_RUBY *SpaceVim-options-if_ruby*
Neovim if_ruby provider is too slow, If you are sure that your nvim does not
support ruby, set this option to false. default is true.
==============================================================================
INFO_SYMBOL *SpaceVim-options-info_symbol*

View File

@ -63,7 +63,12 @@ call SpaceVim#begin()
call SpaceVim#custom#load()
call SpaceVim#default#keyBindings()
if has('timers')
call timer_start(300, 'SpaceVim#default#keyBindings')
else
call SpaceVim#default#keyBindings()
endif
call SpaceVim#end()

View File

@ -320,6 +320,13 @@ function M.enable()
isep = iseps[1]
right_sep = seps[1]
left_sep = seps[2]
for bufnr = 1, vim.fn.bufnr('$') do
if
vim.api.nvim_buf_is_valid(bufnr) and vim.api.nvim_buf_get_option(bufnr, 'buflisted')
then
table.insert(visiable_bufs, bufnr)
end
end
local tabline_augroup = vim.api.nvim_create_augroup('spacevim_tabline', { clear = true })
vim.api.nvim_create_autocmd({ 'BufNewFile', 'BufReadPost' }, {
callback = vim.schedule_wrap(function(event)