nerdtree icon indicating copy to clipboard operation
nerdtree copied to clipboard

Replace NERDTreeNodeDelimiter with VIM's textprop

Open noscript opened this issue 4 years ago • 3 comments

According to NERDTree documentation, the purpose of NERDTreeNodeDelimiter is

to separate the file or directory name from the rest of the characters in the line of text

This is a hack and can be avoided since VIM introduced text properties. Now is possible to assign a property to any text in the buffer and query it later.

Given the lines in the NERDTree buffer:

  .bazelrc
▸ .conf/ [RO] -> /tmp/configuration_test
▸ .git/
  license.txt

We can set to .conf on the line 2 a property as follows:

call prop_type_add('dir_name', {'highlight': 'Directory'})
call prop_add(2, 5, {'end_col': 11, 'type': 'dir_name'})

Then we can query it from the line 2:

let prop = prop_find({'lnum': 2, 'type': 'dir_name'})
echom getline(2)->strpart(prop.col - 1, prop.length) " prints '.conf/'

Besides being a hack, NERDTreeNodeDelimiter also :

  • requires complex syntax highlighting theme. Text properties can replace syntax files entirely.
  • requires using poorly implemented conceal feature. Concealed text is always included when yanking buffer lines or doing visual selection. When cursor is places on concealed text the cursor acts weird as it moves over invisible characters without visibly moving. Placing the cursor on concealed text with mouse leads to unexpected results. And so on...
  • limits rendering customization, like increasing or decreasing indentation level or showing indent lines (can be worked around with again using more conceal).
  • overall makes NERDTree code more complex and non-intuitive.

noscript avatar Jan 29 '21 14:01 noscript

I like this idea, and you make very valid points, but there are a couple of things holding me back on changing it:

  1. These functions came out with Vim 8.2, which means NERDTree would no longer be compatible with Vim 7.3+.
  2. There are a number of NERDTree plugins that would most likely need changing. Coordinating with their developers is a must to prevent their feeling blindsided by such a major change.
  3. I have no experience with these functions, so I'd be learning them on the fly.
  4. I don't have the time to devote to such an undertaking.

The first one, we can address by keeping one branch for 8.2+ compatibility and new features, and another for 7.3+ compatibility and bug fixes only.

The last two are ones perhaps you can help out with. I've been thinking about recruiting someone else to help out with maintaining NERDTree. Any interest?

PhilRunninger avatar Jan 31 '21 03:01 PhilRunninger

Sure, I can help. Maybe I could provide a proof-of-concept PR to illustrate the idea.

noscript avatar Feb 01 '21 13:02 noscript

@Xuyuanp, @ryanoasis, @tiagofumo,

I am looping you, as developers of major NERDTree plugins, into this discussion. The changes proposed here would very likely have a direct impact on your plugins. @noscript, as you work on your proof-of-concept, involve them in the design so there are no surprises. What are everyone's thoughts on keeping two versions of the plugins? I'm thinking the 7.3+ (legacy) version would get no new features, only bug fixes. And the 8.2+ version would have all the new bells and whistles, including what promises to be much easier syntax highlighting.

Thanks, Phil

PhilRunninger avatar Feb 08 '21 19:02 PhilRunninger