diff options
Diffstat (limited to 'src/nvim/fileio.c')
-rw-r--r-- | src/nvim/fileio.c | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 8b650d0d5b..290de034d7 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -4311,38 +4311,46 @@ static int make_bom(char_u *buf, char_u *name) return (int)(p - buf); } +/// 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. +/// When "force" is FALSE: Only try to shorten absolute file names. +/// 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. - * 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. - * When "force" is FALSE: Only try to shorten absolute file names. - * For buffers that have buftype "nofile" or "scratch": never change the file - * name. */ 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. */ |