*/
int
modify_fname(
- char_u *src, /* string with modifiers */
- int *usedlen, /* characters after src that are used */
- char_u **fnamep, /* file name so far */
- char_u **bufp, /* buffer for allocated file name or NULL */
- int *fnamelen) /* length of fnamep */
+ char_u *src, // string with modifiers
+ int tilde_file, // "~" is a file name, not $HOME
+ int *usedlen, // characters after src that are used
+ char_u **fnamep, // file name so far
+ char_u **bufp, // buffer for allocated file name or NULL
+ int *fnamelen) // length of fnamep
{
int valid = 0;
char_u *tail;
|| (*fnamep)[1] == '\\'
# endif
|| (*fnamep)[1] == NUL)
-
#endif
+ && !(tilde_file && (*fnamep)[1] == NUL)
)
{
*fnamep = expand_env_save(*fnamep);
else
{
len = (int)STRLEN(fname);
- (void)modify_fname(mods, &usedlen, &fname, &fbuf, &len);
+ (void)modify_fname(mods, FALSE, &usedlen, &fname, &fbuf, &len);
}
rettv->v_type = VAR_STRING;
int resultlen;
buf_T *buf;
int valid = VALID_HEAD + VALID_PATH; /* assume valid result */
+ int tilde_file = FALSE;
int spec_idx;
#ifdef FEAT_MODIFY_FNAME
int skip_mod = FALSE;
valid = 0; /* Must have ":p:h" to be valid */
}
else
+ {
result = curbuf->b_fname;
+ tilde_file = STRCMP(result, "~") == 0;
+ }
break;
case SPEC_HASH: /* '#' or "#99": alternate file */
valid = 0; /* Must have ":p:h" to be valid */
}
else
+ {
result = buf->b_fname;
+ tilde_file = STRCMP(result, "~") == 0;
+ }
}
break;
#ifdef FEAT_MODIFY_FNAME
else if (!skip_mod)
{
- valid |= modify_fname(src, usedlen, &result, &resultbuf,
+ valid |= modify_fname(src, tilde_file, usedlen, &result, &resultbuf,
&resultlen);
if (result == NULL)
{
#ifdef FEAT_MODIFY_FNAME
len = (int)STRLEN(fname);
fbuf = (char_u *)fname;
- (void)modify_fname((char_u *)":p", &usedlen,
+ (void)modify_fname((char_u *)":p", FALSE, &usedlen,
(char_u **)&fname, &fbuf, &len);
if (fname == NULL)
goto add_err;
char_u *fbuf = NULL;
flen = (int)STRLEN(homedir_env);
- (void)modify_fname((char_u *)":p", &usedlen,
+ (void)modify_fname((char_u *)":p", FALSE, &usedlen,
&homedir_env, &fbuf, &flen);
flen = (int)STRLEN(homedir_env);
if (flen > 0 && vim_ispathsep(homedir_env[flen - 1]))
int typval_compare(typval_T *typ1, typval_T *typ2, exptype_T type, int type_is, int ic);
char_u *typval_tostring(typval_T *arg);
int var_exists(char_u *var);
-int modify_fname(char_u *src, int *usedlen, char_u **fnamep, char_u **bufp, int *fnamelen);
+int modify_fname(char_u *src, int tilde_file, int *usedlen, char_u **fnamep, char_u **bufp, int *fnamelen);
char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, typval_T *expr, char_u *flags);
void filter_map(typval_T *argvars, typval_T *rettv, int map);
/* vim: set ft=c : */
call delete('Xdir ~ dir', 'd')
call assert_false(isdirectory('Xdir ~ dir'))
endfunc
+
+func Test_expand_tilde_filename()
+ split ~
+ call assert_equal('~', expand('%'))
+ call assert_notequal(expand('%:p'), expand('~/'))
+ call assert_match('\~', expand('%:p'))
+ bwipe!
+endfunc
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 211,
/**/
210,
/**/