Skip to content

Commit 1d3a14e

Browse files
chrisbrabrammool
authored andcommitted
patch 8.2.2905: no error when defaults.vim cannot be loaded
Problem: No error when defaults.vim cannot be loaded. Solution: Add an error message. (Christian Brabandt, closes #8248)
1 parent 74ede80 commit 1d3a14e

5 files changed

Lines changed: 26 additions & 3 deletions

File tree

runtime/doc/starting.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ giving the mapping.
10361036

10371037

10381038
Defaults without a .vimrc file ~
1039-
*defaults.vim*
1039+
*defaults.vim* *E1187*
10401040
If Vim is started normally and no user vimrc file is found, the
10411041
$VIMRUNTIME/defaults.vim script is loaded. This will set 'compatible' off,
10421042
switch on syntax highlighting and a few more things. See the script for

src/errors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,5 @@ EXTERN char e_missing_redir_end[]
413413
INIT(= N_("E1185: Missing :redir END"));
414414
EXTERN char e_expression_does_not_result_in_value_str[]
415415
INIT(= N_("E1186: Expression does not result in a value: %s"));
416+
EXTERN char e_failed_to_source_defaults[]
417+
INIT(= N_("E1187: Failed to source defaults.vim"));

src/main.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3128,7 +3128,11 @@ source_startup_scripts(mparm_T *parmp)
31283128
if (parmp->use_vimrc != NULL)
31293129
{
31303130
if (STRCMP(parmp->use_vimrc, "DEFAULTS") == 0)
3131-
do_source((char_u *)VIM_DEFAULTS_FILE, FALSE, DOSO_NONE, NULL);
3131+
{
3132+
if (do_source((char_u *)VIM_DEFAULTS_FILE, FALSE, DOSO_NONE, NULL)
3133+
!= OK)
3134+
emsg(e_failed_to_source_defaults);
3135+
}
31323136
else if (STRCMP(parmp->use_vimrc, "NONE") == 0
31333137
|| STRCMP(parmp->use_vimrc, "NORC") == 0)
31343138
{
@@ -3200,7 +3204,9 @@ source_startup_scripts(mparm_T *parmp)
32003204
&& !has_dash_c_arg)
32013205
{
32023206
// When no .vimrc file was found: source defaults.vim.
3203-
do_source((char_u *)VIM_DEFAULTS_FILE, FALSE, DOSO_NONE, NULL);
3207+
if (do_source((char_u *)VIM_DEFAULTS_FILE, FALSE, DOSO_NONE,
3208+
NULL) == FAIL)
3209+
emsg(e_failed_to_source_defaults);
32043210
}
32053211
}
32063212

src/testdir/test_startup.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,19 @@ func Test_V_arg()
276276
call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline 1: \" The default vimrc file\..* verbose=15\n", out)
277277
endfunc
278278

279+
" Test that an error is shown when the defaults.vim file could not be read
280+
func Test_defaults_error()
281+
" Can't catch the output of gvim.
282+
CheckNotGui
283+
CheckNotMSWindows
284+
285+
let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' --clean -cq')
286+
call assert_match("E1187: Failed to source defaults.vim", out)
287+
288+
let out = system('VIMRUNTIME=/tmp ' .. GetVimCommand() .. ' -u DEFAULTS -cq')
289+
call assert_match("E1187: Failed to source defaults.vim", out)
290+
endfunc
291+
279292
" Test the '-q [errorfile]' argument.
280293
func Test_q_arg()
281294
CheckFeature quickfix

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2905,
753755
/**/
754756
2904,
755757
/**/

0 commit comments

Comments
 (0)