0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.0.1279: initializing menus can be slow

Problem:    Initializing menus can be slow, especially when there are many
            keymaps, color schemes, etc.
Solution:   Do the globbing for runtime files lazlily. (Ken Takata)
This commit is contained in:
Bram Moolenaar 2017-11-09 19:45:48 +01:00
parent 8ac441576f
commit 040c1feb21
3 changed files with 107 additions and 61 deletions

View File

@ -1,4 +1,4 @@
*gui.txt* For Vim version 8.0. Last change: 2017 Sep 23 *gui.txt* For Vim version 8.0. Last change: 2017 Nov 09
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@ -499,6 +499,17 @@ in the menu (which can take a bit of time to load). If you want to have all
filetypes already present at startup, add: > filetypes already present at startup, add: >
:let do_syntax_sel_menu = 1 :let do_syntax_sel_menu = 1
The following menuitems show all available color schemes, keymaps and compiler
settings:
Edit > Color Scheme ~
Edit > Keymap ~
Tools > Set Compiler ~
However, they can also take a bit of time to load, because they search all
related files from the directories in 'runtimepath'. Therefore they are
loaded lazily (by the |CursorHold| event), or you can also load them manually.
If you want to have all these items already present at startup, add: >
:let do_no_lazyload_menus = 1
Note that the menu.vim is sourced when `:syntax on` or `:filetype on` is Note that the menu.vim is sourced when `:syntax on` or `:filetype on` is
executed or after your .vimrc file is sourced. This means that the 'encoding' executed or after your .vimrc file is sourced. This means that the 'encoding'
option and the language of messages (`:language messages`) must be set before option and the language of messages (`:language messages`) must be set before

View File

