Skip to content

Commit

Permalink
Problem: 'viewdir' not respecting $XDG_CONFIG_HOME
Browse files Browse the repository at this point in the history
Problem:  'viewdir' not respecting $XDG_CONFIG_HOME
          (Danilo Rezende, after v9.1.327)
Solution: adjust 'viewdir' option when enabling XDG config mode

fixes: vim#14680

Signed-off-by: Christian Brabandt <[email protected]>
  • Loading branch information
chrisbra committed May 2, 2024
1 parent 652c821 commit d9ee054
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
11 changes: 8 additions & 3 deletions runtime/doc/options.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*options.txt* For Vim version 9.1. Last change: 2024 Mar 29
*options.txt* For Vim version 9.1. Last change: 2024 May 02


VIM REFERENCE MANUAL by Bram Moolenaar
Expand Down Expand Up @@ -6683,7 +6683,8 @@ A jump table for the options with a short description can be found at |Q_op|.
<
*'runtimepath'* *'rtp'* *vimfiles*
'runtimepath' 'rtp' string (default:
Unix: "$HOME/.vim,
Unix: "$HOME/.vim or
$XDG_CONFIG_HOME/vim,
$VIM/vimfiles,
$VIMRUNTIME,
$VIM/vimfiles/after,
Expand Down Expand Up @@ -6735,6 +6736,8 @@ A jump table for the options with a short description can be found at |Q_op|.

And any other file searched for with the |:runtime| command.

For $XDG_CONFIG_HOME see |xdg-base-dir|.

The defaults for most systems are setup to search five locations:
1. In your home directory, for your personal preferences.
2. In a system-wide Vim directory, for preferences from the system
Expand Down Expand Up @@ -8986,13 +8989,15 @@ A jump table for the options with a short description can be found at |Q_op|.
*'viewdir'* *'vdir'*
'viewdir' 'vdir' string (default for Amiga: "home:vimfiles/view",
for Win32: "$HOME/vimfiles/view",
for Unix: "$HOME/.vim/view",
for Unix: "$HOME/.vim/view" or
"$XDG_CONFIG_HOME/vim/view"
for macOS: "$VIM/vimfiles/view",
for VMS: "sys$login:vimfiles/view")
global
{not available when compiled without the |+mksession|
feature}
Name of the directory where to store files for |:mkview|.
For $XDG_CONFIG_HOME see |xdg-base-dir|.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.

Expand Down
6 changes: 3 additions & 3 deletions runtime/doc/starting.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*starting.txt* For Vim version 9.1. Last change: 2024 Apr 21
*starting.txt* For Vim version 9.1. Last change: 2024 May 02


VIM REFERENCE MANUAL by Bram Moolenaar
Expand Down Expand Up @@ -1119,8 +1119,8 @@ feature backward compatible). However, if you want to migrate to use
and `~/.vim/vimrc` file.

*xdg-runtime*
When the |xdg-vimrc| is used the |'runtimepath'| will be modified accordingly
to respect the |xdg-base-dir|: >
When the |xdg-vimrc| is used the 'runtimepath' and 'packpath' options will be
modified accordingly to respect the |xdg-base-dir|: >
"$XDG_CONFIG_HOME/vim,$VIMRUNTIME,/after,$XDG_CONFIG_HOME/vim/after"
<
Expand Down
8 changes: 8 additions & 0 deletions src/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,14 @@ set_init_xdg_rtp(void)
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);
Expand Down
2 changes: 2 additions & 0 deletions src/os_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ typedef struct dsc$descriptor DESC;
# 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

Expand Down
4 changes: 4 additions & 0 deletions src/testdir/test_xdg.vim
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func Test_xdg_runtime_files()
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
Expand All @@ -94,6 +95,7 @@ func Test_xdg_runtime_files()
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
Expand All @@ -112,6 +114,7 @@ func Test_xdg_runtime_files()
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
Expand All @@ -128,6 +131,7 @@ func Test_xdg_runtime_files()
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
Expand Down

0 comments on commit d9ee054

Please sign in to comment.