Coder Social home page Coder Social logo

Comments (28)

chrisbra avatar chrisbra commented on July 4, 2024

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.

from vim.

Yggdroot avatar Yggdroot commented on July 4, 2024

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.

from vim.

Shane-XB-Qian avatar Shane-XB-Qian commented on July 4, 2024

from vim.

chrisbra avatar chrisbra commented on July 4, 2024

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().

from vim.

Yggdroot avatar Yggdroot commented on July 4, 2024

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'})

from vim.

Yggdroot avatar Yggdroot commented on July 4, 2024

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.

3. When text changes *text-prop-changes*
Vim will do its best to keep the text properties on the text where it was
attached. When inserting or deleting text the properties after the change
will move accordingly.
When text is deleted and a text property no longer includes any text, it is
deleted. However, a text property that was defined as zero-width will remain,
unless the whole line is deleted.

However, a text property that was defined as zero-width will remain, unless the whole line is deleted.

from vim.

chrisbra avatar chrisbra commented on July 4, 2024

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.

from vim.

zeertzjq avatar zeertzjq commented on July 4, 2024

Maybe this can be made configurable as a flag of text properties? Similar to neovim/neovim#25767 but in the opposite way.

from vim.

Yggdroot avatar Yggdroot commented on July 4, 2024

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 ?

I think the whole line is deleted is like: norm! dd . setline just need to replace the content of the specified line of buffer.

from vim.

chrisbra avatar chrisbra commented on July 4, 2024

I rather thought of making the behaviour of setline() configurable.

from vim.

habamax avatar habamax commented on July 4, 2024

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.

from vim.

chrisbra avatar chrisbra commented on July 4, 2024

I think removal of text properties as of current implementation is expected.

Yes, that is also my expectation, see also:

Text property columns are not updated or copied: ~
- When setting the line with |setline()| or through an interface, such as Lua,
Tcl or Python. Vim does not know what text got inserted or deleted.
- With a command like `:move`, which takes a line of text out of context.

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?

from vim.

Shane-XB-Qian avatar Shane-XB-Qian commented on July 4, 2024

from vim.

Yggdroot avatar Yggdroot commented on July 4, 2024

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

from vim.

Shane-XB-Qian avatar Shane-XB-Qian commented on July 4, 2024

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. 🤷

from vim.

Yggdroot avatar Yggdroot commented on July 4, 2024

I think removal of text properties as of current implementation is expected.

Yes, that is also my expectation, see also:

Text property columns are not updated or copied: ~
- When setting the line with |setline()| or through an interface, such as Lua,
Tcl or Python. Vim does not know what text got inserted or deleted.
- With a command like `:move`, which takes a line of text out of context.

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?

from vim.

Shane-XB-Qian avatar Shane-XB-Qian commented on July 4, 2024

unless the whole line is deleted it was said for D 😅

from vim.

Yggdroot avatar Yggdroot commented on July 4, 2024

unless the whole line is deleted it was said for D 😅

I think it's dd

from vim.

Shane-XB-Qian avatar Shane-XB-Qian commented on July 4, 2024

i meant that statement was expressed why D was special.

from vim.

chrisbra avatar chrisbra commented on July 4, 2024

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) 

from vim.

Yggdroot avatar Yggdroot commented on July 4, 2024

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?

from vim.

habamax avatar habamax commented on July 4, 2024

: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.

image

from vim.

habamax avatar habamax commented on July 4, 2024

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.

from vim.

Shane-XB-Qian avatar Shane-XB-Qian commented on July 4, 2024

from vim.

Yggdroot avatar Yggdroot commented on July 4, 2024

Can we make their behavior the same?
the 'question' had been answered above.

-- shane.xb.qian

I don't think so.

from vim.

bfrg avatar bfrg commented on July 4, 2024

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. 😄

from vim.

Yggdroot avatar Yggdroot commented on July 4, 2024

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?

from vim.

chrisbra avatar chrisbra commented on July 4, 2024

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.

from vim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.