]> granicus.if.org Git - vim/commitdiff
patch 9.0.0343: ColorScheme autocommand triggered when colorscheme not found v9.0.0343
authorBram Moolenaar <Bram@vim.org>
Wed, 31 Aug 2022 20:17:10 +0000 (21:17 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 31 Aug 2022 20:17:10 +0000 (21:17 +0100)
Problem:    ColorScheme autocommand triggered when colorscheme is not found.
            (Romain Lafourcade)
Solution:   Only trigger ColorScheme when loading the colorscheme succeeds.
            (closes #11024)

src/highlight.c
src/testdir/test_gui.vim
src/version.c

index 95cdb46b5ab6fa8cc54731e3028ae59b68aa4a6c..303d5c294f72d3d1105633f1716a638201911c5d 100644 (file)
@@ -507,7 +507,9 @@ load_colors(char_u *name)
        sprintf((char *)buf, "colors/%s.vim", name);
        retval = source_runtime(buf, DIP_START + DIP_OPT);
        vim_free(buf);
-       apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname, FALSE, curbuf);
+       if (retval == OK)
+           apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname,
+                                                               FALSE, curbuf);
     }
     recursive = FALSE;
 
index ed40c256cb95ac6eca4ecc26f7779e1214ea949b..afac5ccb99ee2e8aa385b4f87c2165a682bfe9bc 100644 (file)
@@ -36,8 +36,12 @@ func Test_colorscheme()
   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
+    au ColorScheme * let g:color_count += 1
+                 \ | let g:after_colors = g:color_count
+                 \ | let g:color_after = expand('<amatch>')
+    au ColorSchemePre * let g:color_count += 1
+                    \ | let g:before_colors = g:color_count
+                    \ | let g:color_pre = expand('<amatch>')
   augroup END
 
   colorscheme torte
@@ -45,6 +49,8 @@ func Test_colorscheme()
   call assert_equal('dark', &background)
   call assert_equal(1, g:before_colors)
   call assert_equal(2, g:after_colors)
+  call assert_equal('torte', g:color_pre)
+  call assert_equal('torte', g:color_after)
   call assert_equal("\ntorte", execute('colorscheme'))
 
   let a = substitute(execute('hi Search'), "\n\\s\\+", ' ', 'g')
@@ -53,6 +59,8 @@ func Test_colorscheme()
   call assert_match("\nSearch         xxx term=reverse ", a)
 
   call assert_fails('colorscheme does_not_exist', 'E185:')
+  call assert_equal('does_not_exist', g:color_pre)
+  call assert_equal('torte', g:color_after)
 
   exec 'colorscheme' colorscheme_saved
   augroup TestColors
index 68f7baa720056bd05d4b8c100e37c5811f4d5226..f2991b872ad303d5aa7e0fad5723eb620aa753a2 100644 (file)
@@ -707,6 +707,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    343,
 /**/
     342,
 /**/