New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] XDG support #3120
[WIP] XDG support #3120
Changes from 8 commits
9c50903
00ff3da
318b69a
793bb3c
a142616
d4fb8fe
14cb32b
faa11d5
86e7c30
beebfb9
81302c6
134879b
b7a56fd
60feda5
a1429b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -427,6 +427,31 @@ char *vim_getenv(const char *name) | |
return xstrdup(kos_env_path); | ||
} | ||
|
||
// XDG Base Directory expansion. | ||
if (strncmp(name, "XDG_", 4) == 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sneaking this into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As it already expand $HOME and others, I thought it was appropriate, but I don't mind changing. I should have updated the doc, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's see what others think. I haven't had chance to carefully think about it. |
||
const char *home = vim_getenv("HOME"); | ||
if (!home) { | ||
return NULL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation is wrong There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
|
||
const char *home_suffix = ""; | ||
if (strcmp(name, "XDG_DATA_HOME") == 0) { | ||
home_suffix = "/.local/share/"; | ||
} else if (strcmp(name, "XDG_CONFIG_HOME") == 0) { | ||
home_suffix = "/.config/"; | ||
} else if (strcmp(name, "XDG_CACHE_HOME") == 0) { | ||
home_suffix = "/.cache/"; | ||
} else if (strcmp(name, "XDG_RUNTIME_DIR") == 0) { | ||
return xstrdup("/tmp/"); // Arbitrary value, any idea? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another option is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fmoralesc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I meant a directory inside /run, not something called "..." inside it. Sorry for the confusion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In any case, it looks like nvim doesn't use XDG_RUNTIME_DIR at all? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that $XDG_RUNTIME_DIR/nvim… is a proper default place for NeoVim sockets, much better then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Do not forget to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nvim doesn't use XDG_RUNTIME_DIR, but it should. I don't know what to modify, though. I think /tmp is a good default. See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables : it MUST NOT survive a reboot. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yamakaky You have completely wrong priorities. Note: XDG_RUNTIME_DIR according to the spec is not something that should be used like $XDG_RUNTIME_DIR/$USER/…, it is $XDG_RUNTIME_DIR/…. |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By the way, where are
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added commits that show how in my opinion this should look like: b4331ac, its parent and parent of its parent. Feel free to pull them (branch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Err. I forgot about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some reordering: e6c09b1. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. It's just that it's a bigger change than simply using __HOME, since you can't expand XDG___DIR in macros, it needs code changes. |
||
|
||
// We need to apprend the prefix to the HOME path. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. apprend -> append There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops ^^ |
||
char *value = vim_getenv("HOME"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You already have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
value = xrealloc(value, strlen(value) + strlen(home_suffix) + 1); | ||
strcat(value, home_suffix); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clint is warning about this strcat() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Saw that, on it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you already have to compute length better use
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done : 86e7c30 |
||
return value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Memory leak: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use |
||
} | ||
|
||
bool vimruntime = (strcmp(name, "VIMRUNTIME") == 0); | ||
if (!vimruntime && strcmp(name, "VIM") != 0) { | ||
return NULL; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,10 @@ | |
#define SPECIAL_WILDCHAR "`'{" | ||
|
||
// Unix system-dependent file names | ||
|
||
#define NVIM_CONF_DIR "$XDG_CONFIG_HOME/nvim/" | ||
#define NVIM_DATA_DIR "$XDG_DATA_HOME/nvim/" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure the leading slashes should be here? Wouldn't this result in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't matter, test with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wow, that's interesting. Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
#ifndef SYS_VIMRC_FILE | ||
# define SYS_VIMRC_FILE "$VIM/nvimrc" | ||
#endif | ||
|
@@ -28,46 +32,50 @@ | |
#ifndef SYNTAX_FNAME | ||
# define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim" | ||
#endif | ||
// Not used anymore ? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WIP. Do we also drop EXINIT ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. |
||
#ifndef USR_EXRC_FILE | ||
# define USR_EXRC_FILE "~/.exrc" | ||
#endif | ||
#ifndef USR_VIMRC_FILE | ||
# define USR_VIMRC_FILE "~/.nvimrc" | ||
# define USR_VIMRC_FILE NVIM_CONF_DIR "/init.vim" | ||
#endif | ||
// Not used anymore ? | ||
#ifndef USR_VIMRC_FILE2 | ||
# define USR_VIMRC_FILE2 "~/.nvim/nvimrc" | ||
#endif | ||
// Not used anymore ? | ||
#ifndef EXRC_FILE | ||
# define EXRC_FILE ".exrc" | ||
#endif | ||
// Not used anymore ? | ||
#ifndef VIMRC_FILE | ||
# define VIMRC_FILE ".nvimrc" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... So what about EXRC_FILE you told me to drop ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, sorry, I thought 'exrc' was related to .exrc |
||
#endif | ||
#ifndef VIMINFO_FILE | ||
# define VIMINFO_FILE "~/.nviminfo" | ||
# define VIMINFO_FILE NVIM_DATA_DIR "/viminfo" | ||
#endif | ||
|
||
// Default for 'backupdir'. | ||
#ifndef DFLT_BDIR | ||
# define DFLT_BDIR ".,~/tmp,~/" | ||
# define DFLT_BDIR ".,$XDG_DATA_HOME/nvim/backup/" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NVIM_DATA_DIR |
||
#endif | ||
|
||
// Default for 'directory'. | ||
#ifndef DFLT_DIR | ||
# define DFLT_DIR ".,~/tmp,/var/tmp,/tmp" | ||
# define DFLT_DIR "$XDG_DATA_HOME/nvim/swap//" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NVIM_DATA_DIR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow, I forgot to use it for half the variables ^^ |
||
#endif | ||
|
||
// Default for 'viewdir'. | ||
#ifndef DFLT_VDIR | ||
# define DFLT_VDIR "~/.nvim/view" | ||
# define DFLT_VDIR "$XDG_DATA_HOME/nvim/view/" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are not views used as configuration? I would use XDG_CONFIG_HOME here. Also this is naturally shortcuted with NVIM_{DATA,CONF}_DIR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you are right. |
||
#endif | ||
|
||
#ifdef RUNTIME_GLOBAL | ||
# define DFLT_RUNTIMEPATH "~/.nvim," RUNTIME_GLOBAL ",$VIMRUNTIME," \ | ||
RUNTIME_GLOBAL "/after,~/.nvim/after" | ||
# define DFLT_RUNTIMEPATH NVIM_CONF_DIR "," RUNTIME_GLOBAL ",$VIMRUNTIME," \ | ||
RUNTIME_GLOBAL "/after," NVIM_CONF_DIR "/after" | ||
#else | ||
# define DFLT_RUNTIMEPATH \ | ||
"~/.nvim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.nvim/after" | ||
NVIM_CONF_DIR ",$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after," NVIM_CONF_DIR "/after" | ||
#endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This entire |
||
|
||
#endif // NVIM_OS_UNIX_DEFS_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function comment above needs to be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done