summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Brabandt <cb@256bit.org>2021-05-29 19:53:50 +0200
committerBram Moolenaar <Bram@vim.org>2021-05-29 19:53:50 +0200
commit1d3a14ecf0cdde026984894c592dc140a2b46887 (patch)
tree61f1f20638e52bd684584205a7f2cdbf20a1a286
parent74ede80aeb272ac81d41a256057c4f250372dd00 (diff)
downloadvim-git-1d3a14ecf0cdde026984894c592dc140a2b46887.tar.gz
patch 8.2.2905: no error when defaults.vim cannot be loadedv8.2.2905
Problem: No error when defaults.vim cannot be loaded. Solution: Add an error message. (Christian Brabandt, closes #8248)
-rw-r--r--runtime/doc/starting.txt2
-rw-r--r--src/errors.h2
-rw-r--r--src/main.c10
-rw-r--r--src/testdir/test_startup.vim13
-rw-r--r--src/version.c2
5 files changed, 26 insertions, 3 deletions
diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt
index 469ec0ca5..d4e8cf818 100644
--- a/runtime/doc/starting.txt
+++ b/runtime/doc/starting.txt
@@ -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
diff --git a/src/errors.h b/src/errors.h
index 2a0a536c8..d6e5dd1d2 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -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"));
diff --git a/src/main.c b/src/main.c
index 277e31790..db8202ea7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);
}
}
diff --git a/src/testdir/test_startup.vim b/src/testdir/test_startup.vim
index 1f14e86e3..76060bf7b 100644
--- a/src/testdir/test_startup.vim
+++ b/src/testdir/test_startup.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index b95a96908..ca90eea2c 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2905,
+/**/
2904,
/**/
2903,