Does @clean go too far?

75 views
Skip to first unread message

Geoff Evans

unread,
Aug 20, 2015, 7:00:45 AM8/20/15
to leo-editor
It seems to me that the file produced by an @clean node is not only clean
but sterile.  I quite agree that many of the sentinel lines are nothing
but a distraction for people; but not the ends of the node lines --
they are the headlines which you presumably chose to be meaningful,
and also the level of indentation in the outline.  For example the
following produced by @file

#@+leo-ver=5-thin
#@+node:gtevans.20150820072801.2: * @file classA.py
#@+others
#@+node:gtevans.20150820072837.1: ** Imports and magic
import mypackage
my_magic_number = 42
#@+node:gtevans.20150820072854.1: ** class definition
class A(object):
   #@+others
   #@+node:gtevans.20150820072948.1: *3* method 1
   def method1(self):
       pass
   #@+at
   # description of aims of method
   #@+node:gtevans.20150820073050.1: *3* method 2
   def method2(self):
       pass
   #@-others
#@-others
#@-leo

becomes, under @clean

import mypackage
my_magic_number = 42
class A(object):
   def method1(self):
       pass
   # description of aims of method
   def method2(self):
       pass

How much more informative if instead it could become something like

#*** Imports and magic
import mypackage
my_magic_number = 42
#*** class definition
class A(object):
   #*** *** method 1
   def method1(self):
       pass
   # description of aims of method
   #*** *** method 2
   def method2(self):
       pass


Would this be possible?  It would have the additional advantages of
making clear which method "description of aims of method" referred to,
and also resolve any ambiguity when the file is edited outside Leo with
new lines at a boundary between nodes.

Meanwhile, immense thanks (once more) for Leo and for the Leo commmunity.
It makes my professional life so much easier.

Cheers,   geoff evans

reinhard...@googlemail.com

unread,
Aug 21, 2015, 5:48:26 AM8/21/15
to leo-editor
How much more informative if instead it could become something like
#*** Imports and magic
import mypackage
my_magic_number = 42
#*** class definition
class A(object):
   #*** *** method 1
   def method1(self):
       pass
   # description of aims of method
   #*** *** method 2
   def method2(self):
       pass

What do you gain by such redundant comments?

Every Python programmer knows that 'class' is a class definition and 'def' (within a class) a method definition. The aims of a method should be expressed by its name. And for additional commentary information is ample room within the method itself.

Reinhard
 

john lunzer

unread,
Aug 21, 2015, 6:04:35 AM8/21/15
to leo-editor
I would be inclined to agree, it does look like redundant information. There would however be some benefit to some sort of delineation made between nodes, but I'm not proposing a new node type to do so. I think to be perfectly honest there will always be a struggle when editing a shared code base when using Leo and others are not using Leo. 

Edward has addressed this many times at many levels. Leo is already pretty smart with Python code for small edits.  I'm not certain there is a great answer other than adding in even MORE "intelligence" into Leo's algorithms which chop up the Python code into nodes. For example Leo could, but doesn't, create a new node(s) when a new method class or function definition is created. This seems odd given that Leo has the ability to chop things up initially. Seems like it wouldn't be a huge stretch to extend this behavior.

Geoff Evans

unread,
Aug 21, 2015, 9:20:46 AM8/21/15
to leo-editor
Okay, that python program was a bad example because the artificial headlines were redundant.  But there are many instances of outlines where the text in the headline is nothing like the text in the body pane.

The essence of what I wanted to say:

My intuition of a 'clean' file is one that reflects just what I typed.
What I typed includes the body panes *and* the outline pane (including its indentations).
@clean as implemented includes only the body panes.
  
"I am sorry I wrote you such a long letter; I didn't have time to write a short one."  -- Blaise Pascal

Edward K. Ream

unread,
Aug 21, 2015, 11:43:50 AM8/21/15
to leo-editor
On Thu, Aug 20, 2015 at 6:00 AM, Geoff Evans <gtev...@nl.rogers.com> wrote:
It seems to me that the file produced by an @clean node is not only clean
but sterile.

​There was a suggestion for @nosent files to generate sentinels corresponding to​
 
​headlines.

In principle, this could be done with @clean or @shadow, as discussed briefly recently.  Not sure whether this can be done easily enough to be worth doing.  It's not something that would add a great deal to Leo in any case: if you are using Leo the sentinels don't matter.

Edward

Terry Brown

unread,
Aug 21, 2015, 2:19:50 PM8/21/15
to leo-e...@googlegroups.com
On Fri, 21 Aug 2015 10:43:49 -0500
"Edward K. Ream" <edre...@gmail.com> wrote:

