vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 41480cd407ed66bdbb8f55265871e99b9d41c6b7
parent 1b5d552ae281a20ccabe7321f30e8a6a61783fc0
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Tue, 29 Dec 2015 12:17:44 +0100

vis: fix default lua package.path and support $XDG_CONFIG_HOME

The ordered list of paths for startup and lexer files is:

 - $VIS_PATH/{,lexers}
 - $XDG_CONFIG_HOME/vis/{,lexers} (defaulting to $HOME/.config/vis/{,lexers})
 - /usr/local/share/vis/{,lexers}
 - /usr/share/vis/{,lexers}
 - package.path (standard lua search path)

Diffstat:
Mlexers/README.md | 2+-
Mvis-lua.c | 35++++++++++++++++++++++-------------
2 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/lexers/README.md b/lexers/README.md @@ -9,7 +9,7 @@ based lexers from the [Scintillua](http://foicica.com/scintillua/) project. Vis searches the lexers in the following locations: * `$VIS_PATH/lexers` - * `$HOME/.vis/lexers` + * `$XDG_CONFIG_HOME/vis/lexers` * `/usr/local/share/vis/lexers` * `/usr/share/vis/lexers` * `package.path` (standard lua search path) diff --git a/vis-lua.c b/vis-lua.c @@ -359,17 +359,10 @@ void vis_lua_start(Vis *vis) { vis->lua = L; luaL_openlibs(L); - /* try to get users home directory */ - const char *home = getenv("HOME"); - if (!home || !*home) { - struct passwd *pw = getpwuid(getuid()); - if (pw) - home = pw->pw_dir; - } /* extends lua's package.path with: * - $VIS_PATH/{,lexers} - * - $HOME/.vis{,lexers} + * - $XDG_CONFIG_HOME/vis/{,lexers} (defaulting to $HOME/.config/vis/{,lexers}) * - /usr/local/share/vis/{,lexers} * - /usr/share/vis/{,lexers} * - package.path (standard lua search path) @@ -387,17 +380,33 @@ void vis_lua_start(Vis *vis) { paths++; } - if (home && *home) { + /* try to get users home directory */ + const char *home = getenv("HOME"); + if (!home || !*home) { + struct passwd *pw = getpwuid(getuid()); + if (pw) + home = pw->pw_dir; + } + + const char *xdg_config = getenv("XDG_CONFIG_HOME"); + if (xdg_config) { + lua_pushstring(L, xdg_config); + lua_pushstring(L, "/vis/?.lua;"); + lua_pushstring(L, xdg_config); + lua_pushstring(L, "/vis/lexers/?.lua;"); + lua_concat(L, 4); + paths++; + } else if (home && *home) { lua_pushstring(L, home); - lua_pushstring(L, "/.vis/?.lua;"); + lua_pushstring(L, "/.config/vis/?.lua;"); lua_pushstring(L, home); - lua_pushstring(L, "/.vis/lexers/?.lua;"); + lua_pushstring(L, "/.config/vis/lexers/?.lua;"); lua_concat(L, 4); paths++; } - lua_pushstring(L, "/usr/local/share/vis/?.lua;/usr/local/share/vis/lexers/?.lua"); - lua_pushstring(L, "/usr/share/vis/?.lua;/usr/share/vis/lexers/?.lua"); + lua_pushstring(L, "/usr/local/share/vis/?.lua;/usr/local/share/vis/lexers/?.lua;"); + lua_pushstring(L, "/usr/share/vis/?.lua;/usr/share/vis/lexers/?.lua;"); lua_getfield(L, -paths, "path"); lua_concat(L, paths); lua_setfield(L, -2, "path");