Skip to content

Commit 25190db

Browse files
committed
patch 8.1.1261: no error for quickfix commands with negative range
Problem: No error for quickfix commands with negative range. Solution: Add ADDR_UNSIGNED and use it for quickfix commands. Make assert_fails() show the command if the error doesn't match.
1 parent e4f5f3a commit 25190db

9 files changed

Lines changed: 177 additions & 67 deletions

File tree

runtime/doc/quickfix.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ processing a quickfix or location list command, it will be aborted.
8787

8888
*:cc*
8989
:cc[!] [nr] Display error [nr]. If [nr] is omitted, the same
90-
error is displayed again. Without [!] this doesn't
90+
:[nr]cc[!] error is displayed again. Without [!] this doesn't
9191
work when jumping to another buffer, the current buffer
9292
has been changed, there is the only window for the
9393
buffer and both 'hidden' and 'autowrite' are off.
@@ -96,10 +96,13 @@ processing a quickfix or location list command, it will be aborted.
9696
there is another window for this buffer.
9797
The 'switchbuf' settings are respected when jumping
9898
to a buffer.
99+
When used in the quickfix window the line number can
100+
be used, including "." for the current line and "$"
101+
for the last line.
99102

100103
*:ll*
101104
:ll[!] [nr] Same as ":cc", except the location list for the
102-
current window is used instead of the quickfix list.
105+
:[nr]ll[!] current window is used instead of the quickfix list.
103106

104107
*:cn* *:cnext* *E553*
105108
:[count]cn[ext][!] Display the [count] next error in the list that

src/eval.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9595,14 +9595,27 @@ assert_beeps(typval_T *argvars)
95959595
return ret;
95969596
}
95979597

