text-highlight file extensions
-
I’m trying to highlight file extensions, e.g.
./data/layers_elevations/L5.ascI tried a keyword list, but adding asc doesn’t do it, likely because it’s not a separate word, but part of a string.
I tried a delimiter as well:
open . | close ((EOL))
which- didn’t just highlight the extension but the entire line (since it starts with a ‘current folder’ period) - I could live with that.
- highlighted the period and decimals in numbers which overwrote the number highlighting that I had already set
is there a way to achieve that?
thanks, Chris
-
@criga76 said in text-highlight file extensions:
is there a way to achieve that?
There’s not a built-in way using User Defined Language (UDL) alone, because it doesn’t accept regular expressions. However, you can add extra highlighting to a UDL using regexes via the PythonScript plugin in conjunction with the script
EnhanceAnyLexer.py
that @Ekopalypse shares in his github repo – doing an expression liker'\.[a-zA-Z]\w*'
should look for a dot, followed by a letter, followed by one or more word characters (by doing the letter first, that guarantees it won’t find the decimal parts of numbers when looking for extensions, though it is technically possible for extensions to be.123
) -
Thanks @peterjones
RegExes would be handy addition, but I’ll try your suggested for now.
Chris -
I tried a keyword list, but adding asc doesn’t do it, likely because it’s not a separate word, but part of a string.
An undocumented fact about the “Operators 1” group is that word characters work just fine, and you can cluster them as if they were keywords [^1], so maybe something like this would suit your use case:
<Keywords name="Operators1">. asc bin txt <!-- more extensions --> </Keywords>
[^1]: I’m purposely contradicting Ivan Radić in his own UDL docs regarding operators:
In short: [“Operators 1” elements] should be special non-alphanumeric characters
Whereas,
Operators2 group is just another keyword group, Keyword group 9 if you will.
The distinction is not actually enforced by LexUser, a useful bug that allowed me, for example, to design a Vim script UDL that highlights variable scope prefixes:
g:
,s:
, etc., by (ab)using Operators1 elements: -
@rdipardo
from everything I’ve tried, it messes with number highlighting as they share the period with file extension :-( -
It might work better if you prefix every extension with a dot (and get rid of the free-standing dot):
<Keywords name="Operators1">.txt .asc .bin</Keywords>
That seems to force an exact match: