nano-devel
[Top][All Lists]
Advanced

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

Re: [Nano-devel] triple quoted strings


From: Benno Schulenberg
Subject: Re: [Nano-devel] triple quoted strings
Date: Tue, 17 Jun 2014 11:58:29 +0200

On Tue, Jun 17, 2014, at 4:48, Mike Frysinger wrote:
> i run into it most when the docstring is using % expansion:
> 
> def foo():
>       s = """blah blah %(here)s
> foo foo""" % {'here': 'cow'}
> 
> the regex looks for """$, and since this """ isn't at the end of the line, it 
> never turns off :(

No, the regex for end doesn't look for $.  The above example in a file
by itself is coloured perfectly fine.  Problems occur when there are
other triple-quoted strings earlier or later in the file.

Paste the below into an empty buffer and save it as mike.py:

  """before"""

  def foo():
        s = """blah blah %(here)s
  foo foo""" % {'here': 'cow'}

  """after"""

When you paste it, everything will be coloured, because nano will
think that the very first """ is the start and the very last the end.

But when you reopen the file, the precalc_multicolorinfo() will
pair the triple quotes correctly, and if the rest of the code were
correct, things would be coloured fine.  However, as each line is
drawn, nano makes some mistake and looks backward and forward
when instead it should trust the precalculated stuff.

You see, when you reopen the above file, the 'def foo()' is coloured
fine, but the 's =' is mistakenly coloured green.  How could that be?
If it really thinks that that """ is an end of string, then 'blah blah'
should not be green.  And if it thinks it is a start, then 's =' should
not be green.  Somehow, when nano draws the line, it decides that the
""" is both an end *and* a start because it sees a """ before it and
also after it.

When you kill the line with """before""", the 's =' gets coloured
correctly.  And when you then kill  """after""", the line with
'foo foo' also is coloured right.  But when in large file with many
triple-quoted strings you kill some line, nano loses its marbles
and colours everything green.

Benno

-- 
http://www.fastmail.fm - Or how I learned to stop worrying and
                          love email again




reply via email to

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