Skip to content

Commit 51a7454

Browse files
committed
patch 8.1.0560: cannot use address type "other" with with user command
Problem: Cannot use address type "other" with with user command. Solution: Add "other" to the list. (Daniel Hahler, closes #3655) Also reject "%" for commands with "other". Add some more tests.
1 parent b513d30 commit 51a7454

3 files changed

Lines changed: 63 additions & 1 deletion

File tree

src/ex_docmd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,6 +2998,7 @@ parse_cmd_address(exarg_T *eap, char_u **errormsg, int silent)
29982998
}
29992999
break;
30003000
case ADDR_TABS_RELATIVE:
3001+
case ADDR_OTHER:
30013002
*errormsg = (char_u *)_(e_invrange);
30023003
return FAIL;
30033004
case ADDR_ARGUMENTS:
@@ -5940,6 +5941,7 @@ static struct
59405941
{ADDR_BUFFERS, "buffers"},
59415942
{ADDR_WINDOWS, "windows"},
59425943
{ADDR_QUICKFIX, "quickfix"},
5944+
{ADDR_OTHER, "other"},
59435945
{-1, NULL}
59445946
};
59455947
#endif

src/testdir/test_usercommands.vim

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func Test_CmdCompletion()
154154
call assert_equal('"com -nargs=* + 0 1 ?', @:)
155155

156156
call feedkeys(":com -addr=\<C-A>\<C-B>\"\<CR>", 'tx')
157-
call assert_equal('"com -addr=arguments buffers lines loaded_buffers quickfix tabs windows', @:)
157+
call assert_equal('"com -addr=arguments buffers lines loaded_buffers other quickfix tabs windows', @:)
158158

159159
call feedkeys(":com -complete=co\<C-A>\<C-B>\"\<CR>", 'tx')
160160
call assert_equal('"com -complete=color command compiler', @:)
@@ -218,3 +218,61 @@ func Test_use_execute_in_completion()
218218
call assert_equal('"DoExec hi', @:)
219219
delcommand DoExec
220220
endfunc
221+
222+
func Test_addr_all()
223+
command! -addr=lines DoSomething let g:a1 = <line1> | let g:a2 = <line2>
224+
%DoSomething
225+
call assert_equal(1, g:a1)
226+
call assert_equal(line('$'), g:a2)
227+
228+
command! -addr=arguments DoSomething let g:a1 = <line1> | let g:a2 = <line2>
229+
args one two three
230+
%DoSomething
231+
call assert_equal(1, g:a1)
232+
call assert_equal(3, g:a2)
233+
234+
command! -addr=buffers DoSomething let g:a1 = <line1> | let g:a2 = <line2>
235+
%DoSomething
236+
for low in range(1, bufnr('$'))
237+
if buflisted(low)
238+
break
239+
endif
240+
endfor
241+
call assert_equal(low, g:a1)
242+
call assert_equal(bufnr('$'), g:a2)
243+
244+
command! -addr=loaded_buffers DoSomething let g:a1 = <line1> | let g:a2 = <line2>
245+
%DoSomething
246+
for low in range(1, bufnr('$'))
247+
if bufloaded(low)
248+
break
249+
endif
250+
endfor
251+
call assert_equal(low, g:a1)
252+
for up in range(bufnr('$'), 1, -1)
253+
if bufloaded(up)
254+
break
255+
endif
256+
endfor
257+
call assert_equal(up, g:a2)
258+
259+
command! -addr=windows DoSomething let g:a1 = <line1> | let g:a2 = <line2>
260+
new
261+
%DoSomething
262+
call assert_equal(1, g:a1)
263+
call assert_equal(winnr('$'), g:a2)
264+
bwipe
265+
266+
command! -addr=tabs DoSomething let g:a1 = <line1> | let g:a2 = <line2>
267+
tabnew
268+
%DoSomething
269+
call assert_equal(1, g:a1)
270+
call assert_equal(len(gettabinfo()), g:a2)
271+
bwipe
272+
273+
command! -addr=other DoSomething echo 'nothing'
274+
DoSomething
275+
call assert_fails('%DoSomething')
276+
277+
delcommand DoSomething
278+
endfunc

src/version.c

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

793793
static int included_patches[] =
794794
{ /* Add new patch number below this line */
795+
/**/
796+
560,
795797
/**/
796798
559,
797799
/**/

0 commit comments

Comments
 (0)