patch 9.1.0393: 'viewdir' not respecting $XDG_CONFIG_HOME

Problem:  'viewdir' not respecting $XDG_CONFIG_HOME
          (Danilo Rezende, after v9.1.327)
Solution: adjust 'viewdir' option when enabling XDG config mode

fixes: #14680
closes: #14708

Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/option.c b/src/option.c
index 0cd2823..2acc0d4 100644
--- a/src/option.c
+++ b/src/option.c
@@ -417,6 +417,14 @@
     options[opt_idx].def_val[VI_DEFAULT] = xdg_rtp;
     p_pp = xdg_rtp;
 
+#if defined(XDG_VDIR) && defined(FEAT_SESSION)
+    if ((opt_idx = findoption((char_u *)"viewdir")) < 0)
+	goto theend;
+
+    options[opt_idx].def_val[VI_DEFAULT] = (char_u *)XDG_VDIR;
+    p_vdir = (char_u *)XDG_VDIR;
+#endif
+
 theend:
     vim_free(vimrc1);
     vim_free(vimrc2);
diff --git a/src/os_unix.h b/src/os_unix.h
index 6efd8ce..99184ab 100644
--- a/src/os_unix.h
+++ b/src/os_unix.h
@@ -347,6 +347,8 @@
 #  define DFLT_VDIR    "sys$login:vimfiles/view"
 # else
 #  define DFLT_VDIR    "$HOME/.vim/view"       // default for 'viewdir'
+#  define XDG_VDIR     (mch_getenv("XDG_CONFIG_HOME") ? \
+	"$XDG_CONFIG_HOME/vim/view" : "~/.config/vim/view")
 # endif
 #endif
 
diff --git a/src/testdir/test_xdg.vim b/src/testdir/test_xdg.vim
index 6f35b72..b9ec3c7 100644
--- a/src/testdir/test_xdg.vim
+++ b/src/testdir/test_xdg.vim
@@ -80,6 +80,7 @@
     call assert_match('XfakeHOME/\.vimrc', $MYVIMRC)
     call filter(g:, {idx, _ -> idx =~ '^rc'})
     call assert_equal(#{rc_one: 'one', rc: '.vimrc'}, g:)
+    call assert_match('XfakeHOME/\.vim/view', &viewdir)
     call writefile(v:errors, 'Xresult')
     quit
   END
@@ -94,6 +95,7 @@
     call assert_match('XfakeHOME/\.vim/vimrc', $MYVIMRC)
     call filter(g:, {idx, _ -> idx =~ '^rc'})
     call assert_equal(#{rc_two: 'two', rc: '.vim/vimrc'}, g:)
+    call assert_match('XfakeHOME/\.vim/view', &viewdir)
     call writefile(v:errors, 'Xresult')
     quit
   END
@@ -112,6 +114,7 @@
     call assert_match('XfakeHOME/\.config/vim/vimrc', $MYVIMRC, msg)
     call filter(g:, {idx, _ -> idx =~ '^rc'})
     call assert_equal(#{rc_three: 'three', rc: '.config/vim/vimrc'}, g:)
+    call assert_match('XfakeHOME/\.config/vim/view', &viewdir)
     call writefile(v:errors, 'Xresult')
     quit
   END
@@ -128,6 +131,7 @@
     call assert_match('XfakeHOME/xdg/vim/vimrc', $MYVIMRC, msg)
     call filter(g:, {idx, _ -> idx =~ '^rc'})
     call assert_equal(#{rc_four: 'four', rc: 'xdg/vim/vimrc'}, g:)
+    call assert_match('XfakeHOME/xdg/vim/view, &viewdir)
     call writefile(v:errors, 'Xresult')
     quit
   END
diff --git a/src/version.c b/src/version.c
index 1efc081..5312bfe 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    393,
+/**/
     392,
 /**/
     391,