]> granicus.if.org Git - vim/commitdiff
patch 8.2.2905: no error when defaults.vim cannot be loaded v8.2.2905
authorChristian Brabandt <cb@256bit.org>
Sat, 29 May 2021 17:53:50 +0000 (19:53 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 29 May 2021 17:53:50 +0000 (19:53 +0200)
Problem:    No error when defaults.vim cannot be loaded.
Solution:   Add an error message. (Christian Brabandt, closes #8248)

runtime/doc/starting.txt
src/errors.h
src/main.c
src/testdir/test_startup.vim
src/version.c

index 469ec0ca5d911ad99be5b5dac4a47b5d123f27f3..d4e8cf818fa937e1cd190208779f434ac5661216 100644 (file)
@@ -1036,7 +1036,7 @@ giving the mapping.
 
 
 Defaults without a .vimrc file ~
-                                                       *defaults.vim*
+                                                       *defaults.vim* *E1187*
 If Vim is started normally and no user vimrc file is found, the
 $VIMRUNTIME/defaults.vim script is loaded.  This will set 'compatible' off,
 switch on syntax highlighting and a few more things.  See the script for
index 2a0a536c84f67f6fd9abc65db563297887b3fd50..d6e5dd1d26b91e4d4fb5e21394fc93074df606a0 100644 (file)
@@ -413,3 +413,5 @@ EXTERN char e_missing_redir_end[]
        INIT(= N_("E1185: Missing :redir END"));
 EXTERN char e_expression_does_not_result_in_value_str[]
        INIT(= N_("E1186: Expression does not result in a value: %s"));
+EXTERN char e_failed_to_source_defaults[]
+       INIT(= N_("E1187: Failed to source defaults.vim"));
index 277e31790bec2bc79a5ebfffba8a4f6276c12b93..db8202ea7d3e6115ded2c0e3599bd6c2a07241a8 100644 (file)
@@ -3128,7 +3128,11 @@ source_startup_scripts(mparm_T *parmp)
     if (parmp->use_vimrc != NULL)
     {
        if (STRCMP(parmp->use_vimrc, "DEFAULTS") == 0)
-           do_source((char_u *)VIM_DEFAULTS_FILE, FALSE, DOSO_NONE, NULL);
+       {
+           if (do_source((char_u *)VIM_DEFAULTS_FILE, FALSE, DOSO_NONE, NULL)
+                                                                        != OK)
+               emsg(e_failed_to_source_defaults);
+       }
        else if (STRCMP(parmp->use_vimrc, "NONE") == 0
                                     || STRCMP(parmp->use_vimrc, "NORC") == 0)
        {
@@ -3200,7 +3204,9 @@ source_startup_scripts(mparm_T *parmp)
                && !has_dash_c_arg)
            {
                // When no .vimrc file was found: source defaults.vim.
-               do_source((char_u *)VIM_DEFAULTS_FILE, FALSE, DOSO_NONE, NULL);
+               if (do_source((char_u *)VIM_DEFAULTS_FILE, FALSE, DOSO_NONE,
+                                                                NULL) == FAIL)
+                   emsg(e_failed_to_source_defaults);
            }
        }
 
index 1f14e86e3b38fe2d317ed0578d06213a8d03cdbc..76060bf7bdef09364ae9068186646d3d937146bd 100644 (file)
@@ -276,6 +276,19 @@ func Test_V_arg()
    call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline 1: \" The default vimrc file\..*  verbose=15\n", out)
 endfunc
 
+" Test that an error is shown when the defaults.vim file could not be read
+func Test_defaults_error()
+  " Can't catch the output of gvim.
+  CheckNotGui
+  CheckNotMSWindows
+
+  let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' --clean -cq')
+  call assert_match("E1187: Failed to source defaults.vim", out)
+
+  let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' -u DEFAULTS -cq')
+  call assert_match("E1187: Failed to source defaults.vim", out)
+endfunc
+
 " Test the '-q [errorfile]' argument.
 func Test_q_arg()
   CheckFeature quickfix
index b95a9690881d691e2591dc79934423c75d81bf54..ca90eea2c5a2db2e860ad6a72c678f34dc021f23 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2905,
 /**/
     2904,
 /**/