ford
ford copied to clipboard
Specify lexer for extra_filetypes
I'm using the .inc extension for include files (and the extra_filetypes option to include these in the documentation). However, I guess Pygments interprets this as some other kind of file and is highlighting it weird. It would be nice to somehow specify the lexer to use for these files, maybe as another option in the declaration, so:
extra_filetypes: inc ! ABC
where ABC is whatever info Pygments needs to treat it as Fortran.
I'll look at incorporating this into the next release.
On 27/03/17 02:42, Jacob Williams wrote:
I'm using the |.inc| extension for include files (and the |extra_filetypes| option to include these in the documentation). However, I guess Pygments interprets this as some other kind of file and is highlighting it weird. It would be nice to somehow specify the lexer to use for these files, maybe as another option in the declaration, so:
|extra_filetypes: inc ! ABC |
where |ABC| is whatever info Pygments needs to treat it as Fortran.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cmacmackin/ford/issues/203, or mute the thread https://github.com/notifications/unsubscribe-auth/AHxJPQFXZ57boi2vNumRUbOq-5s76gP-ks5rpxQLgaJpZM4MpsoJ.
-- Chris MacMackin cmacmackin.github.io https://cmacmackin.github.io
It could be something easy like:
extra_filetypes: inc ! FortranLexer
(i.e. specify the lexer name from pygments.lexers), then we can just update L2065 in sourceform.py to call that one instead of guessing it using the extension.
Note: I did a simple implementation of this approach here if you are interested.
Thanks @jacobwilliams, I pulled in your implementation.
It looks like the initial implementation will only work with the latest versions of Python. I'll need to change it in future.
FYI: For some reason, it doesn't work for me anymore. Maybe they changed something in pygments? This fixes it for me at least: https://github.com/jacobwilliams/ford/commit/0dce0abed905e20ddcee533d52cf6bb0a71c6f3f
But i'm using Python 3.6.4, so I don't know about earlier versions.
Note: this requires this syntax: extra_filetypes: inc # FortranLexer. The fortran.FortranLexer syntax doesn't seem to work for me.
I'm thinking we should use the get_lexer_by_name() method, described here. It looks more robust and like it accepts simpler names.
Yes that works great, and you use just use 'fortran' rather than 'FortranLexer': https://github.com/jacobwilliams/ford/commit/4ba9c62d3e31c9428e546e950383cf93638dd8e0