9598+
static void
9599+
assert_append_cmd_or_arg(garray_T *gap, typval_T *argvars, char_u *cmd)
9600+
{
9601+
char_u *tofree;
9602+
char_u numbuf[NUMBUFLEN];
9603+
9604+
if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN)
9605+
{
9606+
ga_concat(gap, echo_string(&argvars[2], &tofree, numbuf, 0));
9607+
vim_free(tofree);
9608+
}
9609+
else
9610+
ga_concat(gap, cmd);
9611+
}
9612+
95989613
int
95999614
assert_fails(typval_T *argvars)
96009615
{
96019616
char_u *cmd = tv_get_string_chk(&argvars[0]);
96029617
garray_T ga;
96039618
int ret = 0;
9604-
char_u numbuf[NUMBUFLEN];
9605-
char_u *tofree;
96069619

96079620
called_emsg = FALSE;
96089621
suppress_errthrow = TRUE;
@@ -9612,14 +9625,7 @@ assert_fails(typval_T *argvars)
96129625
{
96139626
prepare_assert_error(&ga);
96149627
ga_concat(&ga, (char_u *)"command did not fail: ");
9615-
if (argvars[1].v_type != VAR_UNKNOWN
9616-
&& argvars[2].v_type != VAR_UNKNOWN)
9617-
{
9618-
ga_concat(&ga, echo_string(&argvars[2], &tofree, numbuf, 0));
9619-
vim_free(tofree);
9620-
}
9621-
else
9622-
ga_concat(&ga, cmd);
9628+
assert_append_cmd_or_arg(&ga, argvars, cmd);
96239629
assert_error(&ga);
96249630
ga_clear(&ga);
96259631
ret = 1;
@@ -9635,6 +9641,8 @@ assert_fails(typval_T *argvars)
96359641
prepare_assert_error(&ga);
96369642
fill_assert_error(&ga, &argvars[2], NULL, &argvars[1],
96379643
&vimvars[VV_ERRMSG].vv_tv, ASSERT_OTHER);
9644+
ga_concat(&ga, (char_u *)": ");
9645+
assert_append_cmd_or_arg(&ga, argvars, cmd);
96389646
assert_error(&ga);
96399647
ga_clear(&ga);
96409648
ret = 1;

src/ex_cmds.h

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ typedef enum {
7373
ADDR_BUFFERS, // buffer number
7474
ADDR_TABS, // tab page number
7575
ADDR_TABS_RELATIVE, // Tab page that only relative
76+
ADDR_QUICKFIX_VALID, // quickfix list valid entry number
7677
ADDR_QUICKFIX, // quickfix list entry number
77-
ADDR_OTHER, // something else
78+
ADDR_UNSIGNED, // positive count or zero, defaults to 1
79+
ADDR_OTHER, // something else, use line number for '$', '%', etc.
7880
ADDR_NONE // no range used
7981
} cmd_addr_T;
8082
#endif
@@ -92,7 +94,7 @@ typedef struct exarg exarg_T;
9294
* Not supported commands are included to avoid ambiguities.
9395
*/
9496
#ifdef EX
95-
# undef EX /* just in case */
97+
# undef EX // just in case
9698
#endif
9799
#ifdef DO_DECLARE_EXCMD
98100
# define EX(a, b, c, d, e) {(char_u *)b, c, (long_u)(d), e}
@@ -242,19 +244,19 @@ EX(CMD_change, "change", ex_change,
242244
ADDR_LINES),
243245
EX(CMD_cNext, "cNext", ex_cnext,
244246
RANGE|COUNT|TRLBAR|BANG,
245-
ADDR_OTHER),
247+
ADDR_UNSIGNED),
246248
EX(CMD_cNfile, "cNfile", ex_cnext,
247249
RANGE|COUNT|TRLBAR|BANG,
248-
ADDR_OTHER),
250+
ADDR_UNSIGNED),
249251
EX(CMD_cabbrev, "cabbrev", ex_abbreviate,
250252
EXTRA|TRLBAR|NOTRLCOM|USECTRLV|CMDWIN,
251253
ADDR_NONE),
252254
EX(CMD_cabclear, "cabclear", ex_abclear,
253255
EXTRA|TRLBAR|CMDWIN,
254256
ADDR_NONE),
255257
EX(CMD_cabove, "cabove", ex_cbelow,
256-
RANGE|TRLBAR,
257-
ADDR_OTHER),
258+
RANGE|COUNT|TRLBAR,
259+
ADDR_UNSIGNED),
258260
EX(CMD_caddbuffer, "caddbuffer", ex_cbuffer,
259261
RANGE|WORD1|TRLBAR,
260262
ADDR_OTHER),
@@ -274,14 +276,14 @@ EX(CMD_cbuffer, "cbuffer", ex_cbuffer,
274276
BANG|RANGE|WORD1|TRLBAR,
275277
ADDR_OTHER),
276278
EX(CMD_cbelow, "cbelow", ex_cbelow,
277-
RANGE|TRLBAR,
278-
ADDR_OTHER),
279+
RANGE|COUNT|TRLBAR,
280+
ADDR_UNSIGNED),
279281
EX(CMD_cbottom, "cbottom", ex_cbottom,
280282
TRLBAR,
281283
ADDR_NONE),
282284
EX(CMD_cc, "cc", ex_cc,
283285
RANGE|COUNT|TRLBAR|BANG,
284-
ADDR_OTHER),
286+
ADDR_QUICKFIX),
285287
EX(CMD_cclose, "cclose", ex_cclose,
286288
TRLBAR,
287289
ADDR_NONE),
@@ -290,7 +292,7 @@ EX(CMD_cd, "cd", ex_cd,
290292
ADDR_NONE),
291293
EX(CMD_cdo, "cdo", ex_listdo,
292294
BANG|NEEDARG|EXTRA|NOTRLCOM|RANGE|DFLALL,
293-
ADDR_QUICKFIX),
295+
ADDR_QUICKFIX_VALID),
294296
EX(CMD_center, "center", ex_align,
295297
TRLBAR|RANGE|WHOLEFOLD|EXTRA|CMDWIN|MODIFY,
296298
ADDR_LINES),
@@ -302,10 +304,10 @@ EX(CMD_cfile, "cfile", ex_cfile,
302304
ADDR_NONE),
303305
EX(CMD_cfdo, "cfdo", ex_listdo,
304306
BANG|NEEDARG|EXTRA|NOTRLCOM|RANGE|DFLALL,
305-
ADDR_QUICKFIX),
307+
ADDR_QUICKFIX_VALID),
306308
EX(CMD_cfirst, "cfirst", ex_cc,
307309
RANGE|COUNT|TRLBAR|BANG,
308-
ADDR_OTHER),
310+
ADDR_UNSIGNED),
309311
EX(CMD_cgetfile, "cgetfile", ex_cfile,
310312
TRLBAR|FILE1,
311313
ADDR_NONE),
@@ -335,7 +337,7 @@ EX(CMD_clist, "clist", qf_list,
335337
ADDR_NONE),
336338
EX(CMD_clast, "clast", ex_cc,
337339
RANGE|COUNT|TRLBAR|BANG,
338-
ADDR_OTHER),
340+
ADDR_UNSIGNED),
339341
EX(CMD_close, "close", ex_close,
340342
BANG|RANGE|COUNT|TRLBAR|CMDWIN,
341343
ADDR_WINDOWS),
@@ -353,13 +355,13 @@ EX(CMD_cmenu, "cmenu", ex_menu,
353355
ADDR_OTHER),
354356
EX(CMD_cnext, "cnext", ex_cnext,
355357
RANGE|COUNT|TRLBAR|BANG,
356-
ADDR_OTHER),
358+
ADDR_UNSIGNED),
357359
EX(CMD_cnewer, "cnewer", qf_age,
358360
RANGE|COUNT|TRLBAR,
359-
ADDR_OTHER),
361+
ADDR_UNSIGNED),
360362
EX(CMD_cnfile, "cnfile", ex_cnext,
361363
RANGE|COUNT|TRLBAR|BANG,
362-
ADDR_OTHER),
364+
ADDR_UNSIGNED),
363365
EX(CMD_cnoremap, "cnoremap", ex_map,
364366
EXTRA|TRLBAR|NOTRLCOM|USECTRLV|CMDWIN,
365367
ADDR_NONE),
@@ -374,7 +376,7 @@ EX(CMD_copy, "copy", ex_copymove,
374376
ADDR_LINES),
375377
EX(CMD_colder, "colder", qf_age,
376378
RANGE|COUNT|TRLBAR,
377-
ADDR_OTHER),
379+
ADDR_UNSIGNED),
378380
EX(CMD_colorscheme, "colorscheme", ex_colorscheme,
379381
WORD1|TRLBAR|CMDWIN,
380382
ADDR_NONE),
@@ -398,7 +400,7 @@ EX(CMD_copen, "copen", ex_copen,
398400
ADDR_OTHER),
399401
EX(CMD_cprevious, "cprevious", ex_cnext,
400402
RANGE|COUNT|TRLBAR|BANG,
401-
ADDR_OTHER),
403+
ADDR_UNSIGNED),
402404
EX(CMD_cpfile, "cpfile", ex_cnext,
403405
RANGE|COUNT|TRLBAR|BANG,
404406
ADDR_OTHER),
@@ -407,7 +409,7 @@ EX(CMD_cquit, "cquit", ex_cquit,
407409
ADDR_NONE),
408410
EX(CMD_crewind, "crewind", ex_cc,
409411
RANGE|COUNT|TRLBAR|BANG,
410-
ADDR_OTHER),
412+
ADDR_UNSIGNED),
411413
EX(CMD_cscope, "cscope", ex_cscope,
412414
EXTRA|NOTRLCOM|XFILE,
413415
ADDR_NONE),
@@ -725,16 +727,16 @@ EX(CMD_list, "list", ex_print,
725727
ADDR_LINES),
726728
EX(CMD_lNext, "lNext", ex_cnext,
727729
RANGE|COUNT|TRLBAR|BANG,
728-
ADDR_OTHER),
730+
ADDR_UNSIGNED),
729731
EX(CMD_lNfile, "lNfile", ex_cnext,
730732
RANGE|COUNT|TRLBAR|BANG,
731-
ADDR_OTHER),
733+
ADDR_UNSIGNED),
732734
EX(CMD_last, "last", ex_last,
733735
EXTRA|BANG|EDITCMD|ARGOPT|TRLBAR,
734736
ADDR_NONE),
735737
EX(CMD_labove, "labove", ex_cbelow,
736-
RANGE|TRLBAR,
737-
ADDR_OTHER),
738+
RANGE|COUNT|TRLBAR,
739+
ADDR_UNSIGNED),
738740
EX(CMD_language, "language", ex_language,
739741
EXTRA|TRLBAR|CMDWIN,
740742
ADDR_NONE),
@@ -754,8 +756,8 @@ EX(CMD_lbuffer, "lbuffer", ex_cbuffer,
754756
BANG|RANGE|WORD1|TRLBAR,
755757
ADDR_OTHER),
756758
EX(CMD_lbelow, "lbelow", ex_cbelow,
757-
RANGE|TRLBAR,
758-
ADDR_OTHER),
759+
RANGE|COUNT|TRLBAR,
760+
ADDR_UNSIGNED),
759761
EX(CMD_lbottom, "lbottom", ex_cbottom,
760762
TRLBAR,
761763
ADDR_NONE),
@@ -773,7 +775,7 @@ EX(CMD_lcscope, "lcscope", ex_cscope,
773775
ADDR_NONE),
774776
EX(CMD_ldo, "ldo", ex_listdo,
775777
BANG|NEEDARG|EXTRA|NOTRLCOM|RANGE|DFLALL,
776-
ADDR_QUICKFIX),
778+
ADDR_QUICKFIX_VALID),
777779
EX(CMD_left, "left", ex_align,
778780
TRLBAR|RANGE|WHOLEFOLD|EXTRA|CMDWIN|MODIFY,
779781
ADDR_LINES),
@@ -791,10 +793,10 @@ EX(CMD_lfile, "lfile", ex_cfile,
791793
ADDR_NONE),
792794
EX(CMD_lfdo, "lfdo", ex_listdo,
793795
BANG|NEEDARG|EXTRA|NOTRLCOM|RANGE|DFLALL,
794-
ADDR_QUICKFIX),
796+
ADDR_QUICKFIX_VALID),
795797
EX(CMD_lfirst, "lfirst", ex_cc,
796798
RANGE|COUNT|TRLBAR|BANG,
797-
ADDR_OTHER),
799+
ADDR_UNSIGNED),
798800
EX(CMD_lgetfile, "lgetfile", ex_cfile,
799801
TRLBAR|FILE1,
800802
ADDR_NONE),
@@ -818,10 +820,10 @@ EX(CMD_lhistory, "lhistory", qf_history,
818820
ADDR_NONE),
819821
EX(CMD_ll, "ll", ex_cc,
820822
RANGE|COUNT|TRLBAR|BANG,
821-
ADDR_OTHER),
823+
ADDR_QUICKFIX),
822824
EX(CMD_llast, "llast", ex_cc,
823825
RANGE|COUNT|TRLBAR|BANG,
824-
ADDR_OTHER),
826+
ADDR_UNSIGNED),
825827
EX(CMD_llist, "llist", qf_list,
826828
BANG|EXTRA|TRLBAR|CMDWIN,
827829
ADDR_NONE),
@@ -839,13 +841,13 @@ EX(CMD_lnoremap, "lnoremap", ex_map,
839841
ADDR_NONE),
840842
EX(CMD_lnext, "lnext", ex_cnext,
841843
RANGE|COUNT|TRLBAR|BANG,
842-
ADDR_OTHER),
844+
ADDR_UNSIGNED),
843845
EX(CMD_lnewer, "lnewer", qf_age,
844846
RANGE|COUNT|TRLBAR,
845-
ADDR_OTHER),
847+
ADDR_UNSIGNED),
846848
EX(CMD_lnfile, "lnfile", ex_cnext,
847849
RANGE|COUNT|TRLBAR|BANG,
848-
ADDR_OTHER),
850+
ADDR_UNSIGNED),
849851
EX(CMD_loadview, "loadview", ex_loadview,
850852
FILE1|TRLBAR,
851853
ADDR_NONE),
@@ -860,19 +862,19 @@ EX(CMD_lockvar, "lockvar", ex_lockvar,
860862
ADDR_NONE),
861863
EX(CMD_lolder, "lolder", qf_age,
862864
RANGE|COUNT|TRLBAR,
863-
ADDR_OTHER),
865+
ADDR_UNSIGNED),
864866
EX(CMD_lopen, "lopen", ex_copen,
865867
RANGE|COUNT|TRLBAR,
866868
ADDR_OTHER),
867869
EX(CMD_lprevious, "lprevious", ex_cnext,
868870
RANGE|COUNT|TRLBAR|BANG,
869-
ADDR_OTHER),
871+
ADDR_UNSIGNED),
870872
EX(CMD_lpfile, "lpfile", ex_cnext,
871873
RANGE|COUNT|TRLBAR|BANG,
872874
ADDR_OTHER),
873875
EX(CMD_lrewind, "lrewind", ex_cc,
874876
RANGE|COUNT|TRLBAR|BANG,
875-
ADDR_OTHER),
877+
ADDR_UNSIGNED),
876878
EX(CMD_ltag, "ltag", ex_tag,
877879
TRLBAR|BANG|WORD1,
878880
ADDR_NONE),

src/ex_cmds2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2132,7 +2132,7 @@ ex_listdo(exarg_T *eap)
21322132
else if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo
21332133
|| eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo)
21342134
{
2135-
qf_size = qf_get_size(eap);
2135+
qf_size = qf_get_valid_size(eap);
21362136
if (qf_size <= 0 || eap->line1 > qf_size)
21372137
buf = NULL;
21382138
else

0 commit comments

Comments
 (0)