vim-patch:8.1.0697: ":sign place" requires the buffer argument

Problem:    ":sign place" requires the buffer argument.
Solution:   Make the argument optional.  Also update the help and clean up the
            sign test. (Yegappan Lakshmanan, closes vim/vim#3767)
b328cca254
This commit is contained in:
Andrej Zieger
2019-05-19 21:14:30 +02:00
parent 54c4567564
commit e70609cfac
4 changed files with 96 additions and 67 deletions

View File

@@ -3581,20 +3581,24 @@ extend({expr1}, {expr2} [, {expr3}]) *extend()*
feedkeys({string} [, {mode}]) *feedkeys()* feedkeys({string} [, {mode}]) *feedkeys()*
Characters in {string} are queued for processing as if they Characters in {string} are queued for processing as if they
come from a mapping or were typed by the user. come from a mapping or were typed by the user.
By default the string is added to the end of the typeahead By default the string is added to the end of the typeahead
buffer, thus if a mapping is still being executed the buffer, thus if a mapping is still being executed the
characters come after them. Use the 'i' flag to insert before characters come after them. Use the 'i' flag to insert before
other characters, they will be executed next, before any other characters, they will be executed next, before any
characters from a mapping. characters from a mapping.
The function does not wait for processing of keys contained in The function does not wait for processing of keys contained in
{string}. {string}.
To include special keys into {string}, use double-quotes To include special keys into {string}, use double-quotes
and "\..." notation |expr-quote|. For example, and "\..." notation |expr-quote|. For example,
feedkeys("\<CR>") simulates pressing of the <Enter> key. But feedkeys("\<CR>") simulates pressing of the <Enter> key. But
feedkeys('\<CR>') pushes 5 characters. feedkeys('\<CR>') pushes 5 characters.
If {mode} is absent, keys are remapped.
{mode} is a String, which can contain these character flags: {mode} is a String, which can contain these character flags:
'm' Remap keys. This is default. 'm' Remap keys. This is default. If {mode} is absent,
keys are remapped.
'n' Do not remap keys. 'n' Do not remap keys.
't' Handle keys as if typed; otherwise they are handled as 't' Handle keys as if typed; otherwise they are handled as
if coming from a mapping. This matters for undo, if coming from a mapping. This matters for undo,
@@ -3608,6 +3612,9 @@ feedkeys({string} [, {mode}]) *feedkeys()*
will behave as if <Esc> is typed, to avoid getting will behave as if <Esc> is typed, to avoid getting
stuck, waiting for a character to be typed before the stuck, waiting for a character to be typed before the
script continues. script continues.
Note that if you manage to call feedkeys() while
executing commands, thus calling it recursively, the
all typehead will be consumed by the last call.
'!' When used with 'x' will not end Insert mode. Can be '!' When used with 'x' will not end Insert mode. Can be
used in a test when a timer is set to exit Insert mode used in a test when a timer is set to exit Insert mode
a little later. Useful for testing CursorHoldI. a little later. Useful for testing CursorHoldI.
@@ -7378,6 +7385,9 @@ sign_define({name} [, {dict}]) *sign_define()*
associated line. Overrides |hl-LineNr|, associated line. Overrides |hl-LineNr|,
|hl-CursorLineNr|. |hl-CursorLineNr|.
If the sign named {name} already exists, then the attributes
of the sign are updated.
Returns 0 on success and -1 on failure. Returns 0 on success and -1 on failure.
Examples: > Examples: >
@@ -7432,6 +7442,7 @@ sign_getplaced([{expr} [, {dict}]]) *sign_getplaced()*
empty string, then only signs in the global group are empty string, then only signs in the global group are
returned. If no arguments are supplied, then signs in the returned. If no arguments are supplied, then signs in the
global group placed in all the buffers are returned. global group placed in all the buffers are returned.
See |sign-group|.
Each list item in the returned value is a dictionary with the Each list item in the returned value is a dictionary with the
following entries: following entries:
@@ -7447,7 +7458,8 @@ sign_getplaced([{expr} [, {dict}]]) *sign_getplaced()*
name name of the defined sign name name of the defined sign
priority sign priority priority sign priority
Returns an empty list on failure. Returns an empty list on failure or if there are no placed
signs.
Examples: > Examples: >
" Get a List of signs placed in eval.c in the " Get a List of signs placed in eval.c in the
@@ -7480,7 +7492,8 @@ sign_place({id}, {group}, {name}, {expr} [, {dict}])
allocated. Otherwise the specified number is used. {group} is allocated. Otherwise the specified number is used. {group} is
the sign group name. To use the global sign group, use an the sign group name. To use the global sign group, use an
empty string. {group} functions as a namespace for {id}, thus empty string. {group} functions as a namespace for {id}, thus
two groups can use the same IDs. two groups can use the same IDs. Refer to |sign-identifier|
for more information.
{name} refers to a defined sign. {name} refers to a defined sign.
{expr} refers to a buffer name or number. For the accepted {expr} refers to a buffer name or number. For the accepted
@@ -8576,7 +8589,7 @@ undofile({name}) *undofile()*
If {name} is empty undofile() returns an empty string, since a If {name} is empty undofile() returns an empty string, since a
buffer without a file name will not write an undo file. buffer without a file name will not write an undo file.
Useful in combination with |:wundo| and |:rundo|. Useful in combination with |:wundo| and |:rundo|.
When compiled without the +persistent_undo option this always When compiled without the |+persistent_undo| option this always
returns an empty string. returns an empty string.
undotree() *undotree()* undotree() *undotree()*

View File

@@ -46,13 +46,23 @@ Example to set the color: >
:highlight SignColumn guibg=darkgrey :highlight SignColumn guibg=darkgrey
< <
*sign-identifier*
Each placed sign is identified by a number called the sign identifier. This
identifier is used to jump to the sign or to remove the sign. The identifier
is assigned when placing the sign using the |sign-place| command or the
|sign_place()| function. Each sign identifier should be a unique number. If
multiple placed signs use the same identifier, then jumping to or removing a
sign becomes unpredictable. To avoid overlapping identifiers, sign groups can
be used. The |sign_place()| function can be called with a zero sign identifier
to allocate the next available identifier.
*sign-group* *sign-group*
Each sign can be assigned to either the global group or a named group. When Each placed sign can be assigned to either the global group or a named group.
placing a sign, if a group name is not supplied, or an empty string is used, When placing a sign, if a group name is not supplied, or an empty string is
then the sign is placed in the global group. Otherwise the sign is placed in used, then the sign is placed in the global group. Otherwise the sign is
the named group. The sign identifier is unique within a group. The sign group placed in the named group. The sign identifier is unique within a group. The
allows Vim plugins to use unique signs without interfering with other plugins sign group allows Vim plugins to use unique signs without interfering with
using signs. other plugins using signs.
*sign-priority* *sign-priority*
Each placed sign is assigned a priority value. When multiple signs are placed Each placed sign is assigned a priority value. When multiple signs are placed
@@ -171,8 +181,9 @@ See |sign_place()| for the equivalent Vim script function.
:sign place 9 group=g2 priority=50 line=5 :sign place 9 group=g2 priority=50 line=5
\ name=sign1 file=a.py \ name=sign1 file=a.py
< <
:sign place {id} line={lnum} name={name} buffer={nr} :sign place {id} line={lnum} name={name} [buffer={nr}]
Same, but use buffer {nr}. Same, but use buffer {nr}. If the buffer argument is not
given, place the sign in the current buffer.
*E885* *E885*
:sign place {id} name={name} file={fname} :sign place {id} name={name} file={fname}
@@ -184,8 +195,9 @@ See |sign_place()| for the equivalent Vim script function.
The optional "group={group}" attribute can be used before The optional "group={group}" attribute can be used before
"file=" to select a sign in a particular group. "file=" to select a sign in a particular group.
:sign place {id} name={name} buffer={nr} :sign place {id} name={name} [buffer={nr}]
Same, but use buffer {nr}. Same, but use buffer {nr}. If the buffer argument is not
given, use the current buffer.
REMOVING SIGNS *:sign-unplace* *E159* REMOVING SIGNS *:sign-unplace* *E159*
@@ -307,11 +319,12 @@ JUMPING TO A SIGN *:sign-jump* *E157*
:sign jump {id} group={group} file={fname} :sign jump {id} group={group} file={fname}
Same but jump to the sign in group {group} Same but jump to the sign in group {group}
:sign jump {id} buffer={nr} *E934* :sign jump {id} [buffer={nr}] *E934*
Same, but use buffer {nr}. This fails if buffer {nr} does not Same, but use buffer {nr}. This fails if buffer {nr} does not
have a name. have a name. If the buffer argument is not given, use the
current buffer.
:sign jump {id} group={group} buffer={nr} :sign jump {id} group={group} [buffer={nr}]
Same but jump to the sign in group {group} Same but jump to the sign in group {group}

View File

@@ -1142,7 +1142,7 @@ static void sign_jump_cmd(
char_u *group char_u *group
) )
{ {
if (buf == NULL && sign_name == NULL && group == NULL && id == -1) { if (sign_name == NULL && group == NULL && id == -1) {
EMSG(_(e_argreq)); EMSG(_(e_argreq));
return; return;
} }
@@ -1274,6 +1274,11 @@ static int parse_sign_cmd_args(
return FAIL; return FAIL;
} }
// If the filename is not supplied for the sign place or the sign jump
// command, then use the current buffer.
if (filename == NULL && (cmd == SIGNCMD_PLACE || cmd == SIGNCMD_JUMP)) {
*buf = curwin->w_buffer;
}
return OK; return OK;
} }

