nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nano-devel] python syntax highlighting


From: David Lawrence Ramsey
Subject: Re: [Nano-devel] python syntax highlighting
Date: Thu, 23 Feb 2006 15:17:57 -0500
User-agent: Thunderbird 1.5 (X11/20051201)

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 "#.*$"





reply via email to

[Prev in Thread] Current Thread [Next in Thread]