Skip to content

Commit e5a2dc8

Browse files
committed
patch 8.2.2289: Vim9: 'cpo' can become empty
Problem: Vim9: 'cpo' can become empty. Solution: Use empty_option instead of an empty string. Update quickfix buffer after restoring 'cpo'. (closes #7608)
1 parent 5afd081 commit e5a2dc8

10 files changed

Lines changed: 56 additions & 11 deletions

File tree

src/eval.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,7 @@ pattern_match(char_u *pat, char_u *text, int ic)
19401940

19411941
// avoid 'l' flag in 'cpoptions'
19421942
save_cpo = p_cpo;
1943-
p_cpo = (char_u *)"";
1943+
p_cpo = empty_option;
19441944
regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
19451945
if (regmatch.regprog != NULL)
19461946
{
@@ -6200,8 +6200,14 @@ do_string_sub(
62006200
if (p_cpo == empty_option)
62016201
p_cpo = save_cpo;
62026202
else
6203+
{
62036204
// Darn, evaluating {sub} expression or {expr} changed the value.
6205+
// If it's still empty it was changed and restored, need to restore in
6206+
// the complicated way.
6207+
if (*p_cpo == NUL)
6208+
set_option_value((char_u *)"cpo", 0L, save_cpo, 0);
62046209
free_string_option(save_cpo);
6210+
}
62056211

62066212
return ret;
62076213
}

src/evalbuffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ buflist_find_by_name(char_u *name, int curtab_only)
6868
save_magic = p_magic;
6969
p_magic = TRUE;
7070
save_cpo = p_cpo;
71-
p_cpo = (char_u *)"";
71+
p_cpo = empty_option;
7272

7373
buf = buflist_findnr(buflist_findpat(name, name + STRLEN(name),
7474
TRUE, FALSE, curtab_only));

src/evalfunc.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6316,7 +6316,7 @@ find_some_match(typval_T *argvars, typval_T *rettv, matchtype_T type)
63166316

63176317
// Make 'cpoptions' empty, the 'l' flag should not be used here.
63186318
save_cpo = p_cpo;
6319-
p_cpo = (char_u *)"";
6319+
p_cpo = empty_option;
63206320

63216321
rettv->vval.v_number = -1;
63226322
if (type == MATCH_LIST || type == MATCH_POS)
@@ -8024,8 +8024,14 @@ do_searchpair(
80248024
if (p_cpo == empty_option)
80258025
p_cpo = save_cpo;
80268026
else
8027+
{
80278028
// Darn, evaluating the {skip} expression changed the value.
8029+
// If it's still empty it was changed and restored, need to restore in
8030+
// the complicated way.
8031+
if (*p_cpo == NUL)
8032+
set_option_value((char_u *)"cpo", 0L, save_cpo, 0);
80288033
free_string_option(save_cpo);
8034+
}
80298035

80308036
return retval;
80318037
}
@@ -8723,7 +8729,7 @@ f_split(typval_T *argvars, typval_T *rettv)
87238729

87248730
// Make 'cpoptions' empty, the 'l' flag should not be used here.
87258731
save_cpo = p_cpo;
8726-
p_cpo = (char_u *)"";
8732+
p_cpo = empty_option;
87278733

87288734
str = tv_get_string(&argvars[0]);
87298735
if (argvars[1].v_type != VAR_UNKNOWN)

src/ex_eval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,7 @@ ex_catch(exarg_T *eap)
16951695
*end = NUL;
16961696
}
16971697
save_cpo = p_cpo;
1698-
p_cpo = (char_u *)"";
1698+
p_cpo = empty_option;
16991699
// Disable error messages, it will make current_exception
17001700
// invalid.
17011701
++emsg_off;

src/gui_motif.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3525,7 +3525,7 @@ find_replace_callback(
35253525
char_u *save_cpo = p_cpo;
35263526

35273527
// No need to be Vi compatible here.
3528-
p_cpo = (char_u *)"";
3528+
p_cpo = empty_options;
35293529
u_undo(1);
35303530
p_cpo = save_cpo;
35313531
gui_update_screen();

src/map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2475,7 +2475,7 @@ add_map(char_u *map, int mode)
24752475
char_u *s;
24762476
char_u *cpo_save = p_cpo;
24772477

2478-
p_cpo = (char_u *)""; // Allow <> notation
2478+
p_cpo = empty_option; // Allow <> notation
24792479
s = vim_strsave(map);
24802480
if (s != NULL)
24812481
{

src/quickfix.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8099,6 +8099,7 @@ ex_helpgrep(exarg_T *eap)
80998099
int new_qi = FALSE;
81008100
char_u *au_name = NULL;
81018101
char_u *lang = NULL;
8102+
int updated = FALSE;
81028103

81038104
switch (eap->cmdidx)
81048105
{
@@ -8150,14 +8151,24 @@ ex_helpgrep(exarg_T *eap)
81508151
qfl->qf_ptr = qfl->qf_start;
81518152
qfl->qf_index = 1;
81528153
qf_list_changed(qfl);
8153-
qf_update_buffer(qi, NULL);
8154+
updated = TRUE;
81548155
}
81558156

81568157
if (p_cpo == empty_option)
81578158
p_cpo = save_cpo;
81588159
else
8159-
// Darn, some plugin changed the value.
8160+
{
8161+
// Darn, some plugin changed the value. If it's still empty it was
8162+
// changed and restored, need to restore in the complicated way.
8163+
if (*p_cpo == NUL)
8164+
set_option_value((char_u *)"cpo", 0L, save_cpo, 0);
81608165
free_string_option(save_cpo);
8166+
}
8167+
8168+
if (updated)
8169+
// This may open a window and source scripts, do this after 'cpo' was
8170+
// restored.
8171+
qf_update_buffer(qi, NULL);
81618172

81628173
if (au_name != NULL)
81638174
{

src/syntax.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5670,7 +5670,7 @@ get_syn_pattern(char_u *arg, synpat_T *ci)
56705670

56715671
// Make 'cpoptions' empty, to avoid the 'l' flag
56725672
cpo_save = p_cpo;
5673-
p_cpo = (char_u *)"";
5673+
p_cpo = empty_option;
56745674
ci->sp_prog = vim_regcomp(ci->sp_pattern, RE_MAGIC);
56755675
p_cpo = cpo_save;
56765676

@@ -5858,7 +5858,7 @@ syn_cmd_sync(exarg_T *eap, int syncing UNUSED)
58585858

58595859
// Make 'cpoptions' empty, to avoid the 'l' flag
58605860
cpo_save = p_cpo;
5861-
p_cpo = (char_u *)"";
5861+
p_cpo = empty_option;
58625862
curwin->w_s->b_syn_linecont_prog =
58635863
vim_regcomp(curwin->w_s->b_syn_linecont_pat, RE_MAGIC);
58645864
p_cpo = cpo_save;

src/testdir/test_quickfix.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,26 @@ func Test_helpgrep()
702702
call s:test_xhelpgrep('l')
703703
endfunc
704704

705+
def Test_helpgrep_vim9_restore_cpo()
706+
assert_equal('aABceFs', &cpo)
707+
708+
var rtp_save = &rtp
709+
var dir = 'Xruntime/after'
710+
&rtp ..= ',' .. dir
711+
mkdir(dir .. '/ftplugin', 'p')
712+
writefile(['vim9'], dir .. '/ftplugin/qf.vim')
713+
filetype plugin on
714+
silent helpgrep grail
715+
cwindow
716+
silent helpgrep grail
717+
718+
assert_equal('aABceFs', &cpo)
719+
delete(dir, 'rf')
720+
&rtp = rtp_save
721+
cclose
722+
helpclose
723+
enddef
724+
705725
func Test_errortitle()
706726
augroup QfBufWinEnter
707727
au!

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2289,
753755
/**/
754756
2288,
755757
/**/

0 commit comments

Comments
 (0)