changeset 34979:3c99483807e9 v9.1.0345

patch 9.1.0345: Problem: gvimrc not sourced from XDG_CONFIG_HOME Commit: https://github.com/vim/vim/commit/a34ba821076476a68e0e579723d68e896f771ba6 Author: Maxim Kim <habamax@haba-debian.habamax> Date: Wed Apr 17 22:29:06 2024 +0200 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 <habamax@haba-debian.habamax> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Wed, 17 Apr 2024 22:45:02 +0200
parents 5497fab886b6
children 7129cffaa3bc
files runtime/doc/gui.txt src/os_unix.h src/testdir/test_xdg.vim src/version.c
diffstat 4 files changed, 153 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/runtime/doc/gui.txt
+++ b/runtime/doc/gui.txt
@@ -1,4 +1,4 @@
-*gui.txt*       For Vim version 9.1.  Last change: 2023 Apr 29
+*gui.txt*       For Vim version 9.1.  Last change: 2024 Apr 17
 
 
 		  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -70,6 +70,8 @@ When the GUI starts up initializations a
   - For Win32, $HOME is set by Vim if needed, see |$HOME-windows|.
   - When a "_gvimrc" file is not found, ".gvimrc" is tried too.  And vice
     versa.
+  - On Unix, if "~/.config/vim/gvimrc" or "$XDG_CONFIG_HOME/vim/gvimrc"
+    exists, it is sourced.  You can check this with ":version".
   The name of the first file found is stored in $MYGVIMRC, unless it was
   already set.
 - If the 'exrc' option is set (which is NOT the default) the file ./.gvimrc
--- a/src/os_unix.h
+++ b/src/os_unix.h
@@ -279,6 +279,12 @@ typedef struct dsc$descriptor   DESC;
 # ifndef USR_GVIMRC_FILE3
 #  define USR_GVIMRC_FILE3  "sys$login:_gvimrc"
 # endif
+#else
+# ifndef USR_GVIMRC_FILE3
+#  define USR_GVIMRC_FILE3 (mch_getenv("XDG_CONFIG_HOME") \
+	? "$XDG_CONFIG_HOME/vim/gvimrc" \
+	: "~/.config/vim/gvimrc")
+# endif
 #endif
 
 #ifndef VIM_DEFAULTS_FILE
--- a/src/testdir/test_xdg.vim
+++ b/src/testdir/test_xdg.vim
@@ -3,7 +3,6 @@
 source check.vim
 
 source shared.vim
