patch 9.1.0381: cbuffer and similar commands don't accept a range

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: #14638
closes: #14657

Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Christian Brabandt
2024-04-29 20:36:49 +02:00
parent c4d0c8c812
commit 652c821366
4 changed files with 91 additions and 13 deletions

View File

@ -1,4 +1,4 @@
*quickfix.txt* For Vim version 9.1. Last change: 2023 Apr 15
*quickfix.txt* For Vim version 9.1. Last change: 2024 Apr 28
VIM REFERENCE MANUAL by Bram Moolenaar
@ -287,7 +287,8 @@ processing a quickfix or location list command, it will be aborted.
current window is used instead of the quickfix list.
*:cb* *:cbuffer* *E681*
:cb[uffer][!] [bufnr] Read the error list from the current buffer.
:[range]cb[uffer][!] [bufnr]
Read the error list from the current buffer.
When [bufnr] is given it must be the number of a
loaded buffer. That buffer will then be used instead
of the current buffer.
@ -296,26 +297,31 @@ processing a quickfix or location list command, it will be aborted.
See |:cc| for [!].
*:lb* *:lbuffer*
:lb[uffer][!] [bufnr] Same as ":cbuffer", except the location list for the
:[range]lb[uffer][!] [bufnr]
Same as ":cbuffer", except the location list for the
current window is used instead of the quickfix list.
*:cgetb* *:cgetbuffer*
:cgetb[uffer] [bufnr] Read the error list from the current buffer. Just
:[range]cgetb[uffer] [bufnr]
Read the error list from the current buffer. Just
like ":cbuffer" but don't jump to the first error.
*:lgetb* *:lgetbuffer*
:lgetb[uffer] [bufnr] Same as ":cgetbuffer", except the location list for
:[range]lgetb[uffer] [bufnr]
Same as ":cgetbuffer", except the location list for
the current window is used instead of the quickfix
list.
*:cad* *:cadd* *:caddbuffer*
:cad[dbuffer] [bufnr] Read the error list from the current buffer and add
:[range]cad[dbuffer] [bufnr]
Read the error list from the current buffer and add
the errors to the current quickfix list. If a
quickfix list is not present, then a new list is
created. Otherwise, same as ":cbuffer".
*:laddb* *:laddbuffer*
:laddb[uffer] [bufnr] Same as ":caddbuffer", except the location list for
:[range]laddb[uffer] [bufnr]
Same as ":caddbuffer", except the location list for
the current window is used instead of the quickfix
list.

View File

@ -271,7 +271,7 @@ EXCMD(CMD_cabove, "cabove", ex_cbelow,
ADDR_UNSIGNED),
EXCMD(CMD_caddbuffer, "caddbuffer", ex_cbuffer,
EX_RANGE|EX_WORD1|EX_TRLBAR,
ADDR_OTHER),
ADDR_LINES),
EXCMD(CMD_caddexpr, "caddexpr", ex_cexpr,
EX_NEEDARG|EX_WORD1|EX_NOTRLCOM|EX_EXPR_ARG,
ADDR_NONE),
@ -289,7 +289,7 @@ EXCMD(CMD_catch, "catch", ex_catch,
ADDR_NONE),
EXCMD(CMD_cbuffer, "cbuffer", ex_cbuffer,
EX_BANG|EX_RANGE|EX_WORD1|EX_TRLBAR,
ADDR_OTHER),
ADDR_LINES),
EXCMD(CMD_cbefore, "cbefore", ex_cbelow,
EX_RANGE|EX_COUNT|EX_TRLBAR,
ADDR_UNSIGNED),
@ -331,7 +331,7 @@ EXCMD(CMD_cgetfile, "cgetfile", ex_cfile,
ADDR_NONE),
EXCMD(CMD_cgetbuffer, "cgetbuffer", ex_cbuffer,
EX_RANGE|EX_WORD1|EX_TRLBAR,
ADDR_OTHER),
ADDR_LINES),
EXCMD(CMD_cgetexpr, "cgetexpr", ex_cexpr,
EX_NEEDARG|EX_WORD1|EX_NOTRLCOM|EX_EXPR_ARG,
ADDR_NONE),
@ -820,7 +820,7 @@ EXCMD(CMD_laddexpr, "laddexpr", ex_cexpr,
ADDR_NONE),
EXCMD(CMD_laddbuffer, "laddbuffer", ex_cbuffer,
EX_RANGE|EX_WORD1|EX_TRLBAR,
ADDR_OTHER),
ADDR_LINES),
EXCMD(CMD_laddfile, "laddfile", ex_cfile,
EX_TRLBAR|EX_FILE1,
ADDR_NONE),
@ -832,7 +832,7 @@ EXCMD(CMD_later, "later", ex_later,
ADDR_NONE),
EXCMD(CMD_lbuffer, "lbuffer", ex_cbuffer,
EX_BANG|EX_RANGE|EX_WORD1|EX_TRLBAR,
ADDR_OTHER),
ADDR_LINES),
EXCMD(CMD_lbefore, "lbefore", ex_cbelow,
EX_RANGE|EX_COUNT|EX_TRLBAR,
ADDR_UNSIGNED),
@ -886,7 +886,7 @@ EXCMD(CMD_lgetfile, "lgetfile", ex_cfile,
ADDR_NONE),
EXCMD(CMD_lgetbuffer, "lgetbuffer", ex_cbuffer,
EX_RANGE|EX_WORD1|EX_TRLBAR,
ADDR_OTHER),
ADDR_LINES),
EXCMD(CMD_lgetexpr, "lgetexpr", ex_cexpr,
EX_NEEDARG|EX_WORD1|EX_NOTRLCOM|EX_EXPR_ARG,
ADDR_NONE),

View File

@ -6496,4 +6496,74 @@ func Test_efm_format_b()
call setqflist([], 'f')
endfunc
func XbufferTests_range(cchar)
call s:setup_commands(a:cchar)
enew!
let lines =<< trim END
Xtestfile7:700:10:Line 700
Xtestfile8:800:15:Line 800
END
silent! call setline(1, lines)
norm! Vy
" Note: We cannot use :Xbuffer here,
" it doesn't properly fail, so we need to
" test using the raw c/l commands.
" (also further down)
if (a:cchar == 'c')
exe "'<,'>cbuffer!"
else
exe "'<,'>lbuffer!"
endif
let l = g:Xgetlist()
call assert_true(len(l) == 1 &&
\ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700')
enew!
let lines =<< trim END
Xtestfile9:900:55:Line 900
Xtestfile10:950:66:Line 950
END
silent! call setline(1, lines)
if (a:cchar == 'c')
1cgetbuffer
else
1lgetbuffer
endif
let l = g:Xgetlist()
call assert_true(len(l) == 1 &&
\ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900')
enew!
let lines =<< trim END
Xtestfile11:700:20:Line 700
Xtestfile12:750:25:Line 750
END
silent! call setline(1, lines)
if (a:cchar == 'c')
1,1caddbuffer
else
1,1laddbuffer
endif
let l = g:Xgetlist()
call assert_true(len(l) == 2 &&
\ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' &&
\ l[1].lnum == 700 && l[1].col == 20 && l[1].text ==# 'Line 700')
enew!
" Check for invalid range
" Using Xbuffer will not run the range check in the cbuffer/lbuffer
" commands. So directly call the commands.
if (a:cchar == 'c')
call assert_fails('900,999caddbuffer', 'E16:')
else
call assert_fails('900,999laddbuffer', 'E16:')
endif
endfunc
func Test_cbuffer_range()
call XbufferTests_range('c')
call XbufferTests_range('l')
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
381,
/**/
380,
/**/