Skip to content

Commit 5d09a40

Browse files
committed
patch 9.0.0343: ColorScheme autocommand triggered when colorscheme not found
Problem: ColorScheme autocommand triggered when colorscheme is not found. (Romain Lafourcade) Solution: Only trigger ColorScheme when loading the colorscheme succeeds. (closes #11024)
1 parent 21c3a80 commit 5d09a40

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/highlight.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,9 @@ load_colors(char_u *name)
507507
sprintf((char *)buf, "colors/%s.vim", name);
508508
retval = source_runtime(buf, DIP_START + DIP_OPT);
509509
vim_free(buf);
510-
apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname, FALSE, curbuf);
510+
if (retval == OK)
511+
apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname,
512+
FALSE, curbuf);
511513
}
512514
recursive = FALSE;
513515

src/testdir/test_gui.vim

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,21 @@ func Test_colorscheme()
3636
let g:color_count = 0
3737
augroup TestColors
3838
au!
39-
au ColorScheme * let g:color_count += 1| let g:after_colors = g:color_count
40-
au ColorSchemePre * let g:color_count += 1 |let g:before_colors = g:color_count
39+
au ColorScheme * let g:color_count += 1
40+
\ | let g:after_colors = g:color_count
41+
\ | let g:color_after = expand('<amatch>')
42+
au ColorSchemePre * let g:color_count += 1
43+
\ | let g:before_colors = g:color_count
44+
\ | let g:color_pre = expand('<amatch>')
4145
augroup END
4246

4347
colorscheme torte
4448
redraw!
4549
call assert_equal('dark', &background)
4650
call assert_equal(1, g:before_colors)
4751
call assert_equal(2, g:after_colors)
52+
call assert_equal('torte', g:color_pre)
53+
call assert_equal('torte', g:color_after)
4854
call assert_equal("\ntorte", execute('colorscheme'))
4955

5056
let a = substitute(execute('hi Search'), "\n\\s\\+", ' ', 'g')
@@ -53,6 +59,8 @@ func Test_colorscheme()
5359
call assert_match("\nSearch xxx term=reverse ", a)
5460

5561
call assert_fails('colorscheme does_not_exist', 'E185:')
62+
call assert_equal('does_not_exist', g:color_pre)
63+
call assert_equal('torte', g:color_after)
5664

5765
exec 'colorscheme' colorscheme_saved
5866
augroup TestColors

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,8 @@ static char *(features[]) =
707707

708708
static int included_patches[] =
709709
{ /* Add new patch number below this line */
710+
/**/
711+
343,
710712
/**/
711713
342,
712714
/**/

0 commit comments

Comments
 (0)