Here is an @file that I just made.  Yes, the << ... >>  sentinal is inside 
the quoted string.  But I don't mind that as long as 1) Python sees the 
correct code, and 2) Leo can read the file and reproduce it. And that is 
currently the case, except that Leo may move one or the other of the triple 
quotes to its own line during a round trip, and that would be fine too.

Why am I interested in this?  Mostly because PEP 8, the Python style guide, 
wants docstrings to start right after the triple quotes on the same line.  
I agree with this so I'd like to be possible.  PEP8 also wants the ending 
triple quotes to be on the same line if the docstring is a single line, but 
you wouldn't be using a section reference for a short docstring anyway.

Of course, one could also put the triple quotes inside the section itself.  
I'm not sure how that works if the docstring section itself is a tree of 
nodes, but it probably does.  You tend to get that kind of long, segmented 
docstring when the docstring is used directly for an About or Help display, 
as they are for Leo plugins.

#@+leo-ver=5-thin
#@+node:tom.20211105130433.1: * @file c:\temp\section_quotes.py
#@@language python
"""
#@+<< docstring >>
#@+node:tom.20211105130454.1: ** << docstring >>
This represents a long 
doctring section.
#@-<< docstring >>
#@afterref
"""

# Code here
def f(x):
    return x**2
#@-leo

On Friday, November 5, 2021 at 11:29:38 AM UTC-4 Edward K. Ream wrote:

> On Fri, Nov 5, 2021 at 8:42 AM [email protected] <[email protected]> 
> wrote:
>
>> I do like to write """<< quotation-section >>""" or even single quoted "<< 
>> quotation-section >>".  Not crucial, but perhaps the test could be for 
>> whitespace + quotes?
>
>
> I really do not want to do this.  It would complicate the code (even one 
> 'if' is too many), and imo it is mostly useless.  Indeed, given the 
> reference:
>
> """<< quotation-section >>"""
>
> And the corresponding definition node containing:
>
> line 1
> line 2
> line 3 
> the output is:
>
> """
> #@+<< quotation-section >>
> #@+node:ekr.20211105101807.1: ** << quotation-section >>
> line 1
> line 2
> line 3
> #@-<< quotation-section >>
> #@afterref
> """
>
> How can this possibly be what you want? There are Leo sentinel comments 
> inside the triple-quoted string!
>
> There is an straightforward alternative, which Leo's unit tests use 
> frequently.  Define the contents of << quotation-section 2 >> this way:
>
> a_var = textwrap.dedent('''\
>     line 1
>     line 2
>     line 3
> ''')
>
> This is straightforward, and the generated code is:
>
> #@+<< quotation-section 2 >>
> #@+node:ekr.20211105102445.1: ** << quotation-section 2 >>
> a_var = textwrap.dedent('''\
> line 1
> line 2
> line 3
> ''')
> #@-<< quotation-section 2 >>
>
> Now the triple-quoted string contains only the expected lines!
>
> Edward
>

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/13beeff4-08ce-48d9-88c6-c35c19fb062fn%40googlegroups.com.

Reply via email to