diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-03-24 13:56:55 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-03-24 14:17:40 +0100 |
commit | 7ae41442088a4b1b1cd324b683defd87998ba75c (patch) | |
tree | f6074ac4c2c317fb6546f97da2b894d411b98fc8 | |
parent | 998a16c926623a667ecb0228f4a6cd8ba1e90201 (diff) | |
download | rneovim-7ae41442088a4b1b1cd324b683defd87998ba75c.tar.gz rneovim-7ae41442088a4b1b1cd324b683defd87998ba75c.tar.bz2 rneovim-7ae41442088a4b1b1cd324b683defd87998ba75c.zip |
refactor/rename: path_try_shorten_fname()
-rw-r--r-- | src/nvim/ex_docmd.c | 2 | ||||
-rw-r--r-- | src/nvim/path.c | 2 | ||||
-rw-r--r-- | src/nvim/quickfix.c | 4 | ||||
-rw-r--r-- | src/nvim/shada.c | 6 | ||||
-rw-r--r-- | test/unit/path_spec.lua | 10 |
5 files changed, 12 insertions, 12 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index d5276ffd4b..eb6d7ad815 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -8561,7 +8561,7 @@ eval_vars ( "E495: no autocommand file name to substitute for \"<afile>\""); return NULL; } - result = path_shorten_fname_if_possible(result); + result = path_try_shorten_fname(result); break; case SPEC_ABUF: /* buffer number for autocommand */ diff --git a/src/nvim/path.c b/src/nvim/path.c index 63aeaf5f92..a1f9b2a0cc 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1908,7 +1908,7 @@ int pathcmp(const char *p, const char *q, int maxlen) /// - Pointer into `full_path` if shortened. /// - `full_path` unchanged if no shorter name is possible. /// - NULL if `full_path` is NULL. -char_u *path_shorten_fname_if_possible(char_u *full_path) +char_u *path_try_shorten_fname(char_u *full_path) { char_u *dirname = xmalloc(MAXPATHL); char_u *p = full_path; diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 1aeadcec4a..2d8c353f92 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3649,8 +3649,8 @@ void ex_vimgrep(exarg_T *eap) cur_qf_start = qi->qf_lists[qi->qf_curlist].qf_start; seconds = (time_t)0; - for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi) { - fname = path_shorten_fname_if_possible(fnames[fi]); + for (fi = 0; fi < fcount && !got_int && tomatch > 0; fi++) { + fname = path_try_shorten_fname(fnames[fi]); if (time(NULL) > seconds) { /* Display the file name every second or so, show the user we are * working on it. */ diff --git a/src/nvim/shada.c b/src/nvim/shada.c index a1ce00f665..605d9c30a6 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -76,8 +76,8 @@ KHASH_SET_INIT_STR(strset) (vim_rename((char_u *)a, (char_u *)b)) #define mb_strnicmp(a, b, c) \ (mb_strnicmp((char_u *)a, (char_u *)b, c)) -#define path_shorten_fname_if_possible(b) \ - ((char *)path_shorten_fname_if_possible((char_u *)b)) +#define path_try_shorten_fname(b) \ + ((char *)path_try_shorten_fname((char_u *)b)) #define buflist_new(ffname, sfname, ...) \ (buflist_new((char_u *)ffname, (char_u *)sfname, __VA_ARGS__)) #define os_isdir(f) (os_isdir((char_u *) f)) @@ -1397,7 +1397,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) } case kSDItemBufferList: { for (size_t i = 0; i < cur_entry.data.buffer_list.size; i++) { - char *const sfname = path_shorten_fname_if_possible( + char *const sfname = path_try_shorten_fname( cur_entry.data.buffer_list.buffers[i].fname); buf_T *const buf = buflist_new( cur_entry.data.buffer_list.buffers[i].fname, sfname, 0, diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua index 1bd20b1da9..e8ce660ce1 100644 --- a/test/unit/path_spec.lua +++ b/test/unit/path_spec.lua @@ -261,7 +261,7 @@ describe('path.c', function() end) end) -describe('path_shorten_fname_if_possible', function() +describe('path_try_shorten_fname', function() local cwd = lfs.currentdir() before_each(function() @@ -273,22 +273,22 @@ describe('path_shorten_fname_if_possible', function() lfs.rmdir('ut_directory') end) - describe('path_shorten_fname_if_possible', function() + describe('path_try_shorten_fname', function() itp('returns shortened path if possible', function() lfs.chdir('ut_directory') local full = to_cstr(lfs.currentdir() .. '/subdir/file.txt') - eq('subdir/file.txt', (ffi.string(cimp.path_shorten_fname_if_possible(full)))) + eq('subdir/file.txt', (ffi.string(cimp.path_try_shorten_fname(full)))) end) itp('returns `full_path` if a shorter version is not possible', function() local old = lfs.currentdir() lfs.chdir('ut_directory') local full = old .. '/subdir/file.txt' - eq(full, (ffi.string(cimp.path_shorten_fname_if_possible(to_cstr(full))))) + eq(full, (ffi.string(cimp.path_try_shorten_fname(to_cstr(full))))) end) itp('returns NULL if `full_path` is NULL', function() - eq(NULL, (cimp.path_shorten_fname_if_possible(NULL))) + eq(NULL, (cimp.path_try_shorten_fname(NULL))) end) end) end) |