fix: source syncolors.vim before startup scripts

This fixes an issue (#12573) where colorscheme files are sourced twice
upon startup. This occurs when the startup script calls `:colorscheme`,
which sets the `g:colors_name` global variable. When syntax highlighting
is enabled in `syn_maybe_enable()` the `syntax.vim` script is sourced
which in turn sources `synload.vim`. This script checks to see if
`g:colors_name` is set and, if so, runs

    exe "colors " . colors_name

This is done to ensure that highlight groups are defined before enabling
the syntax highlighting engine.

Instead, source syncolors.vim before the startup scripts which sets up
default highlights and only load the full syntax engine after
the startup scripts or when the user runs `:syntax on`. Add a guard
variable `did_syncolor` to prevent syncolor.vim from being sourced
twice and remove the line mentioned above from synload.vim so that
the colorscheme file is not re-sourced when the syntax engine is loaded.
This commit is contained in:
Gregory Anders
2021-06-10 21:59:10 -06:00
parent 682247b52e
commit 0bcf96bf0b
3 changed files with 14 additions and 6 deletions

View File

@@ -25,6 +25,8 @@ else
endif endif
endif endif
let did_syncolor = 1
" Many terminals can only use six different colors (plus black and white). " Many terminals can only use six different colors (plus black and white).
" Therefore the number of colors used is kept low. It doesn't look nice with " Therefore the number of colors used is kept low. It doesn't look nice with
" too many colors anyway. " too many colors anyway.

View File

@@ -14,10 +14,8 @@ endif
" let others know that syntax has been switched on " let others know that syntax has been switched on
let syntax_on = 1 let syntax_on = 1
" Set the default highlighting colors. Use a color scheme if specified. " Set the default highlighting colors
if exists("colors_name") if !exists("colors_name") && !exists("did_syncolor")
exe "colors " . colors_name
else
runtime! syntax/syncolor.vim runtime! syntax/syncolor.vim
endif endif

View File

@@ -367,11 +367,19 @@ int main(int argc, char **argv)
// Execute --cmd arguments. // Execute --cmd arguments.
exe_pre_commands(&params); exe_pre_commands(&params);
// If using the runtime (-u is not NONE), enable syntax & filetype plugins.
bool enable_syntax =
(params.use_vimrc == NULL || !strequal(params.use_vimrc, "NONE"));
// Source syncolor.vim to set up default UI highlights
if (enable_syntax) {
source_runtime((char_u *)"syntax/syncolor.vim", DIP_ALL);
}
// Source startup scripts. // Source startup scripts.
source_startup_scripts(&params); source_startup_scripts(&params);
// If using the runtime (-u is not NONE), enable syntax & filetype plugins. if (enable_syntax) {
if (params.use_vimrc == NULL || !strequal(params.use_vimrc, "NONE")) {
// Does ":filetype plugin indent on". // Does ":filetype plugin indent on".
filetype_maybe_enable(); filetype_maybe_enable();
// Sources syntax/syntax.vim, which calls `:filetype on`. // Sources syntax/syntax.vim, which calls `:filetype on`.