View File

@@ -14,7 +14,8 @@ func Test_sign()
" the icon name when listing signs. " the icon name when listing signs.
sign define Sign1 text=x sign define Sign1 text=x
try try
sign define Sign2 text=xy texthl=Title linehl=Error numhl=Number icon=../../pixmaps/stock_vim_find_help.png sign define Sign2 text=xy texthl=Title linehl=Error
\ icon=../../pixmaps/stock_vim_find_help.png
catch /E255:/ catch /E255:/
" Ignore error: E255: Couldn't read in sign data! " Ignore error: E255: Couldn't read in sign data!
" This error can happen when running in the GUI. " This error can happen when running in the GUI.
@@ -23,7 +24,9 @@ func Test_sign()
" Test listing signs. " Test listing signs.
let a=execute('sign list') let a=execute('sign list')
call assert_match("^\nsign Sign1 text=x \nsign Sign2 icon=../../pixmaps/stock_vim_find_help.png .*text=xy linehl=Error texthl=Title numhl=Number$", a) call assert_match('^\nsign Sign1 text=x \nsign Sign2 ' .
\ 'icon=../../pixmaps/stock_vim_find_help.png .*text=xy ' .
\ 'linehl=Error texthl=Title$', a)
let a=execute('sign list Sign1') let a=execute('sign list Sign1')
call assert_equal("\nsign Sign1 text=x ", a) call assert_equal("\nsign Sign1 text=x ", a)
@@ -63,7 +66,8 @@ func Test_sign()
" Check placed signs " Check placed signs
let a=execute('sign place') let a=execute('sign place')
call assert_equal("\n--- Signs ---\nSigns for [NULL]:\n line=3 id=41 name=Sign1 priority=10\n", a) call assert_equal("\n--- Signs ---\nSigns for [NULL]:\n" .
\ " line=3 id=41 name=Sign1 priority=10\n", a)
" Unplace the sign and try jumping to it again should fail. " Unplace the sign and try jumping to it again should fail.
sign unplace 41 sign unplace 41
@@ -87,12 +91,20 @@ func Test_sign()
let a=execute('sign place') let a=execute('sign place')
call assert_equal("\n--- Signs ---\n", a) call assert_equal("\n--- Signs ---\n", a)
" Place a sign without specifying the filename or buffer
sign place 77 line=9 name=Sign2
let a=execute('sign place')
call assert_equal("\n--- Signs ---\nSigns for [NULL]:\n" .
\ " line=9 id=77 name=Sign2 priority=10\n", a)
sign unplace *
" Check :jump with file=... " Check :jump with file=...
edit foo edit foo
call setline(1, ['A', 'B', 'C', 'D']) call setline(1, ['A', 'B', 'C', 'D'])
try try
sign define Sign3 text=y texthl=DoesNotExist linehl=DoesNotExist icon=doesnotexist.xpm sign define Sign3 text=y texthl=DoesNotExist linehl=DoesNotExist
\ icon=doesnotexist.xpm
catch /E255:/ catch /E255:/
" ignore error: E255: it can happens for guis. " ignore error: E255: it can happens for guis.
endtry endtry
@@ -148,38 +160,12 @@ func Test_sign()
call assert_equal("\nsign 4 text=#> linehl=Comment", a) call assert_equal("\nsign 4 text=#> linehl=Comment", a)
exe 'sign place 20 line=3 name=004 buffer=' . bufnr('') exe 'sign place 20 line=3 name=004 buffer=' . bufnr('')
let a = execute('sign place') let a = execute('sign place')
call assert_equal("\n--- Signs ---\nSigns for foo:\n line=3 id=20 name=4 priority=10\n", a) call assert_equal("\n--- Signs ---\nSigns for foo:\n" .
\ " line=3 id=20 name=4 priority=10\n", a)
exe 'sign unplace 20 buffer=' . bufnr('') exe 'sign unplace 20 buffer=' . bufnr('')
sign undefine 004 sign undefine 004
call assert_fails('sign list 4', 'E155:') call assert_fails('sign list 4', 'E155:')
" Error cases
call assert_fails("sign place abc line=3 name=Sign1 buffer=" .
\ bufnr('%'), 'E474:')
call assert_fails("sign unplace abc name=Sign1 buffer=" .
\ bufnr('%'), 'E474:')
call assert_fails("sign place 1abc line=3 name=Sign1 buffer=" .
\ bufnr('%'), 'E474:')
call assert_fails("sign unplace 2abc name=Sign1 buffer=" .
\ bufnr('%'), 'E474:')
call assert_fails("sign unplace 2 *", 'E474:')
call assert_fails("sign place 1 line=3 name=Sign1 buffer=" .
\ bufnr('%') . " a", 'E488:')
call assert_fails("sign place name=Sign1 buffer=" . bufnr('%'), 'E474:')
call assert_fails("sign place line=10 buffer=" . bufnr('%'), 'E474:')
call assert_fails("sign unplace 2 line=10 buffer=" . bufnr('%'), 'E474:')
call assert_fails("sign unplace 2 name=Sign1 buffer=" . bufnr('%'), 'E474:')
call assert_fails("sign place 2 line=3 buffer=" . bufnr('%'), 'E474:')
call assert_fails("sign place 2", 'E474:')
call assert_fails("sign place abc", 'E474:')
call assert_fails("sign place 5 line=3", 'E474:')
call assert_fails("sign place 5 name=Sign1", 'E474:')
call assert_fails("sign place 5 group=g1", 'E474:')
call assert_fails("sign place 5 group=*", 'E474:')
call assert_fails("sign place 5 priority=10", 'E474:')
call assert_fails("sign place 5 line=3 name=Sign1", 'E474:')
call assert_fails("sign place 5 group=g1 line=3 name=Sign1", 'E474:')
" After undefining the sign, we should no longer be able to place it. " After undefining the sign, we should no longer be able to place it.
sign undefine Sign1 sign undefine Sign1
sign undefine Sign2 sign undefine Sign2
@@ -202,7 +188,8 @@ func Test_sign_undefine_still_placed()
" Listing placed sign should show that sign is deleted. " Listing placed sign should show that sign is deleted.
let a=execute('sign place') let a=execute('sign place')
call assert_equal("\n--- Signs ---\nSigns for foobar:\n line=1 id=41 name=[Deleted] priority=10\n", a) call assert_equal("\n--- Signs ---\nSigns for foobar:\n" .
\ " line=1 id=41 name=[Deleted] priority=10\n", a)
sign unplace 41 sign unplace 41
let a=execute('sign place') let a=execute('sign place')
@@ -220,7 +207,8 @@ func Test_sign_completion()
call assert_equal('"sign define Sign icon= linehl= numhl= text= texthl=', @:) call assert_equal('"sign define Sign icon= linehl= numhl= text= texthl=', @:)
call feedkeys(":sign define Sign linehl=Spell\<C-A>\<C-B>\"\<CR>", 'tx') call feedkeys(":sign define Sign linehl=Spell\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"sign define Sign linehl=SpellBad SpellCap SpellLocal SpellRare', @:) call assert_equal('"sign define Sign linehl=SpellBad SpellCap ' .
\ 'SpellLocal SpellRare', @:)
call writefile(['foo'], 'XsignOne') call writefile(['foo'], 'XsignOne')
call writefile(['bar'], 'XsignTwo') call writefile(['bar'], 'XsignTwo')
@@ -273,17 +261,22 @@ func Test_sign_invalid_commands()
call assert_fails('sign jump 1 line=100', '474:') call assert_fails('sign jump 1 line=100', '474:')
call assert_fails('sign define Sign2 text=', 'E239:') call assert_fails('sign define Sign2 text=', 'E239:')
" Non-numeric identifier for :sign place " Non-numeric identifier for :sign place
call assert_fails("sign place abc line=3 name=Sign1 buffer=" . bufnr('%'), 'E474:') call assert_fails("sign place abc line=3 name=Sign1 buffer=" . bufnr(''),
\ 'E474:')
" Non-numeric identifier for :sign unplace " Non-numeric identifier for :sign unplace
call assert_fails("sign unplace abc name=Sign1 buffer=" . bufnr('%'), 'E474:') call assert_fails("sign unplace abc name=Sign1 buffer=" . bufnr(''),
\ 'E474:')
" Number followed by an alphabet as sign identifier for :sign place " Number followed by an alphabet as sign identifier for :sign place
call assert_fails("sign place 1abc line=3 name=Sign1 buffer=" . bufnr('%'), 'E474:') call assert_fails("sign place 1abc line=3 name=Sign1 buffer=" . bufnr(''),
\ 'E474:')
" Number followed by an alphabet as sign identifier for :sign unplace " Number followed by an alphabet as sign identifier for :sign unplace
call assert_fails("sign unplace 2abc name=Sign1 buffer=" . bufnr('%'), 'E474:') call assert_fails("sign unplace 2abc name=Sign1 buffer=" . bufnr(''),
\ 'E474:')
" Sign identifier and '*' for :sign unplace " Sign identifier and '*' for :sign unplace
call assert_fails("sign unplace 2 *", 'E474:') call assert_fails("sign unplace 2 *", 'E474:')
" Trailing characters after buffer number for :sign place " Trailing characters after buffer number for :sign place
call assert_fails("sign place 1 line=3 name=Sign1 buffer=" . bufnr('%') . 'xxx', 'E488:') call assert_fails("sign place 1 line=3 name=Sign1 buffer=" .
\ bufnr('%') . 'xxx', 'E488:')
" Trailing characters after buffer number for :sign unplace " Trailing characters after buffer number for :sign unplace
call assert_fails("sign unplace 1 buffer=" . bufnr('%') . 'xxx', 'E488:') call assert_fails("sign unplace 1 buffer=" . bufnr('%') . 'xxx', 'E488:')
call assert_fails("sign unplace * buffer=" . bufnr('%') . 'xxx', 'E488:') call assert_fails("sign unplace * buffer=" . bufnr('%') . 'xxx', 'E488:')
@@ -306,16 +299,11 @@ func Test_sign_invalid_commands()
call assert_fails("sign place abc", 'E474:') call assert_fails("sign place abc", 'E474:')
" Placing a sign with only line number " Placing a sign with only line number
call assert_fails("sign place 5 line=3", 'E474:') call assert_fails("sign place 5 line=3", 'E474:')
" Placing a sign with only sign name
call assert_fails("sign place 5 name=Sign1", 'E474:')
" Placing a sign with only sign group " Placing a sign with only sign group
call assert_fails("sign place 5 group=g1", 'E474:') call assert_fails("sign place 5 group=g1", 'E474:')
call assert_fails("sign place 5 group=*", 'E474:') call assert_fails("sign place 5 group=*", 'E474:')
" Placing a sign with only sign priority " Placing a sign with only sign priority
call assert_fails("sign place 5 priority=10", 'E474:') call assert_fails("sign place 5 priority=10", 'E474:')
" Placing a sign without buffer number or file name
call assert_fails("sign place 5 line=3 name=Sign1", 'E474:')
call assert_fails("sign place 5 group=g1 line=3 name=Sign1", 'E474:')
sign undefine Sign1 sign undefine Sign1
endfunc endfunc
@@ -624,11 +612,13 @@ func Test_sign_group()
" :sign place file={fname} " :sign place file={fname}
let a = execute('sign place file=Xsign') let a = execute('sign place file=Xsign')
call assert_equal("\n--- Signs ---\nSigns for Xsign:\n line=10 id=5 name=sign1 priority=10\n", a) call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" .
\ " line=10 id=5 name=sign1 priority=10\n", a)
" :sign place group={group} file={fname} " :sign place group={group} file={fname}
let a = execute('sign place group=g2 file=Xsign') let a = execute('sign place group=g2 file=Xsign')
call assert_equal("\n--- Signs ---\nSigns for Xsign:\n line=10 id=5 group=g2 name=sign1 priority=10\n", a) call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" .
\ " line=10 id=5 group=g2 name=sign1 priority=10\n", a)
" :sign place group=* file={fname} " :sign place group=* file={fname}
let a = execute('sign place group=* file=Xsign') let a = execute('sign place group=* file=Xsign')
@@ -649,11 +639,13 @@ func Test_sign_group()
" :sign place buffer={fname} " :sign place buffer={fname}
let a = execute('sign place buffer=' . bnum) let a = execute('sign place buffer=' . bnum)
call assert_equal("\n--- Signs ---\nSigns for Xsign:\n line=10 id=5 name=sign1 priority=10\n", a) call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" .
\ " line=10 id=5 name=sign1 priority=10\n", a)
" :sign place group={group} buffer={fname} " :sign place group={group} buffer={fname}
let a = execute('sign place group=g2 buffer=' . bnum) let a = execute('sign place group=g2 buffer=' . bnum)
call assert_equal("\n--- Signs ---\nSigns for Xsign:\n line=12 id=5 group=g2 name=sign1 priority=10\n", a) call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" .
\ " line=12 id=5 group=g2 name=sign1 priority=10\n", a)
" :sign place group=* buffer={fname} " :sign place group=* buffer={fname}
let a = execute('sign place group=* buffer=' . bnum) let a = execute('sign place group=* buffer=' . bnum)
@@ -690,6 +682,12 @@ func Test_sign_group()
sign jump 5 group=g2 file=Xsign sign jump 5 group=g2 file=Xsign
call assert_equal(12, line('.')) call assert_equal(12, line('.'))
" Test for :sign jump command without the filename or buffer
sign jump 5
call assert_equal(10, line('.'))
sign jump 5 group=g1
call assert_equal(11, line('.'))
" Error cases " Error cases
call assert_fails("sign place 3 group= name=sign1 buffer=" . bnum, 'E474:') call assert_fails("sign place 3 group= name=sign1 buffer=" . bnum, 'E474:')