Syntax highlighting of automake files (Makefile.am)

Issue #995 resolved
fluzz created an issue

The "if" keyword is used in Makefile.am files to conditionally create Makefiles (see http://www.gnu.org/software/automake/manual/automake.html#Conditionals)

Currently, the "if" keyword is not recognized by the MakefileLexer, and thus an "err" token is generated (see http://pygments.org/demo/386955/)

So, please, could you add "if" in the keywords list of MakefileLexer ?

Thx for your great work !

Comments (4)

  1. Lev Lozhkin

    Here's a quick patch that will give the desired behavior. I went for clarity, although that made part of the regex redundant.

    diff -r 2ba9b53c87ee pygments/lexers/text.py
    --- a/pygments/lexers/text.py   Tue May 20 07:44:45 2014 -0700
    +++ b/pygments/lexers/text.py   Wed May 21 10:26:38 2014 -0700
    @@ -189,7 +189,9 @@
             # BSD Make
             r'\.\s*(include|undef|error|warning|if|else|elif|endif|for|endfor)|'
             # GNU Make
    -        r'\s*(ifeq|ifneq|ifdef|ifndef|else|endif|-?include|define|endef|:))(?=\s)')
    +        r'\s*(ifeq|ifneq|ifdef|ifndef|else|endif|-?include|define|endef|:)|'
    +        # GNU Automake
    +        r'\s*(if|else|endif))(?=\s)')
         r_comment = re.compile(r'^\s*@?#')
    
         def get_tokens_unprocessed(self, text):
    
  2. fluzz reporter

    I locally "hack-fixed" it by adding 'if' in GNU Make part of the regexp, just because I was wondering if redundancy would not have a bad impact on efficiency (I'm not at all a python expert, though).

    May I expect your patch to be commited for next release ?

    Thx.

  3. Log in to comment