mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.0.1777: cannot cleanup before loading another colorscheme
Problem: Cannot cleanup before loading another colorscheme. Solution: Add the ColorSchemePre autocommand event.
This commit is contained in:
@@ -42,7 +42,16 @@ this autocmd might be useful:
|
|||||||
Replace "blue_sky" with the name of the colorscheme.
|
Replace "blue_sky" with the name of the colorscheme.
|
||||||
|
|
||||||
In case you want to tweak a colorscheme after it was loaded, check out the
|
In case you want to tweak a colorscheme after it was loaded, check out the
|
||||||
ColorScheme autocmd event.
|
ColorScheme autocommand event.
|
||||||
|
|
||||||
|
To clean up just before loading another colorscheme, use the ColorSchemePre
|
||||||
|
autocommand event. For example:
|
||||||
|
let g:term_ansi_colors = ...
|
||||||
|
augroup MyColorscheme
|
||||||
|
au!
|
||||||
|
au ColorSchemePre * unlet g:term_ansi_colors
|
||||||
|
au ColorSchemePre * au! MyColorscheme
|
||||||
|
augroup END
|
||||||
|
|
||||||
To customize a colorscheme use another name, e.g. "~/.vim/colors/mine.vim",
|
To customize a colorscheme use another name, e.g. "~/.vim/colors/mine.vim",
|
||||||
and use `:runtime` to load the original colorscheme:
|
and use `:runtime` to load the original colorscheme:
|
||||||
|
@@ -7734,6 +7734,7 @@ static struct event_name
|
|||||||
{"CmdwinLeave", EVENT_CMDWINLEAVE},
|
{"CmdwinLeave", EVENT_CMDWINLEAVE},
|
||||||
{"CmdUndefined", EVENT_CMDUNDEFINED},
|
{"CmdUndefined", EVENT_CMDUNDEFINED},
|
||||||
{"ColorScheme", EVENT_COLORSCHEME},
|
{"ColorScheme", EVENT_COLORSCHEME},
|
||||||
|
{"ColorSchemePre", EVENT_COLORSCHEMEPRE},
|
||||||
{"CompleteDone", EVENT_COMPLETEDONE},
|
{"CompleteDone", EVENT_COMPLETEDONE},
|
||||||
{"CursorHold", EVENT_CURSORHOLD},
|
{"CursorHold", EVENT_CURSORHOLD},
|
||||||
{"CursorHoldI", EVENT_CURSORHOLDI},
|
{"CursorHoldI", EVENT_CURSORHOLDI},
|
||||||
@@ -9479,7 +9480,8 @@ apply_autocmds_group(
|
|||||||
*/
|
*/
|
||||||
if (fname_io == NULL)
|
if (fname_io == NULL)
|
||||||
{
|
{
|
||||||
if (event == EVENT_COLORSCHEME || event == EVENT_OPTIONSET)
|
if (event == EVENT_COLORSCHEME || event == EVENT_COLORSCHEMEPRE
|
||||||
|
|| event == EVENT_OPTIONSET)
|
||||||
autocmd_fname = NULL;
|
autocmd_fname = NULL;
|
||||||
else if (fname != NULL && !ends_excmd(*fname))
|
else if (fname != NULL && !ends_excmd(*fname))
|
||||||
autocmd_fname = fname;
|
autocmd_fname = fname;
|
||||||
@@ -9549,6 +9551,7 @@ apply_autocmds_group(
|
|||||||
|| event == EVENT_SPELLFILEMISSING
|
|| event == EVENT_SPELLFILEMISSING
|
||||||
|| event == EVENT_QUICKFIXCMDPRE
|
|| event == EVENT_QUICKFIXCMDPRE
|
||||||
|| event == EVENT_COLORSCHEME
|
|| event == EVENT_COLORSCHEME
|
||||||
|
|| event == EVENT_COLORSCHEMEPRE
|
||||||
|| event == EVENT_OPTIONSET
|
|| event == EVENT_OPTIONSET
|
||||||
|| event == EVENT_QUICKFIXCMDPOST
|
|| event == EVENT_QUICKFIXCMDPOST
|
||||||
|| event == EVENT_DIRCHANGED)
|
|| event == EVENT_DIRCHANGED)
|
||||||
|
@@ -7224,6 +7224,8 @@ load_colors(char_u *name)
|
|||||||
buf = alloc((unsigned)(STRLEN(name) + 12));
|
buf = alloc((unsigned)(STRLEN(name) + 12));
|
||||||
if (buf != NULL)
|
if (buf != NULL)
|
||||||
{
|
{
|
||||||
|
apply_autocmds(EVENT_COLORSCHEMEPRE, name,
|
||||||
|
curbuf->b_fname, FALSE, curbuf);
|
||||||
sprintf((char *)buf, "colors/%s.vim", name);
|
sprintf((char *)buf, "colors/%s.vim", name);
|
||||||
retval = source_runtime(buf, DIP_START + DIP_OPT);
|
retval = source_runtime(buf, DIP_START + DIP_OPT);
|
||||||
vim_free(buf);
|
vim_free(buf);
|
||||||
|
@@ -33,13 +33,25 @@ endfunc
|
|||||||
|
|
||||||
func Test_colorscheme()
|
func Test_colorscheme()
|
||||||
let colorscheme_saved = exists('g:colors_name') ? g:colors_name : 'default'
|
let colorscheme_saved = exists('g:colors_name') ? g:colors_name : 'default'
|
||||||
|
let g:color_count = 0
|
||||||
|
augroup TestColors
|
||||||
|
au!
|
||||||
|
au ColorScheme * let g:color_count += 1| let g:after_colors = g:color_count
|
||||||
|
au ColorSchemePre * let g:color_count += 1 |let g:before_colors = g:color_count
|
||||||
|
augroup END
|
||||||
|
|
||||||
colorscheme torte
|
colorscheme torte
|
||||||
redraw!
|
redraw!
|
||||||
sleep 200m
|
sleep 200m
|
||||||
call assert_equal('dark', &background)
|
call assert_equal('dark', &background)
|
||||||
|
call assert_equal(1, g:before_colors)
|
||||||
|
call assert_equal(2, g:after_colors)
|
||||||
|
|
||||||
exec 'colorscheme' colorscheme_saved
|
exec 'colorscheme' colorscheme_saved
|
||||||
|
augroup TestColors
|
||||||
|
au!
|
||||||
|
augroup END
|
||||||
|
unlet g:color_count g:after_colors g:before_colors
|
||||||
redraw!
|
redraw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
1777,
|
||||||
/**/
|
/**/
|
||||||
1776,
|
1776,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -1277,6 +1277,7 @@ enum auto_event
|
|||||||
EVENT_CMDWINENTER, /* after entering the cmdline window */
|
EVENT_CMDWINENTER, /* after entering the cmdline window */
|
||||||
EVENT_CMDWINLEAVE, /* before leaving the cmdline window */
|
EVENT_CMDWINLEAVE, /* before leaving the cmdline window */
|
||||||
EVENT_COLORSCHEME, /* after loading a colorscheme */
|
EVENT_COLORSCHEME, /* after loading a colorscheme */
|
||||||
|
EVENT_COLORSCHEMEPRE, /* before loading a colorscheme */
|
||||||
EVENT_COMPLETEDONE, /* after finishing insert complete */
|
EVENT_COMPLETEDONE, /* after finishing insert complete */
|
||||||
EVENT_CURSORHOLD, /* cursor in same position for a while */
|
EVENT_CURSORHOLD, /* cursor in same position for a while */
|
||||||
EVENT_CURSORHOLDI, /* idem, in Insert mode */
|
EVENT_CURSORHOLDI, /* idem, in Insert mode */
|
||||||
|
Reference in New Issue
Block a user