Skip to content

Commit a34ba82

Browse files
Maxim Kimchrisbra
authored andcommitted
patch 9.1.0345: Problem: gvimrc not sourced from XDG_CONFIG_HOME
Problem: gvimrc not sourced from XDG_CONFIG_HOME (after v9.1.0327) Solution: Also try to source from ~/.config/vim/gvimrc and $XDG_CONFIG_HOME/vim/gvimrc (Maxim Kim) fixes: #14567 closes: #14568 Signed-off-by: Maxim Kim <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent e20fa59 commit a34ba82

File tree

4 files changed

+153
-6
lines changed

4 files changed

+153
-6
lines changed

runtime/doc/gui.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*gui.txt* For Vim version 9.1. Last change: 2023 Apr 29
1+
*gui.txt* For Vim version 9.1. Last change: 2024 Apr 17
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -70,6 +70,8 @@ When the GUI starts up initializations are carried out, in this order:
7070
- For Win32, $HOME is set by Vim if needed, see |$HOME-windows|.
7171
- When a "_gvimrc" file is not found, ".gvimrc" is tried too. And vice
7272
versa.
73+
- On Unix, if "~/.config/vim/gvimrc" or "$XDG_CONFIG_HOME/vim/gvimrc"
74+
exists, it is sourced. You can check this with ":version".
7375
The name of the first file found is stored in $MYGVIMRC, unless it was
7476
already set.
7577
- If the 'exrc' option is set (which is NOT the default) the file ./.gvimrc

src/os_unix.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ typedef struct dsc$descriptor DESC;
279279
# ifndef USR_GVIMRC_FILE3
280280
# define USR_GVIMRC_FILE3 "sys$login:_gvimrc"
281281
# endif
282+
#else
283+
# ifndef USR_GVIMRC_FILE3
284+
# define USR_GVIMRC_FILE3 (mch_getenv("XDG_CONFIG_HOME") \
285+
? "$XDG_CONFIG_HOME/vim/gvimrc" \
286+
: "~/.config/vim/gvimrc")
287+
# endif
282288
#endif
283289

284290
#ifndef VIM_DEFAULTS_FILE

src/testdir/test_xdg.vim

Lines changed: 142 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
source check.vim
44

55
source shared.vim
6-
source mouse.vim
76

