diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-03-17 17:46:00 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-03-17 17:46:00 +0100 |
commit | 3e1916947d5b29f67af554ce3b874b03a84c9093 (patch) | |
tree | f50f78498892b8d04b3d37334c26ad070c5a03ef /src | |
parent | a4c81bea38d1f3e372a4191ab0bd7d664cba1428 (diff) | |
download | vim-git-3e1916947d5b29f67af554ce3b874b03a84c9093.tar.gz |
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restoredv8.2.2616
Problem: Vim9: if 'cpo' is change in Vim9 script it may be restored.
Solution: Apply the changes to 'cpo' to the restored value.
Diffstat (limited to 'src')
-rw-r--r-- | src/scriptfile.c | 27 | ||||
-rw-r--r-- | src/testdir/test_vim9_script.vim | 12 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 38 insertions, 3 deletions
diff --git a/src/scriptfile.c b/src/scriptfile.c index 1e4b5ccf7..203cad09f 100644 --- a/src/scriptfile.c +++ b/src/scriptfile.c @@ -1459,6 +1459,33 @@ almosttheend: si = SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_save_cpo != NULL) { + if (STRCMP(p_cpo, CPO_VIM) != 0) + { + char_u *f; + char_u *t; + + // 'cpo' was changed in the script. Apply the same change to the + // saved value, if possible. + for (f = (char_u *)CPO_VIM; *f != NUL; ++f) + if (vim_strchr(p_cpo, *f) == NULL + && (t = vim_strchr(si->sn_save_cpo, *f)) != NULL) + // flag was removed, also remove it from the saved 'cpo' + mch_memmove(t, t + 1, STRLEN(t)); + for (f = p_cpo; *f != NUL; ++f) + if (vim_strchr((char_u *)CPO_VIM, *f) == NULL + && vim_strchr(si->sn_save_cpo, *f) == NULL) + { + // flag was added, also add it to the saved 'cpo' + t = alloc(STRLEN(si->sn_save_cpo) + 2); + if (t != NULL) + { + *t = *f; + STRCPY(t + 1, si->sn_save_cpo); + vim_free(si->sn_save_cpo); + si->sn_save_cpo = t; + } + } + } set_option_value((char_u *)"cpo", 0L, si->sn_save_cpo, OPT_NO_REDRAW); VIM_CLEAR(si->sn_save_cpo); } diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim index 956de369e..38d0b0abc 100644 --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -1250,17 +1250,23 @@ def Test_vim9_import_export() delete('Xexport.vim') # Check that in a Vim9 script 'cpo' is set to the Vim default. - set cpo&vi - var cpo_before = &cpo + # Flags added or removed are also applied to the restored value. + set cpo=abcd var lines =<< trim END vim9script g:cpo_in_vim9script = &cpo + set cpo+=f + set cpo-=c + g:cpo_after_vim9script = &cpo END writefile(lines, 'Xvim9_script') source Xvim9_script - assert_equal(cpo_before, &cpo) + assert_equal('fabd', &cpo) set cpo&vim assert_equal(&cpo, g:cpo_in_vim9script) + var newcpo = substitute(&cpo, 'c', '', '') .. 'f' + assert_equal(newcpo, g:cpo_after_vim9script) + delete('Xvim9_script') enddef diff --git a/src/version.c b/src/version.c index 425dfaacf..a92db82f3 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2616, +/**/ 2615, /**/ 2614, |