diff options
-rw-r--r-- | src/nvim/option.c | 29 | ||||
-rw-r--r-- | test/old/testdir/test_options.vim | 81 |
2 files changed, 110 insertions, 0 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index 56881cbe58..3648601ab8 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -160,6 +160,14 @@ typedef enum { # include "options.generated.h" #endif +static char *(p_bin_dep_opts[]) = { + "textwidth", "wrapmargin", "modeline", "expandtab", NULL +}; +static char *(p_paste_dep_opts[]) = { + "autoindent", "expandtab", "ruler", "showmatch", "smarttab", + "softtabstop", "textwidth", "wrapmargin", "revins", "varsofttabstop", NULL +}; + void set_init_tablocal(void) { // susy baka: cmdheight calls itself OPT_GLOBAL but is really tablocal! @@ -1681,6 +1689,9 @@ void set_options_bin(int oldval, int newval, int opt_flags) p_et = p_et_nobin; } } + + // Remember where the dependent option were reset + didset_options_sctx(opt_flags, p_bin_dep_opts); } /// Find the parameter represented by the given character (eg ', :, ", or /), @@ -5608,6 +5619,7 @@ static void paste_option_changed(void) p_wm = 0; p_sts = 0; p_ai = 0; + p_et = 0; if (p_vsts) { free_string_option(p_vsts); } @@ -5655,6 +5667,9 @@ static void paste_option_changed(void) } old_p_paste = p_paste; + + // Remember where the dependent options were reset + didset_options_sctx((OPT_LOCAL | OPT_GLOBAL), p_paste_dep_opts); } /// vimrc_found() - Called when a vimrc or "VIMINIT" has been found. @@ -5820,6 +5835,20 @@ int option_set_callback_func(char *optval, Callback *optcb) return OK; } +static void didset_options_sctx(int opt_flags, char **buf) +{ + for (int i = 0;; i++) { + if (buf[i] == NULL) { + break; + } + + int idx = findoption(buf[i]); + if (idx >= 0) { + set_option_sctx_idx(idx, opt_flags, current_sctx); + } + } +} + /// Check if backspacing over something is allowed. /// @param what BS_INDENT, BS_EOL, BS_START, or BS_NOSTOP bool can_bs(int what) diff --git a/test/old/testdir/test_options.vim b/test/old/testdir/test_options.vim index 12a262f2ad..563709b9a3 100644 --- a/test/old/testdir/test_options.vim +++ b/test/old/testdir/test_options.vim @@ -1768,4 +1768,85 @@ func Test_set_option_window_global_local_all() bw! endfunc +func Test_paste_depending_options() + " setting the paste option, resets all dependent options + " and will be reported correctly using :verbose set <option>? + let lines =<< trim [CODE] + " set paste test + set autoindent + set expandtab + " disabled, because depends on compiled feature set + " set hkmap + " set revins + " set varsofttabstop=8,32,8 + set ruler + set showmatch + set smarttab + set softtabstop=4 + set textwidth=80 + set wrapmargin=10 + + source Xvimrc_paste2 + + redir > Xoutput_paste + verbose set expandtab? + verbose setg expandtab? + verbose setl expandtab? + redir END + + qall! + [CODE] + + call writefile(lines, 'Xvimrc_paste', 'D') + call writefile(['set paste'], 'Xvimrc_paste2', 'D') + if !RunVim([], lines, '--clean') + return + endif + + let result = readfile('Xoutput_paste')->filter('!empty(v:val)') + call assert_equal('noexpandtab', result[0]) + call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[1]) + call assert_equal('noexpandtab', result[2]) + call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[3]) + call assert_equal('noexpandtab', result[4]) + call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[5]) + + call delete('Xoutput_paste') +endfunc + +func Test_binary_depending_options() + " setting the paste option, resets all dependent options + " and will be reported correctly using :verbose set <option>? + let lines =<< trim [CODE] + " set binary test + set expandtab + + source Xvimrc_bin2 + + redir > Xoutput_bin + verbose set expandtab? + verbose setg expandtab? + verbose setl expandtab? + redir END + + qall! + [CODE] + + call writefile(lines, 'Xvimrc_bin', 'D') + call writefile(['set binary'], 'Xvimrc_bin2', 'D') + if !RunVim([], lines, '--clean') + return + endif + + let result = readfile('Xoutput_bin')->filter('!empty(v:val)') + call assert_equal('noexpandtab', result[0]) + call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[1]) + call assert_equal('noexpandtab', result[2]) + call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[3]) + call assert_equal('noexpandtab', result[4]) + call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[5]) + + call delete('Xoutput_bin') +endfunc + " vim: shiftwidth=2 sts=2 expandtab |