setline({lnum}, {text}) Set line {lnum} of the current buffer to {text}. To insert lines use append(). To set lines in another buffer use setbufline(). **Any text properties in {lnum} are cleared.**
As the help says: Any text properties in {lnum} are cleared.
If a plugin uses setline
, the text properties defined by other plugins will be removed. This is unexpected.
I think it is reasonable that setline()
does not clear text property.
The following operations have the same effect as call setline(line('.'), '')
ļ¼
0
to go to the first columnD
This won't remove the text property.
Another reason, setline()
won't clear extmarks set by nvim_buf_set_extmark()
in neovim.
setline() does not clear text property.
all
all
No response
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
Well, I can only say this is done intentionally since v8.1.0690. The idea probably was that once you replace a line, all attached properties to it may no longer be valid, which I think makes sense.
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
Although it was intentional, I can not see the advantage of it, but lots of disadvantages. Because I can not prevent the text properties defined by my plugin from being removed by others which use setline()
.
I don't think it make sense that the text property is removed after call setline(line('.'), getline('.'))
, the text is not changed in the user's view.
What is more, as I said above, Another reason, setline() won't clear extmarks set by nvim_buf_set_extmark() in neovimļ¼ where extmarks in neovim is equivalent to text property in vim.
ā
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
What is more, as I said above, Another reason, setline() won't clear extmarks set by nvim_buf_set_extmark() in neovimļ¼ where extmarks in neovim is equivalent to text property in vim.
I don't see how this relates to Vim. We don't have this: nvim_buf_set_extmark()
.
ā
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
looks it make sense if the text was changed. but I am curious you said the by D then it would be remained?
ā¦
-- shane.xb.qian
call prop_type_add('aaa', {'highlight': 'Number'}) call prop_add(line('.'), 0, {'type':'aaa', 'text': 'test'})
ā
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
What is more, as I said above, Another reason, setline() won't clear extmarks set by nvim_buf_set_extmark() in neovimļ¼ where extmarks in neovim is equivalent to text property in vim.
I don't see how this relates to Vim. We don't have this:
nvim_buf_set_extmark()
.
I mean in neovim's point of view, setline
should not remove text property just like setline
does not remove extmarks.
Another reason current behavior is thought to be buggy is : setline
also removes zero-width text property.
However, a text property that was defined as zero-width will remain, unless the whole line is deleted.
ā
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
However, a text property that was defined as zero-width will remain, unless the whole line is deleted.
I think this is essentially what setline does. It deletes the line and replaces it with a new one, even if it is empty.
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
Maybe this can be made configurable as a flag of text properties?
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
However, a text property that was defined as zero-width will remain, unless the whole line is deleted.
I think this is essentially what setline does. It deletes the line and replaces it with a new one, even if it is empty.
Is it not the same with :
norm! 0D
then append some text ?
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
I rahter thought of making the behaviour of setline() configurable.
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
I rather thought of making the behaviour of setline() configurable.
How it would solve the issue then? There still will be setline()
calls that would remove text properties:
Because I can not prevent the text properties defined by my plugin from being removed by others which use setline().
I think removal of text properties as of current implementation is expected.
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
I think removal of text properties as of current implementation is expected.
Yes, that is also my expectation, see also: https://github.com/vim/vim/blob/c52a8560792b47a19fd0686377f588ef25e5a7d4/runtime/doc/textprop.txt#L534-L538
it looks like even :move
drops the text properties.
There still will be setline() calls that would remove text properties
Well, would you expect the text-property to be still there after doing
:5d
:4put ='foobar'
? Once you remove the line and add a new line, how would do you know the attached text-property attached to that line is still valid?
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
ā
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
looks it make sense if the text was changed. but I am curious you said the by D then it would be remained? > ā¦ > -- shane.xb.qian
vim call prop_type_add('aaa', {'highlight': 'Number'}) call prop_add(line('.'), 0, {'type':'aaa', 'text': 'test'})
not sure why
D
was special.. // if delete by :delete, then it was removed too.
ā¦
-- shane.xb.qian
It is different.
:delete is the same as dd
, not D
ā
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
yes, it is different, but the answer maybe as @chrisbra commented above, to D
maybe it was intended to make it happy with instant edit. š¤·
ā
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
I think removal of text properties as of current implementation is expected.
Yes, that is also my expectation, see also:
it looks like even
:move
drops the text properties.There still will be setline() calls that would remove text properties
Well, would you expect the text-property to be still there after doing
:5d :4put ='foobar'
? Once you remove the line and add a new line, how would do you know the attached text-property attached to that line is still valid?
Actually, my expectation is :
for example,
call prop_type_add('aaa', {'highlight': 'Number'}) call prop_add(line('.'), 0, {'type':'aaa', 'text': 'test'})
call setline(line('.'), '')
has the same effect as norm! 0D
.
call prop_type_add('aaa', {'highlight': 'Number'})
call prop_add(line('.'), 1, {'type':'aaa', 'length': 0})
call setline(line('.'), '')
has the same effect as norm! 0D
.
Because However, a text property that was defined as zero-width will remain, unless the whole line is deleted.
I think setline is not delete line 3 and insert a new line after line 2, it is replacing line 3 with new text. Am I right?
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
unless the whole line is deleted
it is D
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
unless the whole line is deleted
it was said for D
š
ā
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
unless the whole line is deleted
it was said forD
š
I think it's dd
ā
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
i meant that statement was expressed why D
was special.
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
I posted the link to the documentation already. It's simply not possible to retain the text property, because how should Vim know where you added some text?
call setline(1, 'You are a hero!') cal prop_type_add('Highlight', #{highlight: 'Search'}) call prop_add(1, 11, {'end_col': 15, 'type': 'Highlight'}) " doesn't work, but would add an off by one error call getline(1)->substitute('\<a\>', 'my', 'g')->setline(1)
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
Notice that my example is special, one is virtual text, the column is 0, another is 0-width.
call prop_type_add('aaa', {'highlight': 'Number'}) call prop_add(line('.'), 0, {'type':'aaa', 'text': 'test'})
call prop_type_add('aaa', {'highlight': 'Number'})
call prop_add(line('.'), 1, {'type':'aaa', 'length': 0})
:call setline(line('.'), '')
will remove the virtual text, :norm! 0D
won't.
Can we make their behavior the same?
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
:call setline(line('.'), '') will remove the virtual text, :norm! 0D won't.
Can we make their behavior the same?
If properties wouldn't be removed, then a lot of things would need to be changed internally...
You have a text property, then you changed a line and now it is invalid.
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
Now if the case is virtual text at the edges of the line -- it could be safe to preserve it, although I am not sure it worth the complexity it brings.
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
Can we make their behavior the same?
the 'question' had been answered above.
ā¦
-- shane.xb.qian
I don't think so.
ā
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
I would also expect setline()
and setbufline()
to remove any text-properties.
I think what you want is something like subbufline()
that substitutes text in a line while preserving text-properties in that line, similar to the :substitute
command. There's already an open feature request for #5632. Bram wasn't opposed to this idea, it just needs to be implemented. š
ā
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
In my view, :call setline(line('.'), '')
and :norm! 0D
do the same thing, why :norm! 0D
don't remove the virtual-text column starts from 0 and the 0-width text property?
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
The effect might be the same, but it is not the same, it's essentially a :d
followed by a :put
.
There is also listener_add()
not sure, if one can use it to save and restore text-properties.
The current behaviour is well documented, so let's close this as a duplicate of #5632 then.
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
Closed #15030 as not planned.
ā
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.