Skip to content

Commit e373277

Browse files
zeertzjqchrisbra
authored andcommitted
vim-patch:9.1.0381: cbuffer and similar commands don't accept a range (neovim#28571)
Problem: cbuffer and similar quickfix and locationlist commands don't accept a range, even so it is documented they should (ilan-schemoul, after 8.1.1241) Solution: Define ex commands with ADDR_LINES instead of ADDR_OTHER fixes: vim/vim#14638 closes: vim/vim#14657 vim/vim@652c821 Co-authored-by: Christian Brabandt <[email protected]>
1 parent 2ebeb61 commit e373277

File tree

3 files changed

+88
-12
lines changed

3 files changed

+88
-12
lines changed

runtime/doc/quickfix.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ processing a quickfix or location list command, it will be aborted.
275275
current window is used instead of the quickfix list.
276276

277277
*:cb* *:cbuffer* *E681*
278-
:cb[uffer][!] [bufnr] Read the error list from the current buffer.
278+
:[range]cb[uffer][!] [bufnr]
279+
Read the error list from the current buffer.
279280
When [bufnr] is given it must be the number of a
280281
loaded buffer. That buffer will then be used instead
281282
of the current buffer.
@@ -284,26 +285,31 @@ processing a quickfix or location list command, it will be aborted.
284285
See |:cc| for [!].
285286

286287
*:lb* *:lbuffer*
287-
:lb[uffer][!] [bufnr] Same as ":cbuffer", except the location list for the
288+
:[range]lb[uffer][!] [bufnr]
289+
Same as ":cbuffer", except the location list for the
288290
current window is used instead of the quickfix list.
289291

290292
*:cgetb* *:cgetbuffer*
291-
:cgetb[uffer] [bufnr] Read the error list from the current buffer. Just
293+
:[range]cgetb[uffer] [bufnr]
294+
Read the error list from the current buffer. Just
292295
like ":cbuffer" but don't jump to the first error.
293296

294297
*:lgetb* *:lgetbuffer*
295-
:lgetb[uffer] [bufnr] Same as ":cgetbuffer", except the location list for
298+
:[range]lgetb[uffer] [bufnr]
299+
Same as ":cgetbuffer", except the location list for
296300
the current window is used instead of the quickfix
297301
list.
298302

299303
*:cad* *:cadd* *:caddbuffer*
300-
:cad[dbuffer] [bufnr] Read the error list from the current buffer and add
304+
:[range]cad[dbuffer] [bufnr]
305+
Read the error list from the current buffer and add
301306
the errors to the current quickfix list. If a
302307
quickfix list is not present, then a new list is
303308
created. Otherwise, same as ":cbuffer".
304309

305310
*:laddb* *:laddbuffer*
306-
:laddb[uffer] [bufnr] Same as ":caddbuffer", except the location list for
311+
:[range]laddb[uffer] [bufnr]
312+
Same as ":caddbuffer", except the location list for
307313
the current window is used instead of the quickfix
308314
list.
309315