> On Thu, Aug 20, 2015 at 6:00 AM, Geoff Evans <gtev...@nl.rogers.com>
> wrote:
>
> > It seems to me that the file produced by an @clean node is not only
> > clean but sterile.
> >
>
> ​There was a suggestion for @nosent files to generate sentinels
> corresponding to​
>
> ​headlines.
>
> In principle, this could be done with @clean or @shadow, as discussed
> briefly recently.

There are also the @auto-<specialization> importer / exporters.

E.g. .../leo/plugins/importers/ctext.py

Just now it seems there might be a regression there, it's failing with

Traceback (most recent call last):
File "/mnt/usr1/usr1/home/tbrown/t/Package/leo/git/leo-editor/leo/core/leoAtFile.py", line 3298, in writer_for_at_auto_cb
return aClass(at.c).write(root, forceSentinels=forceSentinels)
TypeError: write() got an unexpected keyword argument 'forceSentinels'

which I didn't immediately find (i.e. didn't find the
offending .write() yet.).

But @auto-ctext is an example of basically a "headline" driven tree
importer / exporter.

Cheers -Terry

Edward K. Ream

unread,
Aug 22, 2015, 8:31:52 AM8/22/15
to leo-editor
On Fri, Aug 21, 2015 at 1:19 PM, 'Terry Brown' via leo-editor <leo-e...@googlegroups.com> wrote:
On Fri, 21 Aug 2015 10:43:49 -0500
"Edward K. Ream" <edre...@gmail.com> wrote:

There are also the @auto-<specialization> importer / exporters.

E.g. .../leo/plugins/importers/ctext.py

Just now it seems there might be a regression there, it's failing with

Traceback (most recent call last):
  File "/mnt/usr1/usr1/home/tbrown/t/Package/leo/git/leo-editor/leo/core/leoAtFile.py", line 3298, in writer_for_at_auto_cb
    return aClass(at.c).write(root, forceSentinels=forceSentinels)
TypeError: write() got an unexpected keyword argument 'forceSentinels'

which I didn't immediately find (i.e. didn't find the
offending .write() yet.).

​The offending write is CTextWriter.write.  It must have a forceSentinels keyword argument.  I didn't update this method because I didn't know writers/ctext.py existed until just now.

Terry, please update LeoPluginsRef.leo by adding @file writers/ctext.py. 

Support the forceSentinels argument as you like, using the others writers as a guide.

Edward

Geoff Evans

unread,
Aug 24, 2015, 5:56:16 AM8/24/15
to leo-editor
Thanks, all, for your thoughts (and sorry I couldn't respond over the weekend)
 
1)  I agree it's not a big issue.  As Edward writes: "It's not something that would add a great deal to Leo in any case: if you are using Leo the sentinels don't matter."  Though the same could be said for @clean istelf.  The point would be to add something to extra-Leo use, which includes not only colleagues who won't use Leo but also the modes of my brain that are switched on by working with and on paper.
 
2)  Perhaps the strongest case would be for outlines that make heavy use of Organizer nodes with no text in the body pane:  @clean will remove all evidence they existed.
 
3)  A solution is in my own hands:  Copy what I want from the headline to the top of the body node.  This may be my impetus to learn enough about scripting to automate that :-)   And I should study Terry's suggestion.
 
Cheers,  geoff
 
 

john lunzer

unread,
Aug 24, 2015, 6:47:50 AM8/24/15
to leo-editor
On Monday, August 24, 2015 at 5:56:16 AM UTC-4, Geoff Evans wrote:
3)  A solution is in my own hands:  Copy what I want from the headline to the top of the body node.  This may be my impetus to learn enough about scripting to automate that :-)   And I should study Terry's suggestion.
 
Cheers,  geoff

Abbreviations would  probably be the easiest way to do this without using "scripting". Here is the relevant abbreviation: 
hl;;={|{x=c.p.h}|}

I use this one all the time. 

Edward K. Ream

unread,
Aug 24, 2015, 10:28:34 AM8/24/15
to leo-editor
On Mon, Aug 24, 2015 at 4:56 AM, Geoff Evans <gtev...@nl.rogers.com> wrote:
if you are using Leo the sentinels don't matter."  Though the same could be said for @clean i
​ts​
elf. 

​Let's not confuse things.  @clean is super important because it allows the Leo user to get most of the benefits of @file without sentinels.  The only drawback of @clean is dealing with updates made outside of Leo.  But @clean preserves organizer nodes, etc., when using Leo.

If you want to add headline-like comments in body text when using @clean, then by all means do so.  You would be following standard programming practice. @clean does not need to change to allow this.

Yes, such comments might be redundant to the headlines, but so what?

Edward

Edward K. Ream

unread,
Aug 24, 2015, 10:28:34 AM8/24/15
to leo-editor
Reply all
Reply to author
Forward
0 new messages