87
func s:get_rcs()
98
let rcs = {
@@ -44,7 +43,7 @@ func Test_xdg_runtime_files()
4443
call mkdir(expand('~/.vim/'), 'pD')
4544
call mkdir(expand('~/.config/vim/'), 'pD')
4645
call mkdir(expand('~/xdg/vim/'), 'pD')
47-
46+
4847
let rc1=expand('~/.vimrc')
4948
let rc2=expand('~/.vim/vimrc')
5049
let rc3=expand('~/.config/vim/vimrc')
@@ -147,15 +146,153 @@ func Test_xdg_version()
147146
unlet $XDG_CONFIG_HOME
148147
let a = execute(':version')->split('\n')
149148
let a = filter(a, { _, val -> val =~ '\.config\|XDG_CONFIG_HOME' })
150-
call assert_equal(1, len(a))
151-
call assert_match('\~/.config/vim/vimrc', a[0])
149+
" There should be 1 entry for gvimrc and 1 entry for vimrc,
150+
" but only if Vim was compiled with gui support
151+
call assert_equal(1 + has("gui"), len(a))
152+
call assert_match('\~/\.config/vim/vimrc', a[0])
153+
if has("gui")
154+
call assert_match('\~/\.config/vim/gvimrc', a[1])
155+
endif
152156

153157
let $XDG_CONFIG_HOME = expand('~/.xdg')
154158
let a = execute(':version')->split('\n')
155159
let a = filter(a, { _, val -> val =~ '\.config\|XDG_CONFIG_HOME' })
156-
call assert_equal(1, len(a))
160+
call assert_equal(1 + has("gui"), len(a))
157161
call assert_match('XDG_CONFIG_HOME/vim/vimrc', a[0])
162+
if has("gui")
163+
call assert_match('XDG_CONFIG_HOME/vim/gvimrc', a[1])
164+
endif
165+
unlet $XDG_CONFIG_HOME
166+
endfunc
167+
168+
" Test for gvimrc, must be last, since it starts the GUI
169+
" and sources a few extra test files
170+
func Test_zzz_xdg_runtime_files()
171+
CheckCanRunGui
172+
CheckUnix
173+
174+
" Is setup in Github Runner
175+
unlet $XDG_CONFIG_HOME
176+
source setup_gui.vim
177+
call GUISetUpCommon()
178+
179+
" This tests, that the initialization file from
180+
" ~/.vimrc, ~/.vim/vimrc and ~/.config/vim/vimrc (or
181+
" $XDG_HOMECONFIG/vim/vimrc) are sourced in that order
182+
call mkdir(expand('~/.vim/'), 'pD')
183+
call mkdir(expand('~/.config/vim/'), 'pD')
184+
call mkdir(expand('~/xdg/vim/'), 'pD')
185+
186+
let rc1=expand('~/.gvimrc')
187+
let rc2=expand('~/.vim/gvimrc')
188+
let rc3=expand('~/.config/vim/gvimrc')
189+
let rc4=expand('~/xdg/vim/gvimrc')
190+
191+
" g:rc_one|two|three|four is to verify, that the other
192+
" init files are not sourced
193+
" g:rc is to verify which rc file has been loaded.
194+
let file1 =<< trim CODE
195+
let g:rc_one = 'one'
196+
let g:rc = '.gvimrc'
197+
CODE
198+
let file2 =<< trim CODE
199+
let g:rc_two = 'two'
200+
let g:rc = '.vim/gvimrc'
201+
CODE
202+
let file3 =<< trim CODE
203+
let g:rc_three = 'three'
204+
let g:rc = '.config/vim/gvimrc'
205+
CODE
206+
let file4 =<< trim CODE
207+
let g:rc_four = 'four'
208+
let g:rc = 'xdg/vim/gvimrc'
209+
CODE
210+
call writefile(file1, rc1)
211+
call writefile(file2, rc2)
212+
call writefile(file3, rc3)
213+
call writefile(file4, rc4)
214+
215+
" Get the Vim command to run without the '-u NONE' argument
216+
let vimcmd = substitute(GetVimCommand(), '-u NONE', '', '')
217+
218+
" Test for ~/.gvimrc
219+
let lines =<< trim END
220+
" Ignore the "failed to create input context" error.
221+
call test_ignore_error('E285')
222+
gui -f
223+
call assert_match('Xhome/\.gvimrc', $MYGVIMRC)
224+
call filter(g:, {idx, _ -> idx =~ '^rc'})
225+
call assert_equal(#{rc_one: 'one', rc: '.gvimrc'}, g:)
226+
call writefile(v:errors, 'Xresult')
227+
quit
228+
END
229+
call writefile(lines, 'Xscript', 'D')
230+
call system($'{vimcmd} -S Xscript')
231+
call assert_equal([], readfile('Xresult'))
232+
233+
call delete(rc1)
234+
235+
" Test for ~/.vim/gvimrc
236+
let lines =<< trim END
237+
" Ignore the "failed to create input context" error.
238+
call test_ignore_error('E285')
239+
gui -f
240+
call assert_match('Xhome/\.vim/gvimrc', $MYGVIMRC)
241+
call filter(g:, {idx, _ -> idx =~ '^rc'})
242+
call assert_equal(#{rc_two: 'two', rc: '.vim/gvimrc'}, g:)
243+
call writefile(v:errors, 'Xresult')
244+
quit
245+
END
246+
call writefile(lines, 'Xscript', 'D')
247+
call system($'{vimcmd} -S Xscript')
248+
call assert_equal([], readfile('Xresult'))
249+
250+
call delete(rc2)
251+
252+
" XDG_CONFIG_HOME is set in Github CI runners
253+
unlet $XDG_CONFIG_HOME
254+
255+
" Test for ~/.config/vim/gvimrc
256+
let lines =<< trim END
257+
" Ignore the "failed to create input context" error.
258+
call test_ignore_error('E285')
259+
gui -f
260+
let msg = $'HOME="{$HOME}", ~="{expand("~")}"'
261+
call assert_match('Xhome/\.config/vim/gvimrc', $MYGVIMRC, msg)
262+
call filter(g:, {idx, _ -> idx =~ '^rc'})
263+
call assert_equal(#{rc_three: 'three', rc: '.config/vim/gvimrc'}, g:)
264+
call writefile(v:errors, 'Xresult')
265+
quit
266+
END
267+
call writefile(lines, 'Xscript', 'D')
268+
call system($'{vimcmd} -S Xscript')
269+
call assert_equal([], readfile('Xresult'))
270+
271+
call delete(rc3)
272+
273+
" Test for ~/xdg/vim/gvimrc
274+
let $XDG_CONFIG_HOME=expand('~/xdg/')
275+
let lines =<< trim END
276+
" Ignore the "failed to create input context" error.
277+
call test_ignore_error('E285')
278+
gui -f
279+
let msg = $'HOME="{$HOME}", XDG_CONFIG_HOME="{$XDG_CONFIG_HOME}"'
280+
call assert_match('Xhome/xdg/vim/gvimrc', $MYGVIMRC, msg)
281+
call filter(g:, {idx, _ -> idx =~ '^rc'})
282+
call assert_equal(#{rc_four: 'four', rc: 'xdg/vim/gvimrc'}, g:)
283+
call writefile(v:errors, 'Xresult')
284+
quit
285+
END
286+
call writefile(lines, 'Xscript', 'D')
287+
call system($'{vimcmd} -S Xscript')
288+
call assert_equal([], readfile('Xresult'))
289+
290+
call delete(rc4)
291+
292+
" Clean up
158293
unlet $XDG_CONFIG_HOME
294+
call GUITearDownCommon()
295+
call delete('Xhome', 'rf')
159296
endfunc
160297

161298
" vim: shiftwidth=2 sts=2 expandtab

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+
345,
707709
/**/
708710
344,
709711
/**/

0 commit comments

Comments
 (0)