Skip to content

Commit 1a741d3

Browse files
committed
patch 9.1.1163: $MYVIMDIR is set too late
Problem: $MYVIMDIR is set too late and not available while sourcing runtime files (Maxim Kim, after v9.1.1159) Solution: Also set it when $MYVIMRC file is found fixes: #16764 closes: #16767 Signed-off-by: Christian Brabandt <[email protected]>
1 parent 7003a5d commit 1a741d3

5 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/option.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8420,6 +8420,8 @@ vimrc_found(char_u *fname, char_u *envname)
84208420
vim_setenv(envname, p);
84218421
vim_free(p);
84228422
}
8423+
// Set $MYVIMDIR
8424+
export_myvimdir();
84238425
}
84248426
else if (dofree)
84258427
vim_free(p);

src/optionstr.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ static char *(p_sws_values[]) = {"fsync", "sync", NULL};
135135

136136
static int check_opt_strings(char_u *val, char **values, int list);
137137
static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
138-
static void export_myvimdir(void);
139138

140139
/*
141140
* After setting various option values: recompute variables that depend on
@@ -4817,7 +4816,7 @@ restore_shm_value(void)
48174816
/*
48184817
* Export the environment variable $MYVIMDIR to the first item in runtimepath
48194818
*/
4820-
static void
4819+
void
48214820
export_myvimdir()
48224821
{
48234822
int dofree = FALSE;

src/proto/optionstr.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,5 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char_u *
198198
int check_ff_value(char_u *p);
199199
void save_clear_shm_value(void);
200200
void restore_shm_value(void);
201+
void export_myvimdir(void);
201202
/* vim: set ft=c : */

src/testdir/test_xdg.vim

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func Test_xdg_rc_detection()
2121
let rc = s:get_rcs()
2222
let before =<< trim CODE
2323
call writefile([expand('$MYVIMRC')], "XMY_VIMRC")
24-
call writefile([expand('$MYVIMRCDIR')], "XMY_VIMDIR")
24+
call writefile([expand('$MYVIMDIR')], "XMY_VIMDIR")
2525
quit!
2626
CODE
2727
call RunVim(before, [], "")
@@ -58,21 +58,30 @@ func Test_xdg_runtime_files()
5858
" g:rc_one|two|three|four is to verify, that the other
5959
" init files are not sourced
6060
" g:rc is to verify which rc file has been loaded.
61+
" g:rc_vimdir is to verify $MYVIMDIR is set and valid
6162
let file1 =<< trim CODE
6263
let g:rc_one = 'one'
6364
let g:rc = '.vimrc'
65+
let g:rc_vimdir = expand('~/.vim/')
66+
call assert_equal(g:rc_vimdir, $MYVIMDIR)
6467
CODE
6568
let file2 =<< trim CODE
6669
let g:rc_two = 'two'
6770
let g:rc = '.vim/vimrc'
71+
let g:rc_vimdir = expand('~/.vim/')
72+
call assert_equal(g:rc_vimdir, $MYVIMDIR)
6873
CODE
6974
let file3 =<< trim CODE
7075
let g:rc_three = 'three'
7176
let g:rc = '.config/vim/vimrc'
77+
let g:rc_vimdir = expand('~/.config/vim/')
78+
call assert_equal(g:rc_vimdir, $MYVIMDIR)
7279
CODE
7380
let file4 =<< trim CODE
7481
let g:rc_four = 'four'
7582
let g:rc = 'xdg/vim/vimrc'
83+
let g:rc_vimdir = expand('~/xdg/vim/')
84+
call assert_equal(g:rc_vimdir, $MYVIMDIR)
7685
CODE
7786
call writefile(file1, rc1)
7887
call writefile(file2, rc2)
@@ -87,7 +96,7 @@ func Test_xdg_runtime_files()
8796
call assert_match('XfakeHOME/\.vimrc', $MYVIMRC)
8897
call assert_match('XfakeHOME/.vim/', $MYVIMDIR)
8998
call filter(g:, {idx, _ -> idx =~ '^rc'})
90-
call assert_equal(#{rc_one: 'one', rc: '.vimrc'}, g:)
99+
call assert_equal(#{rc_one: 'one', rc: '.vimrc', rc_vimdir: $MYVIMDIR}, g:)
91100
call assert_match('XfakeHOME/\.vim/view', &viewdir)
92101
call writefile(v:errors, 'Xresult')
93102
quit
@@ -103,7 +112,7 @@ func Test_xdg_runtime_files()
103112
call assert_match('XfakeHOME/\.vim/vimrc', $MYVIMRC)
104113
call assert_match('XfakeHOME/\.vim/', $MYVIMDIR)
105114
call filter(g:, {idx, _ -> idx =~ '^rc'})
106-
call assert_equal(#{rc_two: 'two', rc: '.vim/vimrc'}, g:)
115+
call assert_equal(#{rc_two: 'two', rc: '.vim/vimrc', rc_vimdir: $MYVIMDIR}, g:)
107116
call assert_match('XfakeHOME/\.vim/view', &viewdir)
108117
call writefile(v:errors, 'Xresult')
109118
quit
@@ -123,7 +132,7 @@ func Test_xdg_runtime_files()
123132
call assert_match('XfakeHOME/\.config/vim/vimrc', $MYVIMRC, msg)
124133
call assert_match('XfakeHOME/\.config/vim/', $MYVIMDIR, msg)
125134
call filter(g:, {idx, _ -> idx =~ '^rc'})
126-
call assert_equal(#{rc_three: 'three', rc: '.config/vim/vimrc'}, g:)
135+
call assert_equal(#{rc_three: 'three', rc: '.config/vim/vimrc', rc_vimdir: $MYVIMDIR}, g:)
127136
call assert_match('XfakeHOME/\.config/vim/view', &viewdir)
128137
call writefile(v:errors, 'Xresult')
129138
quit
@@ -141,7 +150,7 @@ func Test_xdg_runtime_files()
141150
call assert_match('XfakeHOME/xdg/vim/vimrc', $MYVIMRC, msg)
142151
call assert_match('XfakeHOME/xdg/vim/', $MYVIMDIR, msg)
143152
call filter(g:, {idx, _ -> idx =~ '^rc'})
144-
call assert_equal(#{rc_four: 'four', rc: 'xdg/vim/vimrc'}, g:)
153+
call assert_equal(#{rc_four: 'four', rc: 'xdg/vim/vimrc', rc_vimdir: $MYVIMDIR}, g:)
145154
call assert_match('XfakeHOME/xdg/vim/view, &viewdir)
146155
call writefile(v:errors, 'Xresult')
147156
quit

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1163,
707709
/**/
708710
1162,
709711
/**/

0 commit comments

Comments
 (0)