@ -2,7 +2,7 @@
" You can also use this as a start for your own set of menus. " You can also use this as a start for your own set of menus.
" "
" Maintainer: Bram Moolenaar <Bram@vim.org> " Maintainer: Bram Moolenaar <Bram@vim.org>
" Last Change: 2017 Mar 04 " Last Change: 2017 Nov 09
" Note that ":an" (short for ":anoremenu") is often used to make a menu work " Note that ":an" (short for ":anoremenu") is often used to make a menu work
" in all modes and avoid side effects from mappings defined by the user. " in all modes and avoid side effects from mappings defined by the user.
@ -159,7 +159,7 @@ nnoremenu 20.370 &Edit.Put\ &Before<Tab>[p [p
inoremenu &Edit.Put\ &Before<Tab>[p <C-O>[p inoremenu &Edit.Put\ &Before<Tab>[p <C-O>[p
nnoremenu 20.380 &Edit.Put\ &After<Tab>]p ]p nnoremenu 20.380 &Edit.Put\ &After<Tab>]p ]p
inoremenu &Edit.Put\ &After<Tab>]p <C-O>]p inoremenu &Edit.Put\ &After<Tab>]p <C-O>]p
if has("win32") || has("win16") if has("win32")
vnoremenu 20.390 &Edit.&Delete<Tab>x x vnoremenu 20.390 &Edit.&Delete<Tab>x x
endif endif
noremenu <script> <silent> 20.400 &Edit.&Select\ All<Tab>ggVG :<C-U>call <SID>SelectAll()<CR> noremenu <script> <silent> 20.400 &Edit.&Select\ All<Tab>ggVG :<C-U>call <SID>SelectAll()<CR>
@ -167,7 +167,7 @@ inoremenu <script> <silent> 20.400 &Edit.&Select\ All<Tab>ggVG <C-O>:call <SID>S
cnoremenu <script> <silent> 20.400 &Edit.&Select\ All<Tab>ggVG <C-U>call <SID>SelectAll()<CR> cnoremenu <script> <silent> 20.400 &Edit.&Select\ All<Tab>ggVG <C-U>call <SID>SelectAll()<CR>
an 20.405 &Edit.-SEP2- <Nop> an 20.405 &Edit.-SEP2- <Nop>
if has("win32") || has("win16") || has("gui_gtk") || has("gui_kde") || has("gui_motif") if has("win32") || has("gui_gtk") || has("gui_kde") || has("gui_motif")
an 20.410 &Edit.&Find\.\.\. :promptfind<CR> an 20.410 &Edit.&Find\.\.\. :promptfind<CR>
vunmenu &Edit.&Find\.\.\. vunmenu &Edit.&Find\.\.\.
vnoremenu <silent> &Edit.&Find\.\.\. y:promptfind <C-R>=<SID>FixFText()<CR><CR> vnoremenu <silent> &Edit.&Find\.\.\. y:promptfind <C-R>=<SID>FixFText()<CR><CR>
@ -339,51 +339,65 @@ fun! s:FileFormat()
endif endif
endfun endfun
let s:did_setup_color_schemes = 0
" Setup the Edit.Color Scheme submenu " Setup the Edit.Color Scheme submenu
func! s:SetupColorSchemes() abort
if s:did_setup_color_schemes
return
endif
let s:did_setup_color_schemes = 1
" get NL separated string with file names let n = globpath(&runtimepath, "colors/*.vim", 1, 1)
let s:n = globpath(&runtimepath, "colors/*.vim")
" split at NL, Ignore case for VMS and windows, sort on name " Ignore case for VMS and windows, sort on name
let s:names = sort(map(split(s:n, "\n"), 'substitute(v:val, "\\c.*[/\\\\:\\]]\\([^/\\\\:]*\\)\\.vim", "\\1", "")'), 1) let names = sort(map(n, 'substitute(v:val, "\\c.*[/\\\\:\\]]\\([^/\\\\:]*\\)\\.vim", "\\1", "")'), 1)
" define all the submenu entries " define all the submenu entries
let s:idx = 100 let idx = 100
for s:name in s:names for name in names
exe "an 20.450." . s:idx . ' &Edit.C&olor\ Scheme.' . s:name . " :colors " . s:name . "<CR>" exe "an 20.450." . idx . ' &Edit.C&olor\ Scheme.' . name . " :colors " . name . "<CR>"
let s:idx = s:idx + 10 let idx = idx + 10
endfor endfor
unlet s:name s:names s:n s:idx silent! aunmenu &Edit.Show\ C&olor\ Schemes\ in\ Menu
endfun
if exists("do_no_lazyload_menus")
call s:SetupColorSchemes()
else
an <silent> 20.450 &Edit.Show\ C&olor\ Schemes\ in\ Menu :call <SID>SetupColorSchemes()<CR>
endif
" Setup the Edit.Keymap submenu " Setup the Edit.Keymap submenu
if has("keymap") if has("keymap")
let s:n = globpath(&runtimepath, "keymap/*.vim") let s:did_setup_keymaps = 0
if s:n != ""
let s:idx = 100 func! s:SetupKeymaps() abort
an 20.460.90 &Edit.&Keymap.None :set keymap=<CR> if s:did_setup_keymaps
while strlen(s:n) > 0 return
let s:i = stridx(s:n, "\n") endif
if s:i < 0 let s:did_setup_keymaps = 1
let s:name = s:n
let s:n = "" let n = globpath(&runtimepath, "keymap/*.vim", 1, 1)
else if !empty(n)
let s:name = strpart(s:n, 0, s:i) let idx = 100
let s:n = strpart(s:n, s:i + 1, 19999) an 20.460.90 &Edit.&Keymap.None :set keymap=<CR>
endif for name in n
" Ignore case for VMS and windows " Ignore case for VMS and windows
let s:name = substitute(s:name, '\c.*[/\\:\]]\([^/\\:_]*\)\(_[0-9a-zA-Z-]*\)\=\.vim', '\1', '') let name = substitute(name, '\c.*[/\\:\]]\([^/\\:_]*\)\(_[0-9a-zA-Z-]*\)\=\.vim', '\1', '')
exe "an 20.460." . s:idx . ' &Edit.&Keymap.' . s:name . " :set keymap=" . s:name . "<CR>" exe "an 20.460." . idx . ' &Edit.&Keymap.' . name . " :set keymap=" . name . "<CR>"
unlet s:name let idx = idx + 10
unlet s:i endfor
let s:idx = s:idx + 10 endif
endwhile silent! aunmenu &Edit.Show\ &Keymaps\ in\ Menu
unlet s:idx endfun
if exists("do_no_lazyload_menus")
call s:SetupKeymaps()
else
an <silent> 20.460 &Edit.Show\ &Keymaps\ in\ Menu :call <SID>SetupKeymaps()<CR>
endif endif
unlet s:n
endif endif
if has("win32") || has("win16") || has("gui_motif") || has("gui_gtk") || has("gui_kde") || has("gui_photon") || has("gui_mac") if has("win32") || has("gui_motif") || has("gui_gtk") || has("gui_kde") || has("gui_photon") || has("gui_mac")
an 20.470 &Edit.Select\ Fo&nt\.\.\. :set guifont=*<CR> an 20.470 &Edit.Select\ Fo&nt\.\.\. :set guifont=*<CR>
endif endif
@ -441,10 +455,10 @@ if has("spell")
endif endif
let found = 0 let found = 0
let s = globpath(&rtp, "spell/*." . enc . ".spl") let s = globpath(&runtimepath, "spell/*." . enc . ".spl", 1, 1)
if s != "" if !empty(s)
let n = 300 let n = 300
for f in split(s, "\n") for f in s
let nm = substitute(f, '.*spell[/\\]\(..\)\.[^/\\]*\.spl', '\1', "") let nm = substitute(f, '.*spell[/\\]\(..\)\.[^/\\]*\.spl', '\1', "")
if nm != "en" && nm !~ '/' if nm != "en" && nm !~ '/'
let _nm = nm let _nm = nm
@ -574,27 +588,46 @@ func! s:XxdFind()
endif endif
endfun endfun
let s:did_setup_compilers = 0
" Setup the Tools.Compiler submenu " Setup the Tools.Compiler submenu
let s:n = globpath(&runtimepath, "compiler/*.vim") func! s:SetupCompilers() abort
let s:idx = 100 if s:did_setup_compilers
while strlen(s:n) > 0 return
let s:i = stridx(s:n, "\n")
if s:i < 0
let s:name = s:n
let s:n = ""
else
let s:name = strpart(s:n, 0, s:i)
let s:n = strpart(s:n, s:i + 1, 19999)
endif endif
" Ignore case for VMS and windows let s:did_setup_compilers = 1
let s:name = substitute(s:name, '\c.*[/\\:\]]\([^/\\:]*\)\.vim', '\1', '')
exe "an 30.440." . s:idx . ' &Tools.Se&t\ Compiler.' . s:name . " :compiler " . s:name . "<CR>" let n = globpath(&runtimepath, "compiler/*.vim", 1, 1)
unlet s:name let idx = 100
unlet s:i for name in n
let s:idx = s:idx + 10 " Ignore case for VMS and windows
endwhile let name = substitute(name, '\c.*[/\\:\]]\([^/\\:]*\)\.vim', '\1', '')
unlet s:n exe "an 30.440." . idx . ' &Tools.Se&t\ Compiler.' . name . " :compiler " . name . "<CR>"
unlet s:idx let idx = idx + 10
endfor
silent! aunmenu &Tools.Show\ Compiler\ Se&ttings\ in\ Menu
endfun
if exists("do_no_lazyload_menus")
call s:SetupCompilers()
else
an <silent> 30.440 &Tools.Show\ Compiler\ Se&ttings\ in\ Menu :call <SID>SetupCompilers()<CR>
endif
" Load ColorScheme, Compiler Setting and Keymap menus when idle.
if !exists("do_no_lazyload_menus")
func! s:SetupLazyloadMenus()
call s:SetupColorSchemes()
call s:SetupCompilers()
if has("keymap")
call s:SetupKeymaps()
endif
endfunc
augroup SetupLazyloadMenus
au!
au CursorHold,CursorHoldI * call <SID>SetupLazyloadMenus() | au! SetupLazyloadMenus
augroup END
endif
if !exists("no_buffers_menu") if !exists("no_buffers_menu")
@ -1095,7 +1128,7 @@ if (exists("did_load_filetypes") || exists("syntax_on"))
if exists("do_syntax_sel_menu") if exists("do_syntax_sel_menu")
runtime! synmenu.vim runtime! synmenu.vim
else else
an 50.10 &Syntax.&Show\ File\ Types\ in\ Menu :let do_syntax_sel_menu = 1<Bar>runtime! synmenu.vim<Bar>aunmenu &Syntax.&Show\ File\ Types\ in\ Menu<CR> an <silent> 50.10 &Syntax.&Show\ File\ Types\ in\ Menu :let do_syntax_sel_menu = 1<Bar>runtime! synmenu.vim<Bar>aunmenu &Syntax.&Show\ File\ Types\ in\ Menu<CR>
an 50.195 &Syntax.-SEP1- <Nop> an 50.195 &Syntax.-SEP1- <Nop>
endif endif

View File

@ -761,6 +761,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1279,
/**/ /**/
1278, 1278,
/**/ /**/