1. Georg Brandl
  2. pygments-main
  3. Issues
Issue #816 new

Lexer for CMakeLists.txt is guessed incorrectly

Simon Knopp
created an issue

Files named CMakeLists.txt are correctly assigned a CMakeLexer if you use get_lexer_for_filename. They are incorrectly assigned a TextLexer if you use guess_lexer_for_filename.

In [2]: guess_lexer_for_filename('CMakeLists.txt','')
Out[2]: <pygments.lexers.TextLexer>

In [3]: get_lexer_for_filename('CMakeLists.txt')
Out[3]: <pygments.lexers.CMakeLexer>

Given CMakeLists.txt is a more specific name than *.txt it seems to me that both functions should return a CMakeLexer.

Comments (8)

  1. Gaurav Jain

    Neither of the lexers have a analyse_text method. I think the solution would require a 'bonus' score for explicit filename pattern matches as done in get_lexer_for_filename

  2. Simon Knopp reporter

    Hmm sorry, looking at the code you're right. I was going by the docs at pygments.org which don't mention a second parameter. That's odd, because get_... was changed to accept that optional parameter in 2009 (#355).

  3. Log in to comment