mirror of
https://github.com/neovim/neovim.git
synced 2025-09-10 13:28:19 +00:00
vim-patch:8.2.1741: pathshorten() only supports using one character
Problem: pathshorten() only supports using one character.
Solution: Add an argument to control the length. (closes vim/vim#7006)
6a33ef0deb
Cherry-pick a line in test from patch 8.2.0634.
Use Nvim's config paths in docs.
shorten_dir() returning a pointer looks a bit confusing here, as it is
actually the same pointer passed to it, and it doesn't really reduce
much code, so change it back to void.
Assigning rettv->vval.v_string = NULL is not needed if a pointer is
within 64 bits. While this is usually the case, I'm not sure if it can
be taken for granted.
This commit is contained in:
@@ -6846,12 +6846,23 @@ static void f_or(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
*/
|
||||
static void f_pathshorten(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
rettv->v_type = VAR_STRING;
|
||||
const char *const s = tv_get_string_chk(&argvars[0]);
|
||||
if (!s) {
|
||||
return;
|
||||
int trim_len = 1;
|
||||
|
||||
if (argvars[1].v_type != VAR_UNKNOWN) {
|
||||
trim_len = (int)tv_get_number(&argvars[1]);
|
||||
if (trim_len < 1) {
|
||||
trim_len = 1;
|
||||
}
|
||||
}
|
||||
|
||||
rettv->v_type = VAR_STRING;
|
||||
const char_u *p = (char_u *)tv_get_string_chk(&argvars[0]);
|
||||
if (p == NULL) {
|
||||
rettv->vval.v_string = NULL;
|
||||
} else {
|
||||
rettv->vval.v_string = vim_strsave(p);
|
||||
shorten_dir_len(rettv->vval.v_string, trim_len);
|
||||
}
|
||||
rettv->vval.v_string = shorten_dir((char_u *)xstrdup(s));
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user