[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Nano-devel] python syntax highlighting
From: |
John M. Gabriele |
Subject: |
Re: [Nano-devel] python syntax highlighting |
Date: |
Thu, 23 Feb 2006 12:29:58 -0800 |
> John M. Gabriele wrote:
> > I've got a python file which isn't getting syntax-highlighted
> > (syntax-highlit? ;) correctly.
> >
> > The patterns I'm using I've found in various places on the net:
> >
> > syntax "python" "\.py$"
> > color brightblue "def [a-zA-Z_0-9]+"
> > color brightcyan
>
"\<(and|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|map|not|or|pass|print|raise|return|try|while)\>"
> > color brightgreen "([\"']).*?[^\\]\1"
> > color brightgreen start="\"\"\"" end="\"\"\""
> > color brightred "#.*$"
> >
> > and it breaks on any file with a """triple-quoted string"""
> > as soon as it sees those first three double quote marks.
> >
> > If they're '''triple-quoted like this''' everything is ok, but
> > I don't get the syntax highlighting over multiple lines.
> >
> > If I remove that offending line from the .nanorc, then
> > both forms of multi-line strings (when used over multiple
> > lines) don't syntax highlight. (single-line triple-quoted
> > strings *do* syntax highlight correctly).
> >
> > Anyone have any better Python regex patterns?
>
> Part of the problem with the above is that the double quotes don't need
> to be backslash-escaped. I don't do any Python programming, so I'm not
> entirely sure how to improve these, but I've made an attempt (note that
> it'll only work with nano 1.3.x because of the "icolor" directive):
>
> syntax "python" "\.py$"
> icolor brightblue "def [A-Z_0-9]+"
> color brightcyan
>
"\<(and|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|map|not|or|pass|print|raise|return|try|while)\>"
> color brightgreen "(["']).*[^\\]\1"
> color brightgreen start="("""|''')" end="("""|''')"
> color brightred "#.*$"
>
Thanks. I see you changed
color brightgreen "([\"']).*?[^\\]\1"
to
color brightgreen "(["']).*[^\\]\1"
which seems to work fine, even though it ends up not quite
nanorc syntax highlighted (highlit? :) in my .nanorc.
That triple-quote line:
color brightgreen start="("""|''')" end="("""|''')"
doesn't work though.
When I type ''' or """ in my Python code, everything in the file
before that triple-quote (up to the top of the buffer) gets syntax
highlighted to that one solid color of brightgreen.
Thanks,
---J