Associate additional extension with existing lexer

108 Views Asked by At

Is there an easy way to add a filename and/or extension for existing lexer in pygments? I don't want to write or subclass existing one, as the language is the same, but the file has different extension/name.

I've tried to hack it and add it to the filenames class variable (somewhere in /usr/lib/python2.7/dist-packages/pygments/lexers/agile.py), but for some reason it didn't worked.

I was wondering for something like .pygments file, where users can associate additional names with the lexers, but looks like it's not possible right now.

What is the best way to achieve my goal then?

1

There are 1 best solutions below

0
On

Okay, I've found solution: after adding filenames/extensions to required Lexer you have to regenerate the mapping:

cd /usr/lib/python2.7/dist-packages/pygments/lexers/; sudo python _mapping.py; cd -

This is not 100% clean solution, as in case of package update your changes will gone, but it pretty quick and easy.