diff options
-rw-r--r-- | runtime/doc/options.txt | 3 | ||||
-rw-r--r-- | src/nvim/shada.c | 12 | ||||
-rw-r--r-- | test/config/paths.lua.in | 1 | ||||
-rw-r--r-- | test/functional/shada/shada_spec.lua | 39 |
4 files changed, 48 insertions, 7 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index d65a8b9454..579fced314 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -5374,8 +5374,7 @@ A jump table for the options with a short description can be found at |Q_op|. specifies the start of a path for which no marks will be stored. This is to avoid removable media. For MS-DOS you could use "ra:,rb:". You can also use it for temp files, - e.g., for Unix: "r/tmp". Case is ignored. Maximum length of - each 'r' argument is 50 characters. + e.g., for Unix: "r/tmp". Case is ignored. *shada-s* s Maximum size of an item contents in KiB. If zero then nothing is saved. Unlike Vim this applies to all items, except for diff --git a/src/nvim/shada.c b/src/nvim/shada.c index d6a507eb50..a66b3c598e 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -68,6 +68,8 @@ KHASH_SET_INIT_STR(strset) #define emsgu(a, ...) emsgu((char_u *) a, __VA_ARGS__) #define home_replace_save(a, b) \ ((char *)home_replace_save(a, (char_u *)b)) +#define home_replace(a, b, c, d, e) \ + home_replace(a, (char_u *)b, (char_u *)c, d, e) #define vim_rename(a, b) \ (vim_rename((char_u *)a, (char_u *)b)) #define has_non_ascii(a) (has_non_ascii((char_u *)a)) @@ -4003,16 +4005,16 @@ bool shada_removable(const char *name) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE { char *p; - char part[51]; + char part[MAXPATHL + 1]; bool retval = false; - size_t n; char *new_name = home_replace_save(NULL, name); for (p = (char *) p_shada; *p; ) { - (void) copy_option_part(&p, part, 51, ", "); + (void) copy_option_part(&p, part, ARRAY_SIZE(part), ", "); if (part[0] == 'r') { - n = STRLEN(part + 1); - if (STRNICMP(part + 1, new_name, n) == 0) { + home_replace(NULL, part + 1, NameBuff, MAXPATHL, true); + size_t n = STRLEN(NameBuff); + if (STRNICMP(NameBuff, new_name, n) == 0) { retval = true; break; } diff --git a/test/config/paths.lua.in b/test/config/paths.lua.in index a13230ed28..80cc5629d1 100644 --- a/test/config/paths.lua.in +++ b/test/config/paths.lua.in @@ -7,6 +7,7 @@ end module.test_include_path = "${CMAKE_BINARY_DIR}/test/includes/post" module.test_libnvim_path = "${TEST_LIBNVIM_PATH}" +module.test_source_path = "${CMAKE_SOURCE_DIR}" table.insert(module.include_paths, "${CMAKE_BINARY_DIR}/include") return module diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua index ed022ea65c..dfd5c436e4 100644 --- a/test/functional/shada/shada_spec.lua +++ b/test/functional/shada/shada_spec.lua @@ -7,6 +7,7 @@ local write_file, spawn, set_session, nvim_prog, exc_exec = helpers.write_file, helpers.spawn, helpers.set_session, helpers.nvim_prog, helpers.exc_exec local lfs = require('lfs') +local paths = require('test.config.paths') local msgpack = require('MessagePack') @@ -146,4 +147,42 @@ describe('ShaDa support code', function() session:exit(0) os.remove('NONE') end) + + it('correctly uses shada-r option', function() + nvim('set_var', '__home', paths.test_source_path) + nvim_command('let $HOME = __home') + nvim_command('unlet __home') + nvim_command('edit ~/README.md') + nvim_command('normal! GmAggmaAabc') + nvim_command('undo') + nvim_command('set shada+=%') + nvim_command('wshada! ' .. shada_fname) + local marklike = {[7]=true, [8]=true, [10]=true, [11]=true} + local readme_fname = paths.test_source_path .. '/README.md' + local find_readme = function() + local found = {} + for _, v in ipairs(read_shada_file(shada_fname)) do + if marklike[v.type] and v.value.f == readme_fname then + found[v.type] = (found[v.type] or 0) + 1 + elseif v.type == 9 then + for _, b in ipairs(v.value) do + if b.f == readme_fname then + found[v.type] = (found[v.type] or 0) + 1 + end + end + end + end + return found + end + eq({[7]=1, [8]=2, [9]=1, [10]=4, [11]=1}, find_readme()) + nvim_command('set shada+=r~') + nvim_command('wshada! ' .. shada_fname) + eq({}, find_readme()) + nvim_command('set shada-=r~') + nvim_command('wshada! ' .. shada_fname) + eq({[7]=1, [8]=2, [9]=1, [10]=4, [11]=1}, find_readme()) + nvim_command('set shada+=r' .. paths.test_source_path) + nvim_command('wshada! ' .. shada_fname) + eq({}, find_readme()) + end) end) |