diff options
Diffstat (limited to 'src/nvim/fileio.c')
-rw-r--r-- | src/nvim/fileio.c | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 8b650d0d5b..494b557379 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -4312,7 +4312,7 @@ static int make_bom(char_u *buf, char_u *name) } /* - * Shorten filenames for all buffers. + * Shorten filename of a buffer. * When "force" is TRUE: Use full path from now on for files currently being * edited, both for file name and swap file name. Try to shorten the file * names a bit, if safe to do so. @@ -4320,29 +4320,38 @@ static int make_bom(char_u *buf, char_u *name) * For buffers that have buftype "nofile" or "scratch": never change the file * name. */ +void shorten_buf_fname(buf_T *buf, char_u *dirname, int force) +{ + char_u *p; + + if (buf->b_fname != NULL + && !bt_nofile(buf) + && !path_with_url((char *)buf->b_fname) + && (force + || buf->b_sfname == NULL + || path_is_absolute(buf->b_sfname))) { + xfree(buf->b_sfname); + buf->b_sfname = NULL; + p = path_shorten_fname(buf->b_ffname, dirname); + if (p != NULL) { + buf->b_sfname = vim_strsave(p); + buf->b_fname = buf->b_sfname; + } + if (p == NULL || buf->b_fname == NULL) + buf->b_fname = buf->b_ffname; + } +} + +/* + * Shorten filenames for all buffers. + */ void shorten_fnames(int force) { char_u dirname[MAXPATHL]; - char_u *p; os_dirname(dirname, MAXPATHL); FOR_ALL_BUFFERS(buf) { - if (buf->b_fname != NULL - && !bt_nofile(buf) - && !path_with_url((char *)buf->b_fname) - && (force - || buf->b_sfname == NULL - || path_is_absolute(buf->b_sfname))) { - xfree(buf->b_sfname); - buf->b_sfname = NULL; - p = path_shorten_fname(buf->b_ffname, dirname); - if (p != NULL) { - buf->b_sfname = vim_strsave(p); - buf->b_fname = buf->b_sfname; - } - if (p == NULL || buf->b_fname == NULL) - buf->b_fname = buf->b_ffname; - } + shorten_buf_fname(buf, dirname, force); /* Always make the swap file name a full path, a "nofile" buffer may * also have a swap file. */ |