src/nvim/ex_cmds.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ M.cmds = {
337337
{
338338
command = 'caddbuffer',
339339
flags = bit.bor(RANGE, WORD1, TRLBAR),
340-
addr_type = 'ADDR_OTHER',
340+
addr_type = 'ADDR_LINES',
341341
func = 'ex_cbuffer',
342342
},
343343
{
@@ -373,7 +373,7 @@ M.cmds = {
373373
{
374374
command = 'cbuffer',
375375
flags = bit.bor(BANG, RANGE, WORD1, TRLBAR),
376-
addr_type = 'ADDR_OTHER',
376+
addr_type = 'ADDR_LINES',
377377
func = 'ex_cbuffer',
378378
},
379379
{
@@ -459,7 +459,7 @@ M.cmds = {
459459
{
460460
command = 'cgetbuffer',
461461
flags = bit.bor(RANGE, WORD1, TRLBAR),
462-
addr_type = 'ADDR_OTHER',
462+
addr_type = 'ADDR_LINES',
463463
func = 'ex_cbuffer',
464464
},
465465
{
@@ -1329,7 +1329,7 @@ M.cmds = {
13291329
{
13301330
command = 'laddbuffer',
13311331
flags = bit.bor(RANGE, WORD1, TRLBAR),
1332-
addr_type = 'ADDR_OTHER',
1332+
addr_type = 'ADDR_LINES',
13331333
func = 'ex_cbuffer',
13341334
},
13351335
{
@@ -1353,7 +1353,7 @@ M.cmds = {
13531353
{
13541354
command = 'lbuffer',
13551355
flags = bit.bor(BANG, RANGE, WORD1, TRLBAR),
1356-
addr_type = 'ADDR_OTHER',
1356+
addr_type = 'ADDR_LINES',
13571357
func = 'ex_cbuffer',
13581358
},
13591359
{
@@ -1451,7 +1451,7 @@ M.cmds = {
14511451
{
14521452
command = 'lgetbuffer',
14531453
flags = bit.bor(RANGE, WORD1, TRLBAR),
1454-
addr_type = 'ADDR_OTHER',
1454+
addr_type = 'ADDR_LINES',
14551455
func = 'ex_cbuffer',
14561456
},
14571457
{

test/old/testdir/test_quickfix.vim

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6369,4 +6369,74 @@ func Test_efm_format_b()
63696369
call setqflist([], 'f')
63706370
endfunc
63716371

6372+
func XbufferTests_range(cchar)
6373+
call s:setup_commands(a:cchar)
6374+
6375+
enew!
6376+
let lines =<< trim END
6377+
Xtestfile7:700:10:Line 700
6378+
Xtestfile8:800:15:Line 800
6379+
END
6380+
silent! call setline(1, lines)
6381+
norm! Vy
6382+
" Note: We cannot use :Xbuffer here,
6383+
" it doesn't properly fail, so we need to
6384+
" test using the raw c/l commands.
6385+
" (also further down)
6386+
if (a:cchar == 'c')
6387+
exe "'<,'>cbuffer!"
6388+
else
6389+
exe "'<,'>lbuffer!"
6390+
endif
6391+
let l = g:Xgetlist()
6392+
call assert_true(len(l) == 1 &&
6393+
\ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700')
6394+
6395+
enew!
6396+
let lines =<< trim END
6397+
Xtestfile9:900:55:Line 900
6398+
Xtestfile10:950:66:Line 950
6399+
END
6400+
silent! call setline(1, lines)
6401+
if (a:cchar == 'c')
6402+
1cgetbuffer
6403+
else
6404+
1lgetbuffer
6405+
endif
6406+
let l = g:Xgetlist()
6407+
call assert_true(len(l) == 1 &&
6408+
\ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900')
6409+
6410+
enew!
6411+
let lines =<< trim END
6412+
Xtestfile11:700:20:Line 700
6413+
Xtestfile12:750:25:Line 750
6414+
END
6415+
silent! call setline(1, lines)
6416+
if (a:cchar == 'c')
6417+
1,1caddbuffer
6418+
else
6419+
1,1laddbuffer
6420+
endif
6421+
let l = g:Xgetlist()
6422+
call assert_true(len(l) == 2 &&
6423+
\ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' &&
6424+
\ l[1].lnum == 700 && l[1].col == 20 && l[1].text ==# 'Line 700')
6425+
enew!
6426+
6427+
" Check for invalid range
6428+
" Using Xbuffer will not run the range check in the cbuffer/lbuffer
6429+
" commands. So directly call the commands.
6430+
if (a:cchar == 'c')
6431+
call assert_fails('900,999caddbuffer', 'E16:')
6432+
else
6433+
call assert_fails('900,999laddbuffer', 'E16:')
6434+
endif
6435+
endfunc
6436+
6437+
func Test_cbuffer_range()
6438+
call XbufferTests_range('c')
6439+
call XbufferTests_range('l')
6440+
endfunc
6441+
63726442
" vim: shiftwidth=2 sts=2 expandtab

0 commit comments

Comments
 (0)