aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-02-07 07:13:13 +0800
committerGitHub <noreply@github.com>2022-02-07 07:13:13 +0800
commitcf86adba61d7ae93f129823eb65a0dcaf3df70c5 (patch)
tree56a429f22215a8cca22dbca44b35135d508a8b30 /src/nvim/eval.c
parent380bc4fe22e8dbd478e58d568e0d749df439fec9 (diff)
parent72816136a57adbd051c688ee3213fa9446ea48f6 (diff)
downloadrneovim-cf86adba61d7ae93f129823eb65a0dcaf3df70c5.tar.gz
rneovim-cf86adba61d7ae93f129823eb65a0dcaf3df70c5.tar.bz2
rneovim-cf86adba61d7ae93f129823eb65a0dcaf3df70c5.zip
Merge pull request #17263 from zeertzjq/vim-8.2.0208
vim-patch:8.2.{0208,0215,0942,3824,3939}: fnamemodify() patches
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index dccad5a2d0..926c385892 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -10624,12 +10624,13 @@ int modify_fname(char_u *src, bool tilde_file, size_t *usedlen, char_u **fnamep,
char_u *s, *p, *pbuf;
char_u dirname[MAXPATHL];
int c;
- int has_fullname = 0;
+ bool has_fullname = false;
+ bool has_homerelative = false;
repeat:
// ":p" - full path/file_name
if (src[*usedlen] == ':' && src[*usedlen + 1] == 'p') {
- has_fullname = 1;
+ has_fullname = true;
valid |= VALID_PATH;
*usedlen += 2;
@@ -10698,8 +10699,8 @@ repeat:
}
pbuf = NULL;
// Need full path first (use expand_env() to remove a "~/")
- if (!has_fullname) {
- if (c == '.' && **fnamep == '~') {
+ if (!has_fullname && !has_homerelative) {
+ if ((c == '.' || c == '~') && **fnamep == '~') {
p = pbuf = expand_env_save(*fnamep);
} else {
p = pbuf = (char_u *)FullName_save((char *)*fnamep, FALSE);
@@ -10708,18 +10709,33 @@ repeat:
p = *fnamep;
}
- has_fullname = 0;
+ has_fullname = false;
if (p != NULL) {
if (c == '.') {
os_dirname(dirname, MAXPATHL);
- s = path_shorten_fname(p, dirname);
- if (s != NULL) {
- *fnamep = s;
- if (pbuf != NULL) {
- xfree(*bufp); // free any allocated file name
- *bufp = pbuf;
- pbuf = NULL;
+ if (has_homerelative) {
+ s = vim_strsave(dirname);
+ home_replace(NULL, s, dirname, MAXPATHL, true);
+ xfree(s);
+ }
+ size_t namelen = STRLEN(dirname);
+
+ // Do not call shorten_fname() here since it removes the prefix
+ // even though the path does not have a prefix.
+ if (fnamencmp(p, dirname, namelen) == 0) {
+ p += namelen;
+ if (vim_ispathsep(*p)) {
+ while (*p && vim_ispathsep(*p)) {
+ p++;
+ }
+ *fnamep = p;
+ if (pbuf != NULL) {
+ // free any allocated file name
+ xfree(*bufp);
+ *bufp = pbuf;
+ pbuf = NULL;
+ }
}
}
} else {
@@ -10730,6 +10746,7 @@ repeat:
*fnamep = s;
xfree(*bufp);
*bufp = s;
+ has_homerelative = true;
}
}
xfree(pbuf);