Git Product home page Git Product logo

Comments (5)

kyx0r avatar kyx0r commented on August 28, 2024

Hi Cedric,
It's hard for me to understand what you want to achieve exactly, but try messing around with hll
definition in conf.c

change the continuation bit from
{"tex", NULL, {14 | SYN_BD}, {1}, 0, 2},
to
{"tex", NULL, {14 | SYN_BD}, {0}, 0, 2},

is that what you want to achieve?
As far as I can tell everything in nextvi works correctly regarding syntax hl. If you want some very
complex special behavior for hll, you can create a special ft type for it, swap ft at runtime do what you want and swap back to original default ft. Nextvi has the means to do all that.

from nextvi.

Vouivre avatar Vouivre commented on August 28, 2024

I'll try to explain it better: I want to use the the syntax highlighting, in particular the ex features hlp, hll and hlw for tex files. Those features works perfectly fine for c files, for example if I use them on vi.c but not for tex files. Usual syntax highlighting works for tex files, but not hll, hlp or hlw. With your change, I was able to get hll working as expected for a tex file.

Could you briefly summarize what is this continuation bit ?

from nextvi.

kyx0r avatar kyx0r commented on August 28, 2024

Continuation byte defines where syntax highlight continues in a case of a match for a corresponding group.
In BRE, a group is any regular expression that gets captured inside ()
Possible values for continuation are 0, 1, -1 as described in vi.h L316 read it first as I am going to
explain what happens with hll below.

The pattern for hll is "^.+$" (actually the $ isn't needed anymore I should remove it later)
This pattern does not have any capturing groups except the implicit capturing group granted to
all entries in conf.c by rset_make(). The implicit group creates the separation needed between the
regular expressions, that's how it knows what matched what. Therefore end[0] byte is the only
corresponding byte that has a meaning full effect on entry {"tex", NULL, {14 | SYN_BD}, {0}, 0, 2},

When "^.+" matches the whole line, the code in syn_hilight() will check the continuation options
for this set. ( {"tex", NULL, {14 | SYN_BD}, {0}, 0, 2} is considered a set. so for instance the "tex" ft currently
has 5 sets like this in conf.c) When the set and some corresponding group in the set matches it's corresponding
continuation option is read. When it reads 1, like it currently is set by default, instead of terminating and calling it
"i've matched the whole line, no chars left, done." it would try to dig deeper and find more possible matches, the ones
other than whole line. It can do that because of the ^ anchor, which is why change 62. is so important. The ^ anchor ensures
that the regex won't simply say "hey just match the whole line again" every time string gets advanced by 1 when we
try to dig in deeper into the string.

The brother anchor $ can also have this property, though there isn't really any tangible use case for it in nextvi other than
to try and continue past the '\n' which can happen when using keybind R for example. But this is rather rare use, I did not code
nextvi to take advantage of $.

So what you did there when changing 1 to 0, is basically telling nextvi to be lazy and just go with the first thing that matches.
Which is totally fine if that's the result you wanted.

Generally these are the things to consider when determining how things get highlighted:

  1. continuation options
  2. order of the set, the topmost take priority

There are a few implications, when you remove the continuation byte from hll that means nothing else will be able to highlight
the line, due to posix submatch rule longest match first.
So it is possible to come up with a combination of syntax rules where a very special order is required and it can't be achieved using the default options. In that case you have the option to write C code that will dynamically construct appropriate regex and adjust pattern when needed based on some conditions you define in code, usually this operation is cheap enough to be viable. If I optimize re_comp and factor out the recursion it would be even more viable than ever.

Dammit, that was way longer than briefly, i'd call it breezily instead, ha.

from nextvi.

kyx0r avatar kyx0r commented on August 28, 2024

Btw, Cedric, I don't use latex so I am not very familiar with whatever syntax it has. If you want to add something to it, like a more sensible default thing feel free to do so. I mean anything if you wanna add new programming language or whatevs I don't really mind you doing so. Adding stuff to conf does not really incur any meaningful performance loss, or some bad memory usage (though it does create a few dead static bytes) it's fine.

If you think having 0 there instead of 1 is better default for tex I guess you know better than me.

If you want hlp working for tex, gotta copy that set defined in c set with ->func set to 3

from nextvi.

Vouivre avatar Vouivre commented on August 28, 2024

Thank you very much for this loooonnnnnggg and detailed explanation! I appreciate it a lot and ...... I feel embarassed that you took so much time!

Thank you!

from nextvi.

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.