-source mouse.vim
 
 func s:get_rcs()
   let rcs = {
@@ -44,7 +43,7 @@ func Test_xdg_runtime_files()
   call mkdir(expand('~/.vim/'), 'pD')
   call mkdir(expand('~/.config/vim/'), 'pD')
   call mkdir(expand('~/xdg/vim/'), 'pD')
- 
+
   let rc1=expand('~/.vimrc')
   let rc2=expand('~/.vim/vimrc')
   let rc3=expand('~/.config/vim/vimrc')
@@ -147,15 +146,153 @@ func Test_xdg_version()
   unlet $XDG_CONFIG_HOME
   let a = execute(':version')->split('\n')
   let a = filter(a, { _, val -> val =~ '\.config\|XDG_CONFIG_HOME' })
-  call assert_equal(1, len(a))
-  call assert_match('\~/.config/vim/vimrc', a[0])
+  " There should be 1 entry for gvimrc and 1 entry for vimrc,
+  " but only if Vim was compiled with gui support
+  call assert_equal(1 + has("gui"), len(a))
+  call assert_match('\~/\.config/vim/vimrc', a[0])
+  if has("gui")
+    call assert_match('\~/\.config/vim/gvimrc', a[1])
+  endif
 
   let $XDG_CONFIG_HOME = expand('~/.xdg')
   let a = execute(':version')->split('\n')
   let a = filter(a, { _, val -> val =~ '\.config\|XDG_CONFIG_HOME' })
-  call assert_equal(1, len(a))
+  call assert_equal(1 + has("gui"), len(a))
   call assert_match('XDG_CONFIG_HOME/vim/vimrc', a[0])
+  if has("gui")
+    call assert_match('XDG_CONFIG_HOME/vim/gvimrc', a[1])
+  endif
   unlet $XDG_CONFIG_HOME
 endfunc
 
+" Test for gvimrc, must be last, since it starts the GUI
+" and sources a few extra test files
+func Test_zzz_xdg_runtime_files()
+  CheckCanRunGui
+  CheckUnix
+
+  " Is setup in Github Runner
+  unlet $XDG_CONFIG_HOME
+  source setup_gui.vim
+  call GUISetUpCommon()
+
+  " This tests, that the initialization file from
+  " ~/.vimrc, ~/.vim/vimrc and ~/.config/vim/vimrc (or
+  " $XDG_HOMECONFIG/vim/vimrc) are sourced in that order
+  call mkdir(expand('~/.vim/'), 'pD')
+  call mkdir(expand('~/.config/vim/'), 'pD')
+  call mkdir(expand('~/xdg/vim/'), 'pD')
+
+  let rc1=expand('~/.gvimrc')
+  let rc2=expand('~/.vim/gvimrc')
+  let rc3=expand('~/.config/vim/gvimrc')
+  let rc4=expand('~/xdg/vim/gvimrc')
+
+  " g:rc_one|two|three|four is to verify, that the other
+  " init files are not sourced
+  " g:rc is to verify which rc file has been loaded.
+  let file1 =<< trim CODE
+    let g:rc_one = 'one'
+    let g:rc = '.gvimrc'
+  CODE
+  let file2 =<< trim CODE
+    let g:rc_two = 'two'
+    let g:rc = '.vim/gvimrc'
+  CODE
+  let file3 =<< trim CODE
+    let g:rc_three = 'three'
+    let g:rc = '.config/vim/gvimrc'
+  CODE
+  let file4 =<< trim CODE
+    let g:rc_four = 'four'
+    let g:rc = 'xdg/vim/gvimrc'
+  CODE
+  call writefile(file1, rc1)
+  call writefile(file2, rc2)
+  call writefile(file3, rc3)
+  call writefile(file4, rc4)
+
+  " Get the Vim command to run without the '-u NONE' argument
+  let vimcmd = substitute(GetVimCommand(), '-u NONE', '', '')
+
+  " Test for ~/.gvimrc
+  let lines =<< trim END
+    " Ignore the "failed to create input context" error.
+    call test_ignore_error('E285')
+    gui -f
+    call assert_match('Xhome/\.gvimrc', $MYGVIMRC)
+    call filter(g:, {idx, _ -> idx =~ '^rc'})
+    call assert_equal(#{rc_one: 'one', rc: '.gvimrc'}, g:)
+    call writefile(v:errors, 'Xresult')
+    quit
+  END
+  call writefile(lines, 'Xscript', 'D')
+  call system($'{vimcmd} -S Xscript')
+  call assert_equal([], readfile('Xresult'))
+
+  call delete(rc1)
+
+  " Test for ~/.vim/gvimrc
+  let lines =<< trim END
+    " Ignore the "failed to create input context" error.
+    call test_ignore_error('E285')
+    gui -f
+    call assert_match('Xhome/\.vim/gvimrc', $MYGVIMRC)
+    call filter(g:, {idx, _ -> idx =~ '^rc'})
+    call assert_equal(#{rc_two: 'two', rc: '.vim/gvimrc'}, g:)
+    call writefile(v:errors, 'Xresult')
+    quit
+  END
+  call writefile(lines, 'Xscript', 'D')
+  call system($'{vimcmd} -S Xscript')
+  call assert_equal([], readfile('Xresult'))
+
+  call delete(rc2)
+
+  " XDG_CONFIG_HOME is set in Github CI runners
+  unlet $XDG_CONFIG_HOME
+
+  " Test for ~/.config/vim/gvimrc
+  let lines =<< trim END
+    " Ignore the "failed to create input context" error.
+    call test_ignore_error('E285')
+    gui -f
+    let msg = $'HOME="{$HOME}", ~="{expand("~")}"'
+    call assert_match('Xhome/\.config/vim/gvimrc', $MYGVIMRC, msg)
+    call filter(g:, {idx, _ -> idx =~ '^rc'})
+    call assert_equal(#{rc_three: 'three', rc: '.config/vim/gvimrc'}, g:)
+    call writefile(v:errors, 'Xresult')
+    quit
+  END
+  call writefile(lines, 'Xscript', 'D')
+  call system($'{vimcmd} -S Xscript')
+  call assert_equal([], readfile('Xresult'))
+
+  call delete(rc3)
+
+  " Test for ~/xdg/vim/gvimrc
+  let $XDG_CONFIG_HOME=expand('~/xdg/')
+  let lines =<< trim END
+    " Ignore the "failed to create input context" error.
+    call test_ignore_error('E285')
+    gui -f
+    let msg = $'HOME="{$HOME}", XDG_CONFIG_HOME="{$XDG_CONFIG_HOME}"'
+    call assert_match('Xhome/xdg/vim/gvimrc', $MYGVIMRC, msg)
+    call filter(g:, {idx, _ -> idx =~ '^rc'})
+    call assert_equal(#{rc_four: 'four', rc: 'xdg/vim/gvimrc'}, g:)
+    call writefile(v:errors, 'Xresult')
+    quit
+  END
+  call writefile(lines, 'Xscript', 'D')
+  call system($'{vimcmd} -S Xscript')
+  call assert_equal([], readfile('Xresult'))
+
+  call delete(rc4)
+
+  " Clean up
+  unlet $XDG_CONFIG_HOME
+  call GUITearDownCommon()
+  call delete('Xhome', 'rf')
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    345,
+/**/
     344,
 /**/
     343,