Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get lines with highlights similar to textprops #5101

Open
varingst opened this issue Oct 21, 2019 · 1 comment
Open

Get lines with highlights similar to textprops #5101

varingst opened this issue Oct 21, 2019 · 1 comment

Comments

@varingst
Copy link

I was playing with popups and textprops the other day, and made a plugin that popups the function name when on/after typing the closing paren, if the function name is not visible on screen:

+ l:col_offset : v })█ map(

I used textprops to highlight the function name in the popup as it is highlighted in the buffer, by calling synID() on every char and parsing it to an object like

{ 'text': 'Foo(', 'props': [
  { 'highlight': 'VimFuncName', 'id': 265, 'col': 7, 'end_col': 11, 'string': 'Foo' },
  { 'highlight': 'VimParenSep', 'id': 316, 'col': 11, 'end_col': 12, 'string': '(' },
]}

Following that I translate the syntax IDs, create any missing text property types for them with prop_type_add(), offset the column start/end values, and pass the object to popup_atcursor()

That might seem like overkill for that particular use, but I have some additional ideas where I'd like to parse and reproduce the syntax highlighting. Think things similar to the output of g/{pat}/p, :changes, :jumps, etc.

A clear and concise description of what is hard to do.

Resolving the syntax stack for every char in a line seems not only awkward, but expensive compared to constructing an object for a line/range of lines in one pass from vim's internal representations.

Describe the solution you'd like

A classic highlighting equivalent of prop_list()

A function syngetline() that returns an object similar to the one above, facilitating classic highlighting to textprops conversion.

@andymass
Copy link

Note that getting syntax for every character in the forward direction is quite fast. Random access is very slow.

What is the benefit of this request? The function would be equally slow to using synid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants