67455Re: [patch] Add a 'modifier' keyword to the :syntax commands, allowing syntax matches to stack.
- Dec 5, 2012On Wednesday, December 5, 2012 12:03:31 PM UTC-6, So8res wrote:
> I'm a bit stuck on how synID* should work in this context.I don't understand. synIDattr(synID(...),"name") on foo returns "Foo". synIDattr(synIDtrans(synID(...)),"name") on foo returns "Comment". Can't we just add something like synIDattr(synID(...),"combine") which returns true/false? Determining the highlight would then be a matter of going up the syntax stack until a non-combining item is found, then walking back up the stack getting the attributes for the translated syntax ID of each item.
> The problem is that synID() returns the id of the *highlight group*, not the syntax match. In the following example:
> syntax match Foo 'foo' combine
> syntax match Bar 'bar'
> highlight link Foo Comment
> highlight link Bar Comment
> if you have the highlight id for 'Comment', I can't reliably tell you whether or not it's going to combine with attributes further up the stack.
That said, doing all that in vimscript would probably be quite inefficient. The TOHtml implementation even has a comment on the loop that finds all characters in a particular highlight group, that the loop needs to be kept small. A traversal up and down the syntax stack for every character in the document would be a very bad thing. Doing the same thing for every entire highlighted item found would also probably not be very good. So I think we want a new set of functions to help out.
> The best I can think to do is one of:What would these do?
> 1. Add synmatchID() and synmatchIDattr()
> 2. Add syncombines(line, col) which tells you if you also need to consult the rest of the synstack() for attributes.This could work but would likewise affect the performance of a tight inner loop requiring "if" logic and a vimscript stack traversal on each character.
Syntax highlighting internally uses a unique number for each individually highlighted item. What if we add a function to return this number (synconcealed() already returns it as one item in a list for different reasons), and another function to get a list of syntax IDs which apply to an item's highlighting (in order of application), given this item number?
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
- << Previous post in topic Next post in topic >>