mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.3901: Vim9: Cannot set 'cpo' in main .vimrc if using Vim9 script
Problem: Vim9: Cannot set 'cpo' in main .vimrc if using Vim9 script. Solution: Do not restore 'cpo' at the end of the main .vimrc.
This commit is contained in:
@@ -2133,8 +2133,18 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
Commas can be added for readability.
|
Commas can be added for readability.
|
||||||
To avoid problems with flags that are added in the future, use the
|
To avoid problems with flags that are added in the future, use the
|
||||||
"+=" and "-=" feature of ":set" |add-option-flags|.
|
"+=" and "-=" feature of ":set" |add-option-flags|.
|
||||||
|
|
||||||
NOTE: This option is set to the Vi default value when 'compatible' is
|
NOTE: This option is set to the Vi default value when 'compatible' is
|
||||||
set and to the Vim default value when 'compatible' is reset.
|
set and to the Vim default value when 'compatible' is reset.
|
||||||
|
|
||||||
|
NOTE: In a |Vim9| script, when `vim9script` is encountered, the value
|
||||||
|
is saved, 'cpoptions' is set to the Vim default, and the saved value
|
||||||
|
is restored at the end of the script. Changes to the value of
|
||||||
|
'cpoptions' will be applied to the saved value, but keep in mind that
|
||||||
|
removing a flag that is not present when 'cpoptions' is changed has no
|
||||||
|
effect. In the |.vimrc| file the value is not restored, thus using
|
||||||
|
`vim9script` in the |.vimrc| file results in using the Vim default.
|
||||||
|
|
||||||
NOTE: This option is set to the POSIX default value at startup when
|
NOTE: This option is set to the POSIX default value at startup when
|
||||||
the Vi default value would be used and the $VIM_POSIX environment
|
the Vi default value would be used and the $VIM_POSIX environment
|
||||||
variable exists |posix|. This means Vim tries to behave like the
|
variable exists |posix|. This means Vim tries to behave like the
|
||||||
|
@@ -1402,6 +1402,7 @@ 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
|
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
|
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.
|
original value to get the same effect. The order of flags may change.
|
||||||
|
In the |vimrc| file sourced on startup this does not happen.
|
||||||
|
|
||||||
*vim9-mix*
|
*vim9-mix*
|
||||||
There is one way to use both legacy and Vim9 syntax in one script file: >
|
There is one way to use both legacy and Vim9 syntax in one script file: >
|
||||||
|
@@ -1372,6 +1372,9 @@ do_source(
|
|||||||
if (ret_sid != NULL)
|
if (ret_sid != NULL)
|
||||||
*ret_sid = current_sctx.sc_sid;
|
*ret_sid = current_sctx.sc_sid;
|
||||||
|
|
||||||
|
// Remember the "is_vimrc" flag for when the file is sourced again.
|
||||||
|
si->sn_is_vimrc = is_vimrc;
|
||||||
|
|
||||||
// Used to check script variable index is still valid.
|
// Used to check script variable index is still valid.
|
||||||
si->sn_script_seq = current_sctx.sc_seq;
|
si->sn_script_seq = current_sctx.sc_seq;
|
||||||
}
|
}
|
||||||
@@ -1471,9 +1474,11 @@ do_source(
|
|||||||
|
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
almosttheend:
|
almosttheend:
|
||||||
|
// If "sn_save_cpo" is set that means we encountered "vim9script": restore
|
||||||
|
// 'cpoptions', unless in the main .vimrc file.
|
||||||
// Get "si" again, "script_items" may have been reallocated.
|
// Get "si" again, "script_items" may have been reallocated.
|
||||||
si = SCRIPT_ITEM(current_sctx.sc_sid);
|
si = SCRIPT_ITEM(current_sctx.sc_sid);
|
||||||
if (si->sn_save_cpo != NULL)
|
if (si->sn_save_cpo != NULL && si->sn_is_vimrc == DOSO_NONE)
|
||||||
{
|
{
|
||||||
if (STRCMP(p_cpo, CPO_VIM) != 0)
|
if (STRCMP(p_cpo, CPO_VIM) != 0)
|
||||||
{
|
{
|
||||||
@@ -1503,8 +1508,8 @@ almosttheend:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
set_option_value((char_u *)"cpo", 0L, si->sn_save_cpo, OPT_NO_REDRAW);
|
set_option_value((char_u *)"cpo", 0L, si->sn_save_cpo, OPT_NO_REDRAW);
|
||||||
VIM_CLEAR(si->sn_save_cpo);
|
|
||||||
}
|
}
|
||||||
|
VIM_CLEAR(si->sn_save_cpo);
|
||||||
|
|
||||||
restore_funccal();
|
restore_funccal();
|
||||||
# ifdef FEAT_PROFILE
|
# ifdef FEAT_PROFILE
|
||||||
|
@@ -1866,6 +1866,7 @@ typedef struct
|
|||||||
int sn_version; // :scriptversion
|
int sn_version; // :scriptversion
|
||||||
int sn_state; // SN_STATE_ values
|
int sn_state; // SN_STATE_ values
|
||||||
char_u *sn_save_cpo; // 'cpo' value when :vim9script found
|
char_u *sn_save_cpo; // 'cpo' value when :vim9script found
|
||||||
|
char sn_is_vimrc; // .vimrc file, do not restore 'cpo'
|
||||||
|
|
||||||
# ifdef FEAT_PROFILE
|
# ifdef FEAT_PROFILE
|
||||||
int sn_prof_on; // TRUE when script is/was profiled
|
int sn_prof_on; // TRUE when script is/was profiled
|
||||||
|
@@ -4270,18 +4270,64 @@ def Test_restoring_cpo()
|
|||||||
delete('Xclose')
|
delete('Xclose')
|
||||||
delete('Xdone')
|
delete('Xdone')
|
||||||
|
|
||||||
writefile(['vim9script'], 'XanotherScript')
|
writefile(['vim9script', 'g:cpoval = &cpo'], 'XanotherScript')
|
||||||
set cpo=aABceFsMny>
|
set cpo=aABceFsMny>
|
||||||
edit XanotherScript
|
edit XanotherScript
|
||||||
so %
|
so %
|
||||||
assert_equal('aABceFsMny>', &cpo)
|
assert_equal('aABceFsMny>', &cpo)
|
||||||
|
assert_equal('aABceFs', g:cpoval)
|
||||||
:1del
|
:1del
|
||||||
|
setline(1, 'let g:cpoval = &cpo')
|
||||||
w
|
w
|
||||||
so %
|
so %
|
||||||
assert_equal('aABceFsMny>', &cpo)
|
assert_equal('aABceFsMny>', &cpo)
|
||||||
|
assert_equal('aABceFsMny>', g:cpoval)
|
||||||
|
|
||||||
delete('XanotherScript')
|
delete('XanotherScript')
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
|
unlet g:cpoval
|
||||||
|
|
||||||
|
if has('unix')
|
||||||
|
# 'cpo' is not restored in main vimrc
|
||||||
|
var save_HOME = $HOME
|
||||||
|
$HOME = getcwd() .. '/Xhome'
|
||||||
|
mkdir('Xhome')
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
writefile(['before: ' .. &cpo], 'Xresult')
|
||||||
|
set cpo+=M
|
||||||
|
writefile(['after: ' .. &cpo], 'Xresult', 'a')
|
||||||
|
END
|
||||||
|
writefile(lines, 'Xhome/.vimrc')
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
call writefile(['later: ' .. &cpo], 'Xresult', 'a')
|
||||||
|
END
|
||||||
|
writefile(lines, 'Xlegacy')
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
call writefile(['vim9: ' .. &cpo], 'Xresult', 'a')
|
||||||
|
qa
|
||||||
|
END
|
||||||
|
writefile(lines, 'Xvim9')
|
||||||
|
|
||||||
|
var cmd = GetVimCommand() .. " -S Xlegacy -S Xvim9"
|
||||||
|
cmd = substitute(cmd, '-u NONE', '', '')
|
||||||
|
exe "silent !" .. cmd
|
||||||
|
|
||||||
|
assert_equal([
|
||||||
|
'before: aABceFs',
|
||||||
|
'after: aABceFsM',
|
||||||
|
'later: aABceFsM',
|
||||||
|
'vim9: aABceFs'], readfile('Xresult'))
|
||||||
|
|
||||||
|
$HOME = save_HOME
|
||||||
|
delete('Xhome', 'rf')
|
||||||
|
delete('Xlegacy')
|
||||||
|
delete('Xvim9')
|
||||||
|
delete('Xresult')
|
||||||
|
endif
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
" Use :function so we can use Check commands
|
" Use :function so we can use Check commands
|
||||||
|
@@ -749,6 +749,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
3901,
|
||||||
/**/
|
/**/
|
||||||
3900,
|
3900,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user