[PATCH] XDG Base Directory Specification support

951 views
Skip to first unread message

Jean-François Bignolles

unread,
Mar 3, 2014, 5:20:47 PM3/3/14
to vim...@googlegroups.com
Hello,

the attached patch adds support for XDG Base Directory Specification.
This is a compile-time option ("--enable-xdg-basedir"), off by default.
See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
for details.

When enabled:

- Vim handles environment variables XDG_CACHE_HOME, XDG_CONFIG_HOME
and XDG_DATA_HOME as specified in the spec (i.e. expands them with
default values if they aren't defined).

- Directory options and user configuration files handling are changed
to enable XDG organization (by using XDG_* variables).

In the patch, look for 'os_unix.txt' diff for more details.

jfb

vim-xdg_basedir.patch

Anton Bobrov

unread,
Mar 4, 2014, 4:54:15 AM3/4/14
to vim...@googlegroups.com
> 'viewdir' $XDG_CACHE_HOME/vim/view

My precious views are treated as "user specific non-essential data files". Sweet.

glts

unread,
Mar 4, 2014, 9:36:46 AM3/4/14
to vim...@googlegroups.com
+1 for this initiative.


--
David

Nikolay Pavlov

unread,
Mar 4, 2014, 9:48:49 AM3/4/14
to vim...@googlegroups.com


On Mar 4, 2014 7:30 AM, "Jean-François Bignolles" <jf.big...@gmail.com> wrote:
>
> Hello,
>
> the attached patch adds support for XDG Base Directory Specification.
> This is a compile-time option ("--enable-xdg-basedir"), off by default.
> See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
> for details.
>
> When enabled:
>
> - Vim handles environment variables XDG_CACHE_HOME, XDG_CONFIG_HOME
>   and XDG_DATA_HOME as specified in the spec (i.e. expands them with
>   default values if they aren't defined).

What about making this part not depend on configure options?

>
> - Directory options and user configuration files handling are changed
>   to enable XDG organization (by using XDG_* variables).
>
> In the patch, look for 'os_unix.txt' diff for more details.

Views should go to config dir. These are not caches.

Swap files to XDG_RUNTIME_DIR and do so by default.

Also what about populating &rtp from XDG_CONFIG_DIRS?

>
> jfb
>
> --
> --
> You received this message from the "vim_dev" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Jean-François Bignolles

unread,
Mar 4, 2014, 3:13:47 PM3/4/14
to vim...@googlegroups.com
Hello,

Le mardi 4 mars 2014 10:54:15 UTC+1, Anton Bobrov a écrit :
> > 'viewdir' $XDG_CACHE_HOME/vim/view
>
> My precious views are treated as "user specific non-essential data files". Sweet.

You're right, 'viewdir' must be based on XDG_CONFIG_HOME
instead of XDG_CACHE_HOME. I've fixed it in the revised patch.

jfb
vim-xdg_basedir-2.patch

Jean-François Bignolles

unread,
Mar 4, 2014, 3:49:52 PM3/4/14
to vim...@googlegroups.com
Hello,

Le mardi 4 mars 2014 15:48:49 UTC+1, ZyX a écrit :
> On Mar 4, 2014 7:30 AM, "Jean-François Bignolles" <jf.big...@gmail.com> wrote:
>
> > the attached patch adds support for XDG Base Directory Specification.
> > This is a compile-time option ("--enable-xdg-basedir"), off by default.
>
> What about making this part not depend on configure options?

If I had been the only person to decide what must be integrated in Vim,
I would have made this a non-option. By making it an off-by-default option,
the patch is more likely to be integrated (I suppose). Maybe it will be
turned to an on-by-default option after (or even completely removed).

> Views should go to config dir. These are not caches.
Yes, it's fixed in 2nd patch.

> Swap files to XDG_RUNTIME_DIR and do so by default.

According to the spec (v0.7):
"The lifetime of the directory MUST be bound to the user being logged in"
"It MUST be created when the user first logs in and if the user fully logs out the directory MUST be removed."
"Files in the directory MUST not survive reboot or a full logout/login cycle."

So, what if the user was editing files with Vim when he got brutally
disconnected (for whatever reason)? I agree on runtime status of swap
files, but they're in a safer place with XDG_CACHE_HOME
(which is user-managed).

Moreover, there is no default value for this variable; what to do in case
of missing definition?

> Also what about populating &rtp from XDG_CONFIG_DIRS?
My patch is for user files, XDG_CONFIG_DIRS is for system files.
System files locations are rather configured by distribution vendors.
Plus, this variable contains a list of directories instead of a
single directory, which makes things more complicated.
So for now I won't touch it - but I'll think about it.

jfb

Nikolay Pavlov

unread,
Mar 4, 2014, 4:33:36 PM3/4/14
to vim...@googlegroups.com


On Mar 5, 2014 12:49 AM, "Jean-François Bignolles" <jf.big...@gmail.com> wrote:
>
> Hello,
>
> Le mardi 4 mars 2014 15:48:49 UTC+1, ZyX a écrit :
> > On Mar 4, 2014 7:30 AM, "Jean-François Bignolles" <jf.big...@gmail.com> wrote:
> >
> > > the attached patch adds support for XDG Base Directory Specification.
> > > This is a compile-time option ("--enable-xdg-basedir"), off by default.
> >
> > What about making this part not depend on configure options?
>
> If I had been the only person to decide what must be integrated in Vim,
> I would have made this a non-option. By making it an off-by-default option,
> the patch is more likely to be integrated (I suppose). Maybe it will be
> turned to an on-by-default option after (or even completely removed).

I mean that missing XDG* vars should be expanded to default values like Vim does for HOME on windows and VIM/VIMRUNTIME without special configure option. Such expansion is unlikely to break anything.

But new &option values should depend on configure switch or, better, command-line option (e.g. --xdg/--no-xdg pair with the default chosen by the configure).

>
> > Views should go to config dir. These are not caches.
> Yes, it's fixed in 2nd patch.
>
> > Swap files to XDG_RUNTIME_DIR and do so by default.
>
> According to the spec (v0.7):
> "The lifetime of the directory MUST be bound to the user being logged in"
> "It MUST be created when the user first logs in and if the user fully logs out the directory MUST be removed."
> "Files in the directory MUST not survive reboot or a full logout/login cycle."
>
> So, what if the user was editing files with Vim when he got brutally
> disconnected (for whatever reason)? I agree on runtime status of swap
> files, but they're in a safer place with XDG_CACHE_HOME
> (which is user-managed).

If he is disconnected he should have used screen/tmux/dtach. What is wanted to be kept is usually not only what is saved in swap file. Though there are also cases of e.g. power fail which are not handled by screen.

But AFAIR you still have current directory as the first one. I think it should be the second, after $XDG_whatever.

>
> Moreover, there is no default value for this variable; what to do in case
> of missing definition?

Proceed to the next directory in the list.

>
> > Also what about populating &rtp from XDG_CONFIG_DIRS?
> My patch is for user files, XDG_CONFIG_DIRS is for system files.
> System files locations are rather configured by distribution vendors.
> Plus, this variable contains a list of directories instead of a
> single directory, which makes things more complicated.
> So for now I won't touch it - but I'll think about it.
>
> jfb
>

Gary Johnson

unread,
Mar 4, 2014, 5:47:15 PM3/4/14
to vim...@googlegroups.com
On 2014-03-05, Nikolay Pavlov wrote:
>
> On Mar 5, 2014 12:49 AM, "Jean-François Bignolles" wrote:

> > Le mardi 4 mars 2014 15:48:49 UTC+1, ZyX a écrit :

> > > Swap files to XDG_RUNTIME_DIR and do so by default.
> >
> > According to the spec (v0.7):
> > "The lifetime of the directory MUST be bound to the user being logged in"
> > "It MUST be created when the user first logs in and if the user fully logs
> > out the directory MUST be removed."
> > "Files in the directory MUST not survive reboot or a full logout/login
> > cycle."
> >
> > So, what if the user was editing files with Vim when he got brutally
> > disconnected (for whatever reason)? I agree on runtime status of swap
> > files, but they're in a safer place with XDG_CACHE_HOME
> > (which is user-managed).
>
> If he is disconnected he should have used screen/tmux/dtach. What is wanted to
> be kept is usually not only what is saved in swap file. Though there are also
> cases of e.g. power fail which are not handled by screen.
>
> But AFAIR you still have current directory as the first one. I think it should
> be the second, after $XDG_whatever.

Definitely not. Swap files should be put in some directory that is
likely to survive a system crash. If some user wishes to shoot
himself in the foot by putting swap files in a volatile directory
such as XDG_RUNTIME_DIR, fine, but Vim should not help him do it.

I don't put swap files in the current directory, either, but at
least that is a relatively safe default.

Regards,
Gary

Bram Moolenaar

unread,
May 28, 2014, 1:49:50 PM5/28/14
to Jean-François Bignolles, vim...@googlegroups.com
I had a look at this.

First a small remark about the patch:

Places for your personal initializations:
- Unix $HOME/.vimrc or $HOME/.vim/vimrc
+ Unix $HOME/.vimrc or $HOME/.vim/vimrc;
+ with |+xdg_basedir| feature, it can also be
+ $XDG_CONFIG_HOME/vim/vimrc (first place)

That should be $XDG_CONFIG_HOME/vim, without the /vimrc.

Problem with making this a compile-time feature is that if the binary is
shared with several users, or it's part of a precompiled package,
suddenly the user has to put his Vim files elsewhere. This will quickly
lead to two different binaries, so that users can select the one that
fits them.

Making this a runtime option is problematic, since the changes are in
the default values.

This is far from ideal, I expect it to cause more trouble than it would
ever solve. Who actually uses these $XDG_ variables?

Probably the only way is to ADD these $XDG_ directories, after the
current directories. So that they only get used if the old directories
do not exist. Then users getting a new binary will not notice a
difference, and are free to move their files to the new location, if
that is that they prefer.

In practice this probably means users would do:
mv ~/.vim ~/.config/vim
mv ~/.vimrc ~/.config/vim/vimrc

--
hundred-and-one symptoms of being an internet addict:
223. You set up a web-cam as your home's security system.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Jean-François Bignolles

unread,
Jun 1, 2014, 4:54:39 PM6/1/14
to vim...@googlegroups.com, jf.big...@gmail.com
Hi,

I made a new patch (based on vim 7.4.315).

Le mercredi 28 mai 2014 19:49:50 UTC+2, Bram Moolenaar a écrit :

> I had a look at this.
>
> First a small remark about the patch:
>
> Places for your personal initializations:
>
> - Unix $HOME/.vimrc or $HOME/.vim/vimrc
> + Unix $HOME/.vimrc or $HOME/.vim/vimrc;
> + with |+xdg_basedir| feature, it can also be
> + $XDG_CONFIG_HOME/vim/vimrc (first place)
>
> That should be $XDG_CONFIG_HOME/vim, without the /vimrc.

No. "$XDG_CONFIG_HOME/vim" is a *DIRECTORY*, not a file; it's an alternative
choice for "$HOME/vim". This documentation extract talks about the "vimrc",
the main Vim user configuration *FILE*.

> Problem with making this a compile-time feature is that if the binary is
> shared with several users, or it's part of a precompiled package,
> suddenly the user has to put his Vim files elsewhere. This will quickly
> lead to two different binaries, so that users can select the one that
> fits them.
>
> Making this a runtime option is problematic, since the changes are in
> the default values.

In the new patch there is no compile-time switch anymore; XDG support is
always enabled, but in a way where compatibility with non-XDG version is
preserved.

> This is far from ideal, I expect it to cause more trouble than it would
> ever solve. Who actually uses these $XDG_ variables?

For end user, defining $XDG_ variables is is optional, not mandatory.
For the developper wishing to support XDG, interpreting them is a
requirement: it allows the user to overide default locations.
That's why special logic is added for $XDG_ variables expansion.

> Probably the only way is to ADD these $XDG_ directories, after the
> current directories. So that they only get used if the old directories
> do not exist. Then users getting a new binary will not notice a
> difference, and are free to move their files to the new location, if
> that is that they prefer.

The new patch does this.

> In practice this probably means users would do:
> mv ~/.vim ~/.config/vim
> mv ~/.vimrc ~/.config/vim/vimrc

Exactly.

So, let's give a short description:
- vimrc: "$XDG_CONFIG_HOME/vim/vimrc" is added (3rd choice).
- gvimrc: "$XDG_CONFIG_HOME/vim/gvimrc" is added (3rd choice).
- viminfo path is unchanged, but the user can use 'viminfo' option.
- 'backupdir' and 'directory': "$XDG_CACHE_HOME/vim" is added (2nd choice);
if the user doesn't create this directory, Vim behaviour is unchanged.
- 'runtimepath': "$XDG_CONFIG_HOME/vim" and "$XDG_CONFIG_HOME/vim/after"
are added, but don't replace "$HOME/.vim" and "$HOME/.vim/after".
- 'viewdir' is unchanged (since it's a single directory option).

regards,
jfb

Note: can't make "Attach a file" to work, so the patch is appended...

--------------------------------------------------------->8
diff -r 07aa56179a10 runtime/doc/gui.txt
--- a/runtime/doc/gui.txt Thu May 29 11:47:40 2014 +0200
+++ b/runtime/doc/gui.txt Sun Jun 01 22:10:28 2014 +0200
@@ -1,4 +1,4 @@
-*gui.txt* For Vim version 7.4. Last change: 2014 Mar 08
+*gui.txt* For Vim version 7.4. Last change: 2014 May 30


VIM REFERENCE MANUAL by Bram Moolenaar
@@ -66,7 +66,8 @@
- If the GVIMINIT environment variable exists and is not empty, it is
executed as an Ex command.
- If the user gvimrc file exists, it is sourced. The name of this file is
- normally "$HOME/.gvimrc". You can check this with ":version".
+ normally "$HOME/.gvimrc". It can also be "$XDG_CONFIG_HOME/vim/gvimrc"
+ (see |xdg_basedir|). You can check this with ":version".
- For Win32, when $HOME is not set, "$VIM\_gvimrc" is used.
- When a "_gvimrc" file is not found, ".gvimrc" is tried too. And vice
versa.
diff -r 07aa56179a10 runtime/doc/options.txt
--- a/runtime/doc/options.txt Thu May 29 11:47:40 2014 +0200
+++ b/runtime/doc/options.txt Sun Jun 01 22:10:28 2014 +0200
@@ -1,4 +1,4 @@
-*options.txt* For Vim version 7.4. Last change: 2014 May 13
+*options.txt* For Vim version 7.4. Last change: 2014 May 30


VIM REFERENCE MANUAL by Bram Moolenaar
@@ -988,7 +988,7 @@
*'backupdir'* *'bdir'*
'backupdir' 'bdir' string (default for Amiga: ".,t:",
for MS-DOS and Win32: ".,$TEMP,c:/tmp,c:/temp"
- for Unix: ".,~/tmp,~/")
+ for Unix: ".,$XDG_CACHE_HOME/vim,~/tmp,~/")
global
{not in Vi}
List of directories for the backup file, separated with commas.
@@ -1008,7 +1008,8 @@
name, precede it with a backslash.
- To include a comma in a directory name precede it with a backslash.
- A directory name may end in an '/'.
- - Environment variables are expanded |:set_env|.
+ - Environment variables are expanded |:set_env|; see |xdg_basedir|
+ for expansion of $XDG_CACHE_HOME.
- Careful with '\' characters, type one before a space, type two to
get one in the option (see |option-backslash|), for example: >
:set bdir=c:\\tmp,\ dir\\,with\\,commas,\\\ dir\ with\ spaces
@@ -2478,7 +2479,7 @@
*'directory'* *'dir'*
'directory' 'dir' string (default for Amiga: ".,t:",
for MS-DOS and Win32: ".,$TEMP,c:\tmp,c:\temp"
- for Unix: ".,~/tmp,/var/tmp,/tmp")
+ for Unix: ".,$XDG_CACHE_HOME/vim,~/tmp,/var/tmp,/tmp")
global
List of directory names for the swap file, separated with commas.
- The swap file will be created in the first directory where this is
@@ -2503,7 +2504,8 @@
name, precede it with a backslash.
- To include a comma in a directory name precede it with a backslash.
- A directory name may end in an ':' or '/'.
- - Environment variables are expanded |:set_env|.
+ - Environment variables are expanded |:set_env|; see |xdg_basedir|
+ for expansion of $XDG_CACHE_HOME.
- Careful with '\' characters, type one before a space, type two to
get one in the option (see |option-backslash|), for example: >
:set dir=c:\\tmp,\ dir\\,with\\,commas,\\\ dir\ with\ spaces
@@ -5726,9 +5728,11 @@
*'runtimepath'* *'rtp'* *vimfiles*
'runtimepath' 'rtp' string (default:
Unix: "$HOME/.vim,
+ $XDG_CONFIG_HOME/vim,
$VIM/vimfiles,
$VIMRUNTIME,
$VIM/vimfiles/after,
+ $XDG_CONFIG_HOME/vim/after,
$HOME/.vim/after"
Amiga: "home:vimfiles,
$VIM/vimfiles,
@@ -5774,6 +5778,9 @@

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

+ Environment variables are expanded |:set_env|; see |xdg_basedir|
+ for expansion of $XDG_CONFIG_HOME.
+
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
diff -r 07aa56179a10 runtime/doc/os_unix.txt
--- a/runtime/doc/os_unix.txt Thu May 29 11:47:40 2014 +0200
+++ b/runtime/doc/os_unix.txt Sun Jun 01 22:10:28 2014 +0200
@@ -1,4 +1,4 @@
-*os_unix.txt* For Vim version 7.4. Last change: 2005 Mar 29
+*os_unix.txt* For Vim version 7.4. Last change: 2014 May 30


VIM REFERENCE MANUAL by Bram Moolenaar
@@ -57,4 +57,37 @@
The file "tools/vim132" is a shell script that can be used to put Vim in 132
column mode on a vt100 and lookalikes.

+ *xdg_basedir* *$XDG_CACHE_HOME* *$XDG_CONFIG_HOME* *$XDG_DATA_HOME*
+Vim supports the XDG Base Directory specification. This means that:
+
+ 1. The XDG environment variables mentionned above (names in XDG_*) are
+ handled by Vim in a special way. If they aren't defined or are empty,
+ Vim expands them with the default value of the XDG specification:
+
+ VARIABLE DEFAULT VALUE~
+ $XDG_CACHE_HOME $HOME/.cache
+ $XDG_CONFIG_HOME $HOME/.config
+ $XDG_DATA_HOME $HOME/.local/share
+
+ 2. The following options have their default value changed with respect
+ to their non-XDG Unix counterparts:
+
+ OPTION DEFAULT VALUE~
+ 'backupdir' .,$XDG_CACHE_HOME/vim,~/,/tmp
+ 'directory' .,$XDG_CACHE_HOME/vim,~/tmp,/var/tmp,/tmp
+ 'runtimepath' $HOME/.vim,$XDG_CONFIG_HOME/vim,$VIM,$VIMRUNTIME,
+ $VIM/after,$XDG_CONFIG_HOME/vim/after,$HOME/.vim/after
+
+ 3. For each list of candidate user configuration files, an alternative
+ is added:
+
+ WHAT PREPENDED NAME~
+ |vimrc| $XDG_CONFIG_HOME/vim/vimrc
+ |gvimrc| $XDG_CONFIG_HOME/vim/gvimrc
+
+See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
+for more details.
+
+User may also use $XDG_ paths with 'viminfo' and the 'viewdir' options.
+
vim:tw=78:ts=8:ft=help:norl:
diff -r 07aa56179a10 runtime/doc/starting.txt
--- a/runtime/doc/starting.txt Thu May 29 11:47:40 2014 +0200
+++ b/runtime/doc/starting.txt Sun Jun 01 22:10:28 2014 +0200
@@ -1,4 +1,4 @@
-*starting.txt* For Vim version 7.4. Last change: 2014 Mar 29
+*starting.txt* For Vim version 7.4. Last change: 2014 May 30


VIM REFERENCE MANUAL by Bram Moolenaar
@@ -758,7 +758,8 @@
name. Also see |vimrc-intro|.

Places for your personal initializations:
- Unix $HOME/.vimrc or $HOME/.vim/vimrc
+ Unix $HOME/.vimrc, $HOME/.vim/vimrc
+ or $XDG_CONFIG_HOME/vim/vimrc (see |xdg_basedir|)
OS/2 $HOME/.vimrc, $HOME/vimfiles/vimrc
or $VIM/.vimrc (or _vimrc)
MS-Windows $HOME/_vimrc, $HOME/vimfiles/vimrc
@@ -769,9 +770,13 @@
The files are searched in the order specified above and only the first
one that is found is read.

- RECOMMENDATION: Put all your Vim configuration stuff in the
- $HOME/.vim/ directory ($HOME/vimfiles/ for MS-Windows). That makes it
- easy to copy it to another system.
+ RECOMMENDATION: Put all your Vim configuration stuff in the preferred
+ directory. That makes it easy to copy it to another system.
+ The preferred directory is:
+ Unix $HOME/.vim or $XDG_CONFIG_HOME/vim/vimrc
+ (see |xdg_basedir|)
+ Ms-Windows $HOME/vimfiles
+ OS/2 $HOME/vimfiles

If Vim was started with "-u filename", the file "filename" is used.
All following initializations until 4. are skipped. $MYVIMRC is not
@@ -804,6 +809,7 @@
- The user vimrc file(s):
"$HOME/.vimrc" (for Unix and OS/2) (*)
"$HOME/.vim/vimrc" (for Unix and OS/2) (*)
+ "$XDG_CONFIG_HOME/vim/vimrc" (Unix: see |xdg_basedir|) (*)
"s:.vimrc" (for Amiga) (*)
"home:.vimrc" (for Amiga) (*)
"home:vimfiles:vimrc" (for Amiga) (*)
@@ -895,6 +901,7 @@

Some hints on using initializations:

+
Standard setup:
Create a vimrc file to set the default settings and mappings for all your edit
sessions. Put it in a place so that it will be found by 3b:
diff -r 07aa56179a10 src/misc1.c
--- a/src/misc1.c Thu May 29 11:47:40 2014 +0200
+++ b/src/misc1.c Sun Jun 01 22:10:28 2014 +0200
@@ -14,6 +14,13 @@
#include "vim.h"
#include "version.h"

+/* When Gtk GUI is enabled, we can use GLib support functions
+ * of XDG Base Directory
+ */
+#ifdef FEAT_GUI_GTK
+#include <glib.h>
+#endif
+
static char_u *vim_version_dir __ARGS((char_u *vimdir));
static char_u *remove_tail __ARGS((char_u *p, char_u *pend, char_u *name));
#if defined(FEAT_CMDL_COMPL)
@@ -4141,9 +4148,61 @@
*dst = NUL;
}

+/* XDG environment variable identifier (<=> variable name) */
+typedef enum {
+ XDG_CACHE_HOME,
+ XDG_CONFIG_HOME,
+ XDG_DATA_HOME
+} XdgEnvId_T;
+
+/* XDG environment variable names (indexed by 'XdgEnvId_T' above) */
+static const char_u *xdg_env_name[] = {
+ "XDG_CACHE_HOME",
+ "XDG_CONFIG_HOME",
+ "XDG_DATA_HOME"
+};
+
+#ifndef FEAT_GUI_GTK
+/* No Gtk (Glib more exactly) XDG support function, use internal code instead */
+
+/*
+ * Return XDG environment variable value or "emulated" one.
+ */
+ char_u *
+vim_getxdg (id)
+ XdgEnvId_T id; /* XDG environment variable identifier */
+{
+ /* Default [unexpanded] values, indexed by 'id' */
+ static const char_u *def_value[] = {
+ /* XDG_CACHE_HOME */ "$HOME/.cache",
+ /* XDG_CONFIG_HOME */ "$HOME/.config",
+ /* XDG_DATA_HOME */ "$HOME/.local/share"
+ };
+ /* Cached values */
+ static char_u *env_value[] = { NULL, NULL, NULL };
+
+ char_u *dir;
+
+ if (env_value[id] == NULL) {
+ dir = mch_getenv (xdg_env_name[id]);
+
+ if ((dir != NULL) && (dir[0] != NUL))
+ /* Variable exists and isn't empty => can use it */
+ dir = vim_strsave (dir);
+ else {
+ /* Use expanded default value */
+ dir = alloc (MAXPATHL);
+ expand_env ((char_u*)def_value[id], dir, MAXPATHL);
+ }
+ env_value[id] = dir;
+ }
+ return env_value[id];
+}
+#endif /* !FEAT_GUI_GTK */
/*
* Vim's version of getenv().
* Special handling of $HOME, $VIM and $VIMRUNTIME.
+ * Also special handling of some $XDG_* variables.
* Also does ACP to 'enc' conversion for Win32.
* "mustfree" is set to TRUE when returned is allocated, it must be
* initialized to FALSE by the caller.
@@ -4188,6 +4247,30 @@
return p;
}

+ /* Retrieve XDG environment variable (maybe virtual) value */
+ if (STRCMP (name, xdg_env_name[XDG_CACHE_HOME]) == 0) {
+#ifdef FEAT_GUI_GTK
+ return (char_u*) g_get_user_cache_dir ();
+#else
+ return vim_getxdg (XDG_CACHE_HOME);
+#endif
+ }
+
+ if (STRCMP (name, xdg_env_name[XDG_CONFIG_HOME]) == 0) {
+#ifdef FEAT_GUI_GTK
+ return (char_u*) g_get_user_config_dir ();
+#else
+ return vim_getxdg (XDG_CONFIG_HOME);
+#endif
+ }
+
+ if (STRCMP (name, xdg_env_name[XDG_DATA_HOME]) == 0) {
+#ifdef FEAT_GUI_GTK
+ return (char_u*) g_get_user_data_dir ();
+#else
+ return vim_getxdg (XDG_DATA_HOME);
+#endif
+ }
vimruntime = (STRCMP(name, "VIMRUNTIME") == 0);
if (!vimruntime && STRCMP(name, "VIM") != 0)
return NULL;
diff -r 07aa56179a10 src/os_unix.h
--- a/src/os_unix.h Thu May 29 11:47:40 2014 +0200
+++ b/src/os_unix.h Sun Jun 01 22:10:28 2014 +0200
@@ -309,11 +309,14 @@
# endif
#endif

-#if !defined(USR_VIMRC_FILE3) && defined(OS2)
-# define USR_VIMRC_FILE3 "$VIM/.vimrc"
-#endif
-#if !defined(USR_VIMRC_FILE3) && defined(VMS)
-# define USR_VIMRC_FILE3 "sys$login:_vimrc"
+#ifndef USR_VIMRC_FILE3
+# if defined(OS2)
+# define USR_VIMRC_FILE3 "$VIM/.vimrc"
+# elif defined(VMS)
+# define USR_VIMRC_FILE3 "sys$login:_vimrc"
+# else
+# define USR_VIMRC_FILE3 "$XDG_CONFIG_HOME/vim/vimrc"
+# endif
#endif

#ifndef USR_GVIMRC_FILE
@@ -336,9 +339,11 @@
# endif
#endif

-#ifdef VMS
-# ifndef USR_GVIMRC_FILE3
-# define USR_GVIMRC_FILE3 "sys$login:_gvimrc"
+#ifndef USR_GVIMRC_FILE3
+# if defined(VMS)
+# define USR_GVIMRC_FILE3 "sys$login:_gvimrc"
+# else
+# define USR_GVIMRC_FILE3 "$XDG_CONFIG_HOME/vim/gvimrc"
# endif
#endif

@@ -387,7 +392,8 @@
# ifdef VMS
# define DFLT_BDIR "./,sys$login:,tmp:"
# else
-# define DFLT_BDIR ".,~/tmp,~/" /* default for 'backupdir' */
+# define DFLT_BDIR ".,$XDG_CACHE_HOME/vim,~/tmp,~/"
+ /* default for 'backupdir' */
# endif
# endif
#endif
@@ -399,7 +405,8 @@
# ifdef VMS
# define DFLT_DIR "./,sys$login:,tmp:"
# else
-# define DFLT_DIR ".,~/tmp,/var/tmp,/tmp" /* default for 'directory' */
+# define DFLT_DIR ".,$XDG_CACHE_HOME/vim,~/tmp,/var/tmp,/tmp"
+ /* default for 'directory' */
# endif
# endif
#endif
@@ -418,20 +425,26 @@

#define DFLT_ERRORFILE "errors.err"

-#ifdef OS2
-# define DFLT_RUNTIMEPATH "$HOME/vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/vimfiles/after"
+#ifndef RUNTIME_GLOBAL
+ #define RUNTIME_GLOBAL "$VIM/vimfiles"
+#endif
+
+#if defined(OS2)
+# define RUNTIME_USER "$HOME/vimfiles"
+#elif defined(VMS)
+# define RUNTIME_USER "sys$login:vimfiles"
#else
-# ifdef VMS
-# define DFLT_RUNTIMEPATH "sys$login:vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,sys$login:vimfiles/after"
-# else
-# ifdef RUNTIME_GLOBAL
-# define DFLT_RUNTIMEPATH "~/.vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL "/after,~/.vim/after"
-# else
-# define DFLT_RUNTIMEPATH "~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after"
-# endif
-# endif
+# define RUNTIME_USER "~/.vim,$XDG_CONFIG_HOME/vim"
+# define RUNTIME_AFTER "$XDG_CONFIG_HOME/vim/after,~/.vim/after"
#endif

+#ifndef RUNTIME_AFTER
+#define RUNTIME_AFTER RUNTIME_USER "/after"
+#endif
+
+#define DFLT_RUNTIMEPATH RUNTIME_USER "," RUNTIME_GLOBAL ",$VIMRUNTIME," \
+ RUNTIME_GLOBAL "/after," RUNTIME_AFTER
+
#ifdef OS2
/*
* Try several directories to put the temp files.

Павлов Николай Александрович

unread,
Jun 1, 2014, 5:09:05 PM6/1/14
to vim...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
AFAIR Google has extension filter in their web interface. You need to use name with a known extension; .diff is known to work.
-----BEGIN PGP SIGNATURE-----
Version: APG v1.1.1

iQI1BAEBCgAfBQJTi5ZfGBxaeVggPHp5eC52aW1AZ21haWwuY29tPgAKCRCf3UKj
HhHSvuS/EAChYfZLQZ11scLjnN4iSEkVNccxu5WhBCve0Hy7E04eXKpds56PPHGt
AWpr4oMWWhhKABBTSM1Erxs0bQSG4HrFKAQ2W52Gz2lnBgL1F88opyPIC0MZAdZA
vQYrMnqG3QBoBDswByYbFSVQGdfwf3BXxg6FKtbzy/mis7Y5gFyHDjhm5xCM4K7B
N3W4lBsV137oNtJUNwOUJlCLDrSeP07Z0XZ+5416FcSZAkrlggqHk/iU5nIH+ROI
5usCs/45B7qjyCLNNdMPhQ+YCpY76/7u7dlPbwwg2NBIaO+qneoLs9cMHL9hx8uQ
S+CiDkryEnxDVQ4IuHBufhjZr07hxwT3mJkMOtqzCedQBIs3wO28k0c5KZoa7v2G
jDhUKALpTlWf7yTUzcnVpfRn8IWD7jehgWZjivyHRNMF2lMy6I73cd2ebXi6mltI
BKANG4b33IrNP9lWWlYF6/h5+eUUFKndVLj2shCOl1t8P5cY72vDbRfsSbJibw/c
SUBtYCO1qS3FDZv3uJYffGN6FctH5vrwe1JTgRxi+nv7y/aolDHS1i1x2KJ23z5h
YbaPquEWQuAALcoAM5J4Vgao/0e3caX6GjrBdZ/Tfv5vBpXEmJDI/5vZF+3v5WCa
X+698fiRcUcX/PNN9IWka/zUhxj92A8i5x99Ns6INQ/I2XLWHsM6gA==
=dfC5
-----END PGP SIGNATURE-----

Bram Moolenaar

unread,
Jun 2, 2014, 10:43:42 AM6/2/14
to Jean-François Bignolles, vim...@googlegroups.com
Thanks for the update. I'm still a bit worried that including this
patch will cause backwards compatibility problems.

I notice you use string concatenation:

+#define RUNTIME_AFTER RUNTIME_USER "/after"

Older C compilers do not support this. I'm not sure which ones, it is
not used yet in Vim.

--
hundred-and-one symptoms of being an internet addict:
254. You wake up daily with your keyboard printed on your forehead.

ZyX

unread,
Jun 2, 2014, 1:42:38 PM6/2/14
to vim...@googlegroups.com, jf.big...@gmail.com
> +#define RUNTIME_AFTER RUNTIME_USER "/after"
>
> Older C compilers do not support this. I'm not sure which ones, it is
> not used yet in Vim.

I used it for exception messages in Python. It is also present in version.c: https://bitbucket.org/ZyX_I/vim/src/ef30fcd05203feee8ca40a23ac75eed55549c681/src/version.c#cl-52 (#if protected with comment

> * Construct the long version string. Necessary because
> * VAX C can't catenate strings in the preprocessor.

, #if checks whether we are using VMS and VAX compiler). It is used a lot in term.c: https://bitbucket.org/ZyX_I/vim/src/ef30fcd05203feee8ca40a23ac75eed55549c681/src/term.c#cl-166, https://bitbucket.org/ZyX_I/vim/src/ef30fcd05203feee8ca40a23ac75eed55549c681/src/term.c#cl-394, including #if defined(VMS)-protected https://bitbucket.org/ZyX_I/vim/src/ef30fcd05203feee8ca40a23ac75eed55549c681/src/term.c#cl-745 (note ESC_STR "some string" sequences: they expand to (char_u *)"\x27" "some string"). This all is protected with #ifdef EBCDIC though, I am not sure when this macros is defined (looks like a compatibility layer for the compilers you describe).

Thus I think it is logical to replace with code similar to that in version.c which only avoids using preprocessor string concatenation when using VMS VAX compiler. Do you really need to support this? I heard it was replaced with DEC/Compaq C which supports C89.

Jean-François Bignolles

unread,
Jun 3, 2014, 5:42:19 PM6/3/14
to vim...@googlegroups.com, jf.big...@gmail.com
Le lundi 2 juin 2014 16:43:42 UTC+2, Bram Moolenaar a écrit :
>
> I notice you use string concatenation:
>
> +#define RUNTIME_AFTER RUNTIME_USER "/after"
>
> Older C compilers do not support this. I'm not sure which ones, it is
> not used yet in Vim.

Wrong. At least in "os_unix.h", for unpatched Vim 7.4 source, line 426:

# define DFLT_RUNTIMEPATH "~/.vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL "/after,~/.vim/after"

That's why I did not ask myself any question about string litterals
concatenation. It's a C89 feature, and had probably been available
in some pre-ANSI compilers.

Example: for Amiga, look "3.7 String merging" at:

https://archive.org/stream/Manx_Aztec_C_Compiler_1986_Manx_Software_Systems#page/n45/mode/2up

regards,
jfb

Bram Moolenaar

unread,
Jun 4, 2014, 2:31:24 PM6/4/14
to Jean-François Bignolles, vim...@googlegroups.com

Jean-François Bignolles wrote:

> Le lundi 2 juin 2014 16:43:42 UTC+2, Bram Moolenaar a écrit :
> >
> > I notice you use string concatenation:
> >
> > +#define RUNTIME_AFTER RUNTIME_USER "/after"
> >
> > Older C compilers do not support this. I'm not sure which ones, it is
> > not used yet in Vim.
>
> Wrong. At least in "os_unix.h", for unpatched Vim 7.4 source, line 426:
>
> # define DFLT_RUNTIMEPATH "~/.vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL "/after,~/.vim/after"
>
> That's why I did not ask myself any question about string litterals
> concatenation. It's a C89 feature, and had probably been available
> in some pre-ANSI compilers.

Not on some systems though. The question is if this is still relevant.
I recall it not working for some Amiga compilers. But that's history.
Current Vim probably doesn't fit in memory of those systems anyway.

--
hundred-and-one symptoms of being an internet addict:
265. Your reason for not staying in touch with family is that
they do not have e-mail addresses.
Reply all
Reply to author
Forward
0 new messages