mirror of
https://github.com/neovim/neovim.git
synced 2025-09-27 21:48:35 +00:00
Merge #6272 'stdpath()'
This commit is contained in:
@@ -15702,6 +15702,56 @@ static void f_split(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
p_cpo = save_cpo;
|
||||
}
|
||||
|
||||
/// "stdpath()" helper for list results
|
||||
static void get_xdg_var_list(const XDGVarType xdg, typval_T *rettv)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
const void *iter = NULL;
|
||||
list_T *const list = tv_list_alloc(kListLenShouldKnow);
|
||||
rettv->v_type = VAR_LIST;
|
||||
rettv->vval.v_list = list;
|
||||
tv_list_ref(list);
|
||||
char *const dirs = stdpaths_get_xdg_var(xdg);
|
||||
do {
|
||||
size_t dir_len;
|
||||
const char *dir;
|
||||
iter = vim_env_iter(':', dirs, iter, &dir, &dir_len);
|
||||
if (dir != NULL && dir_len > 0) {
|
||||
char *dir_with_nvim = xmemdupz(dir, dir_len);
|
||||
dir_with_nvim = concat_fnames_realloc(dir_with_nvim, "nvim", true);
|
||||
tv_list_append_string(list, dir_with_nvim, strlen(dir_with_nvim));
|
||||
xfree(dir_with_nvim);
|
||||
}
|
||||
} while (iter != NULL);
|
||||
xfree(dirs);
|
||||
}
|
||||
|
||||
/// "stdpath(type)" function
|
||||
static void f_stdpath(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = NULL;
|
||||
|
||||
const char *const p = tv_get_string_chk(&argvars[0]);
|
||||
if (p == NULL) {
|
||||
return; // Type error; errmsg already given.
|
||||
}
|
||||
|
||||
if (strcmp(p, "config") == 0) {
|
||||
rettv->vval.v_string = (char_u *)get_xdg_home(kXDGConfigHome);
|
||||
} else if (strcmp(p, "data") == 0) {
|
||||
rettv->vval.v_string = (char_u *)get_xdg_home(kXDGDataHome);
|
||||
} else if (strcmp(p, "cache") == 0) {
|
||||
rettv->vval.v_string = (char_u *)get_xdg_home(kXDGCacheHome);
|
||||
} else if (strcmp(p, "config_dirs") == 0) {
|
||||
get_xdg_var_list(kXDGConfigDirs, rettv);
|
||||
} else if (strcmp(p, "data_dirs") == 0) {
|
||||
get_xdg_var_list(kXDGDataDirs, rettv);
|
||||
} else {
|
||||
EMSG2(_("E6100: \"%s\" is not a valid stdpath"), p);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* "str2float()" function
|
||||
*/
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include "nvim/event/rstream.h"
|
||||
#include "nvim/event/wstream.h"
|
||||
#include "nvim/channel.h"
|
||||
#include "nvim/os/stdpaths_defs.h"
|
||||
|
||||
#define COPYID_INC 2
|
||||
#define COPYID_MASK (~0x1)
|
||||
|
@@ -280,6 +280,7 @@ return {
|
||||
spellsuggest={args={1, 3}},
|
||||
split={args={1, 3}},
|
||||
sqrt={args=1, func="float_op_wrapper", data="&sqrt"},
|
||||
stdpath={args=1},
|
||||
str2float={args=1},
|
||||
str2nr={args={1, 2}},
|
||||
strcharpart={args={2, 3}},
|
||||
|
@@ -88,7 +88,7 @@ char *stdpaths_get_xdg_var(const XDGVarType idx)
|
||||
///
|
||||
/// In WIN32 get_xdg_home(kXDGDataHome) returns `{xdg_directory}/nvim-data` to
|
||||
/// avoid storing configuration and data files in the same path.
|
||||
static char *get_xdg_home(const XDGVarType idx)
|
||||
char *get_xdg_home(const XDGVarType idx)
|
||||
FUNC_ATTR_WARN_UNUSED_RESULT
|
||||
{
|
||||
char *dir = stdpaths_get_xdg_var(idx);
|
||||
|
Reference in New Issue
Block a user