Lexer for CMakeLists.txt is guessed incorrectly

Issue #816 new
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. Tim Hatch
    • changed milestone to 1.61

    Let's look at this for 1.61. I suspect it's because CMakeLexer doesn't have an analyse_text method.

  2. 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

  3. Gaurav Jain

    What is supposed to be the difference between guess_lexer_for_filename and get_lexer_for_filename? Both take a filename and code to analyse.

  4. Gaurav Jain

    get_lexer_for_filename seems to take an optional second parameter that can be the text to analyse

  5. 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).

  6. Log in to comment