kyx0r / nextvi

A small vi/ex terminal text editor (neatvi rewrite)
150 stars 14 forks source link

highlight rules for all filetypes #128

Open devank4000 opened 4 days ago

devank4000 commented 4 days ago

It would be nice to have a way to add highlight rules for all filetypes without copypasting the same rule for different filetypes. Would be especially useful for hll, hlw, hlp, trailing whitespaces and search keyword.

kyx0r commented 3 days ago

Hi, While the added benefit of not having to specify the hl for every ft sounds nice, it creates problems that can be overlooked.

  1. You lose ability to change the color based on filetype.
  2. The position within the rset is strategic and defines the highlighting order. You will lose that ability.
  3. Combining parts of ft is not supported, which means it has to be implemented = more lines of code.
  4. Not every filetype needs or will use the dynamic options since there are internal filetypes as well. Dealing with this is even more unneeded complexity for a questionable benefit.

The solution is to prefer simplicity over complexity. I suggest you to use C preprocessor instead to make the copy pasting a bit easier.

devank4000 commented 3 days ago

Here's there solution i tried -

#define FILETYPES \
    X("/") \
        ....
#define X(ft) \
    {ft, "([ \t]+)\n$", {0, SYN_BGMK(9)}}, \
        ....
FILETYPES
#undef X
#undef FILETYPES

However this ignores the other highlights

kyx0r commented 2 days ago

Your best bet is doing this

#define all(ft) \
        {ft, "([ \t]+)\n$", {0, SYN_BGMK(9)}}, \

And calling all("/") on every ft. Of course only do this if you have more than 1.