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.