To: vim_dev@googlegroups.com Subject: Patch 8.2.2616 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2616 Problem: Vim9: if 'cpo' is changed in Vim9 script it may be restored. Solution: Apply the changes to 'cpo' to the restored value. Files: runtime/doc/vim9.txt, src/scriptfile.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.2615/runtime/doc/vim9.txt 2021-03-14 18:38:50.016676652 +0100 --- runtime/doc/vim9.txt 2021-03-17 17:37:32.590884860 +0100 *************** *** 1080,1086 **** Vim default value, like with: > :set cpo&vim One of the effects is that |line-continuation| is always enabled. ! The original value of 'cpoptions' is restored at the end of the script. *vim9-mix* There is one way to use both legacy and Vim9 syntax in one script file: > --- 1083,1091 ---- Vim default value, like with: > :set cpo&vim One of the effects is that |line-continuation| is always enabled. ! The original value of 'cpoptions' is restored at the end of the script, while ! flags added or removed in the script are also added to or removed from the ! original value to get the same effect. The order of flags may change. *vim9-mix* There is one way to use both legacy and Vim9 syntax in one script file: > *** ../vim-8.2.2615/src/scriptfile.c 2021-03-10 13:39:46.322350547 +0100 --- src/scriptfile.c 2021-03-17 17:35:31.831212969 +0100 *************** *** 1459,1464 **** --- 1459,1491 ---- 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); } *** ../vim-8.2.2615/src/testdir/test_vim9_script.vim 2021-03-17 15:23:11.967685790 +0100 --- src/testdir/test_vim9_script.vim 2021-03-17 17:42:48.086027910 +0100 *************** *** 1250,1266 **** delete('Xexport.vim') # Check that in a Vim9 script 'cpo' is set to the Vim default. ! set cpo&vi ! var cpo_before = &cpo var lines =<< trim END vim9script g:cpo_in_vim9script = &cpo END writefile(lines, 'Xvim9_script') source Xvim9_script ! assert_equal(cpo_before, &cpo) set cpo&vim assert_equal(&cpo, g:cpo_in_vim9script) delete('Xvim9_script') enddef --- 1250,1272 ---- delete('Xexport.vim') # Check that in a Vim9 script 'cpo' is set to the Vim default. ! # 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('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 *** ../vim-8.2.2615/src/version.c 2021-03-17 15:23:11.967685790 +0100 --- src/version.c 2021-03-17 16:53:30.022239727 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2616, /**/ -- An alien life briefly visits earth. Just before departing it leaves a message in the dust on the back of a white van. The world is shocked and wants to know what it means. After months of studies the worlds best linguistic scientists are able to decipher the message: "Wash me!". /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///