ford icon indicating copy to clipboard operation
ford copied to clipboard

Specify lexer for extra_filetypes

Open jacobwilliams opened this issue 8 years ago • 8 comments

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.

jacobwilliams avatar Mar 27 '17 01:03 jacobwilliams

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

cmacmackin avatar Mar 27 '17 09:03 cmacmackin

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.

jacobwilliams avatar Mar 27 '17 15:03 jacobwilliams

Note: I did a simple implementation of this approach here if you are interested.

jacobwilliams avatar Mar 28 '17 01:03 jacobwilliams

Thanks @jacobwilliams, I pulled in your implementation.

cmacmackin avatar Dec 30 '17 18:12 cmacmackin

It looks like the initial implementation will only work with the latest versions of Python. I'll need to change it in future.

cmacmackin avatar Jun 30 '18 13:06 cmacmackin

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.

jacobwilliams avatar Jul 01 '18 15:07 jacobwilliams

I'm thinking we should use the get_lexer_by_name() method, described here. It looks more robust and like it accepts simpler names.

cmacmackin avatar Jul 01 '18 15:07 cmacmackin

Yes that works great, and you use just use 'fortran' rather than 'FortranLexer': https://github.com/jacobwilliams/ford/commit/4ba9c62d3e31c9428e546e950383cf93638dd8e0

jacobwilliams avatar Jul 01 '18 17:07 jacobwilliams