patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Problem: Vim9: if 'cpo' is change in Vim9 script it may be restored.
Solution: Apply the changes to 'cpo' to the restored value.
diff --git a/src/scriptfile.c b/src/scriptfile.c
index 1e4b5cc..203cad0 100644
--- a/src/scriptfile.c
+++ b/src/scriptfile.c
@@ -1459,6 +1459,33 @@
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);
}