How to: test-driven design in Leo

2016-11-28 Thread Edward K. Ream
Using reload has made a big difference in my unit testing. I can run tests 
repeatedly in unitTest.leo, even after I have changed (in leoPy.leo) the 
code being tested.

This workflow about doubles my testing productivity.  True test-driven 
development is possible, here and now, in Leo.

The guidelines are simple:

1. @test nodes should use imp.reload(x) to reload all modules x affected by 
the tests.

2. @test nodes must create new instances of all classes being tested.

When creating a new @test node, cutting and pasting code from previous unit 
tests usually suffices. Fancy @button scripts that create preamble code are 
not required, but might be useful if you are creating lots of tests at once.

The rest of the post will explain these guidelines in more detail, using 
this example...

*Example*

Here is the beginning of @test elisp importer:

if 1: # Enable TDD
# The preamble...
g.cls()
if c.isChanged(): c.save()
# import leo
import leo.core.leoImport as leoImport
import leo.plugins.importers.linescanner as linescanner
import leo.plugins.importers.elisp
# Reload all.
import imp
imp.reload(leo.plugins.importers.linescanner)
imp.reload(leo.plugins.importers.elisp)
imp.reload(leoImport)
# instantiate the class
ic = leoImport.LeoImportCommands(c)
else: # Run the test in "production mode".
ic = c.importCommands
# run the test.
ic.elispUnitTest(p,s=s,showTree=True)

*Using imp reload*

As you can see, the test imports and reloads three modules. The test uses 
leoImport, so it too must be reloaded even thought leoImport.py doesn't 
change.

*Instantiating classes*

imp.reload is not enough. imp.reload doesn't change existing objects. You 
must create (instantiate) new objects to test.  This part of the example 
shows how:

if 1: # Enable TDD
# The preamble, not shown...
# instantiate the class
ic = leoImport.LeoImportCommands(c)
else: # Run the test in "production mode".
ic = c.importCommands
# run the test.
ic.elispUnitTest(p,s=s,showTree=True)

And that's all there is to it.  Creating the preamble as in the example is 
an investment that quickly pays off.  Give this kind of code a try.  You'll 
be glad you did.

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 leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.


Re: ENB: Big speedups and Aha's

2016-11-28 Thread Edward K. Ream
On Monday, November 28, 2016 at 10:54:48 AM UTC-6, Edward K. Ream wrote:

> Anyone who wants to understand the importers should read this post 
carefully...

> There probably are languages in which a pattern could match on a line 
*after* the close of a comment or string.

This got me thinking about the differences between line-oriented and 
character-oriented scanners.  There are surprisingly few.

*tl;dr:* Hehe.  Read the summary...

*Summary* 

- i.v2_gen_lines matches patterns *only *at the end of the previous line. 
This is a merely a useful *convenience*. Overrides (x.v2_gen_lines) could 
match patterns after every call to i.scan_dict.  This proves that *any* 
language can be handled correctly. 

- i.scan_dict (and i.scan_table) are character oriented. They are 
surprisingly similar to the scanning code in the old importers, except that 
they are faster and more elegant ;-)

- The new line-oriented api is the other reason (besides i.v2_gen_lines) 
that the new importers are line-oriented. The new importers only ever add 
whole lines to blocks. This eliminates *all *character-oriented fiddling, a 
huge simplification compared to the old importers.

EKR

-- 
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 leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.


Re: where re-define default color? [was] how to setup Leo cursor size and highlight currently line?

2016-11-28 Thread Zoom.Quiet
On Mon, Nov 28, 2016 at 2:38 PM, 'Terry Brown' via leo-editor
 wrote:
> Try these settings:
>
> @color undefined_section_name_color = orange
> @color section_name_brackets_color = orange
> @bool underline_undefined_section_names = False
>

thanks! them is working ;-) as atta. snap
i search them in the node: lThemes: copy to last top-level setting in
myLeoSettings.leo
because myLeoSettings.leo is hand upgrade from Leo 3.6
so many new config nodes not in the outline

maybe i need diff them all for know i really lost what.


> Cheers -Terry
>
> 
> From: Zoom.Quiet 
> To: leo-editor@googlegroups.com
> Sent: Monday, November 28, 2016 1:56 PM
> Subject: Re: where re-define default color? [was] how to setup Leo cursor
> size and highlight currently line?
>
> On Mon, Nov 28, 2016 at 1:49 PM, john lunzer  wrote:
>> Cursor size is as follows:
>>
>> create a node with headline:
>>
>> @int qt-cursor-width = 3
>>
>> under an @settings parent node. Obviously change 3 to however big you want
>> the cursor.
>>
>
> thanx for u suggest ;-)
> but i need to change the default color for  < and > of <> case
> because ,i custom the dark theme, the default color not clean enough.
>
>>

...

-- 
life is pathetic, go Pythonic! 人生苦短, Python当歌!
俺: http://zoomquiet.io
授: http://creativecommons.org/licenses/by-sa/2.5/cn/
怒: 冗余不做,日子甭过!备份不做,十恶不赦!
KM keep growing environment culture which promoting organization be learnning!

-- 
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 leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.


Re: where re-define default color? [was] how to setup Leo cursor size and highlight currently line?

2016-11-28 Thread 'Terry Brown' via leo-editor
Try these settings:
@color undefined_section_name_color = orange
@color section_name_brackets_color = orange
@bool underline_undefined_section_names = False

Cheers -Terry
 
  From: Zoom.Quiet 
 To: leo-editor@googlegroups.com 
 Sent: Monday, November 28, 2016 1:56 PM
 Subject: Re: where re-define default color? [was] how to setup Leo cursor size 
and highlight currently line?
   
On Mon, Nov 28, 2016 at 1:49 PM, john lunzer  wrote:
> Cursor size is as follows:
>
> create a node with headline:
>
> @int qt-cursor-width = 3
>
> under an @settings parent node. Obviously change 3 to however big you want
> the cursor.
>

thanx for u suggest ;-)
but i need to change the default color for  < and > of <> case
because ,i custom the dark theme, the default color not clean enough.

>
> As for highlighting the current line I do not know how this is done.
>
> On Sunday, November 27, 2016 at 6:25:07 PM UTC-5, Zoom.Quiet wrote:
>>
>> as atta. snap.
>> base john lunzer  suggest config:
>> ~/.leo/myLeoSettings.leo#@settings-->Syntax
>> coloring-->Language-specific colors-->Python
>>
>> reply-to: leo-e...@googlegroups.com
>> to: leo-editor 
>> date: Sat, Apr 16, 2016 at 4:19 AM
>> subject: Re: [theme] how to setup Leo cursor size and highlight currently
>> line?
>>
>> @color blank_color = grey
>> @color tab_color = red
>> @color label_color = red
>> ...
>>
>> i got pretty dark-theme in macOS, but like <>
>> the <<>> usage default color, not good enough,
>> but i can not found, where can re-define it...
>>
>> thanks for any suggest.
>>
>>
>> On Sat, Apr 16, 2016 at 11:33 AM, Edward K. Ream 
>> wrote:
>> >
>> >
>> > On Sat, Apr 16, 2016 at 11:20 AM, Zoom.Quiet  wrote:
>> >>
>> >> thanks again , and i sharing the custom story as:
>> >> Leo 5.2 theme custom — Medium
>> >>
>> >>
>> >> https://medium.com/@zoom.quiet/leo-5-2-theme-custom-d6f77573b7d6#.wvihrt11x
>> >
>> >
>> > Looks good :-)
>> >
>> > Edward
>>
>>
>> --
>> life is pathetic, go Pythonic! 人生苦短, Python当歌!
>> 俺: http://zoomquiet.io
>> 授: http://creativecommons.org/licenses/by-sa/2.5/cn/
>> 怒: 冗余不做,日子甭过!备份不做,十恶不赦!
>> KM keep growing environment culture which promoting organization be
>> learnning!
>
> --
> 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 leo-editor+unsubscr...@googlegroups.com.
> To post to this group, send email to leo-editor@googlegroups.com.
> Visit this group at https://groups.google.com/group/leo-editor.
> For more options, visit https://groups.google.com/d/optout.



-- 
life is pathetic, go Pythonic! 人生苦短, Python当歌!
俺: http://zoomquiet.io
授: http://creativecommons.org/licenses/by-sa/2.5/cn/
怒: 冗余不做,日子甭过!备份不做,十恶不赦!
KM keep growing environment culture which promoting organization be learnning!

-- 
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 leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

   
 

-- 
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 leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.


Re: where re-define default color? [was] how to setup Leo cursor size and highlight currently line?

2016-11-28 Thread Zoom.Quiet
On Mon, Nov 28, 2016 at 1:49 PM, john lunzer  wrote:
> Cursor size is as follows:
>
> create a node with headline:
>
> @int qt-cursor-width = 3
>
> under an @settings parent node. Obviously change 3 to however big you want
> the cursor.
>

thanx for u suggest ;-)
but i need to change the default color for  < and > of <> case
because ,i custom the dark theme, the default color not clean enough.

>
> As for highlighting the current line I do not know how this is done.
>
> On Sunday, November 27, 2016 at 6:25:07 PM UTC-5, Zoom.Quiet wrote:
>>
>> as atta. snap.
>> base john lunzer  suggest config:
>> ~/.leo/myLeoSettings.leo#@settings-->Syntax
>> coloring-->Language-specific colors-->Python
>>
>> reply-to: leo-e...@googlegroups.com
>> to: leo-editor 
>> date: Sat, Apr 16, 2016 at 4:19 AM
>> subject: Re: [theme] how to setup Leo cursor size and highlight currently
>> line?
>>
>> @color blank_color = grey
>> @color tab_color = red
>> @color label_color = red
>> ...
>>
>> i got pretty dark-theme in macOS, but like <>
>> the <<>> usage default color, not good enough,
>> but i can not found, where can re-define it...
>>
>> thanks for any suggest.
>>
>>
>> On Sat, Apr 16, 2016 at 11:33 AM, Edward K. Ream 
>> wrote:
>> >
>> >
>> > On Sat, Apr 16, 2016 at 11:20 AM, Zoom.Quiet  wrote:
>> >>
>> >> thanks again , and i sharing the custom story as:
>> >> Leo 5.2 theme custom — Medium
>> >>
>> >>
>> >> https://medium.com/@zoom.quiet/leo-5-2-theme-custom-d6f77573b7d6#.wvihrt11x
>> >
>> >
>> > Looks good :-)
>> >
>> > Edward
>>
>>
>> --
>> life is pathetic, go Pythonic! 人生苦短, Python当歌!
>> 俺: http://zoomquiet.io
>> 授: http://creativecommons.org/licenses/by-sa/2.5/cn/
>> 怒: 冗余不做,日子甭过!备份不做,十恶不赦!
>> KM keep growing environment culture which promoting organization be
>> learnning!
>
> --
> 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 leo-editor+unsubscr...@googlegroups.com.
> To post to this group, send email to leo-editor@googlegroups.com.
> Visit this group at https://groups.google.com/group/leo-editor.
> For more options, visit https://groups.google.com/d/optout.



-- 
life is pathetic, go Pythonic! 人生苦短, Python当歌!
俺: http://zoomquiet.io
授: http://creativecommons.org/licenses/by-sa/2.5/cn/
怒: 冗余不做,日子甭过!备份不做,十恶不赦!
KM keep growing environment culture which promoting organization be learnning!

-- 
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 leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.


Re: where re-define default color? [was] how to setup Leo cursor size and highlight currently line?

2016-11-28 Thread john lunzer
Cursor size is as follows:

create a node with headline:

@int qt-cursor-width = 3

under an @settings parent node. Obviously change 3 to however big you want 
the cursor.


As for highlighting the current line I do not know how this is done. 

On Sunday, November 27, 2016 at 6:25:07 PM UTC-5, Zoom.Quiet wrote:
>
> as atta. snap. 
> base john lunzer > suggest config: 
> ~/.leo/myLeoSettings.leo#@settings-->Syntax 
> coloring-->Language-specific colors-->Python 
>
> reply-to: leo-e...@googlegroups.com  
> to: leo-editor > 
> date: Sat, Apr 16, 2016 at 4:19 AM 
> subject: Re: [theme] how to setup Leo cursor size and highlight currently 
> line? 
>
> @color blank_color = grey 
> @color tab_color = red 
> @color label_color = red 
> ... 
>
> i got pretty dark-theme in macOS, but like <> 
> the <<>> usage default color, not good enough, 
> but i can not found, where can re-define it... 
>
> thanks for any suggest. 
>
>
> On Sat, Apr 16, 2016 at 11:33 AM, Edward K. Ream  > wrote: 
> > 
> > 
> > On Sat, Apr 16, 2016 at 11:20 AM, Zoom.Quiet  > wrote: 
> >> 
> >> thanks again , and i sharing the custom story as: 
> >> Leo 5.2 theme custom — Medium 
> >> 
> >> 
> https://medium.com/@zoom.quiet/leo-5-2-theme-custom-d6f77573b7d6#.wvihrt11x 
> > 
> > 
> > Looks good :-) 
> > 
> > Edward 
>
>
> -- 
> life is pathetic, go Pythonic! 人生苦短, Python当歌! 
> 俺: http://zoomquiet.io 
> 授: http://creativecommons.org/licenses/by-sa/2.5/cn/ 
> 怒: 冗余不做,日子甭过!备份不做,十恶不赦! 
> KM keep growing environment culture which promoting organization be 
> learnning! 
>

-- 
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 leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.


Re: Status report: the new importers have passed a major milestone

2016-11-28 Thread Edward K. Ream
On Sunday, November 20, 2016 at 3:23:47 AM UTC-6, Edward K. Ream wrote:

The new importers are nearly complete! The recent simplifications have been 
> a complete success. All the hard work is done.
>

Well, that was wishful thinking ;-) 8 intense days later, the to-do list is:

- 2 importers remain to be converted.
- Get i.scan_dict fully functional.
- Revise python.findClass, for head-to-prev-node and tail-to-next-node.

We are definitely nearer the end. Maybe 2-4 more days.

I'll be leaving for Florida sometime around December 9.  I'll have my 
computer with me, but I definitely want to complete the importer work well 
before then.

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 leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.


ENB: Big speedups and Aha's

2016-11-28 Thread Edward K. Ream
This is an Engineering Notebook post.  Feel free to ignore.

Otoh, anyone who wants to understand the importers should read this post 
carefully.

*tl;dr:* 

1. i.scan_dict should result in an 5x speed improvement over i.scan_table. 
Maybe more.

2. A clever trick, *discovered while writing this post*, makes it possible 
to scan comments and strings *quickly*, *without changing the line-oriented 
nature of the code*.

*The new code*

Rev 78413a4 contains the new code. It mostly works, but it is still 
disabled.

Up until now, the importers have used a table-driven scanner, *i.scan_table*.  
This scanner knows about *context*: strings, comments, etc. For *each* 
character of the input file, the present importer calls i.scan_table to 
update brackets and set the context.

i.scan_table tries to match each pattern of the table against the input 
character.  Most tables contain 8-10 entries.  Most input characters *fail* 
to match, so on average, 8-10 fairly complex comparisons are done for *each 
*character of the input file.

Instead, *i.scan_dict* looks up the incoming character in a *dictionary*. 
Most characters do *not* appear in the dict, so i.scan_dict fails 
immediately. So on average, i.scan_dict must be about 8x faster than 
i.scan_table.

*Aha: how to scan strings and comments*

For years I have been noodling whether there is some way to scan comments 
and strings *quickly* while using the line-oriented scanning code. We would 
naively expect that going into "string-scanning mode" would speed up the 
scan compared to calling i.scan_dict for every character.

But actually, it wouldn't help all that much now that i.scan_dict is so 
fast.  And furthermore, that would complicate x.v2_gen_lines.

The problem is this: if i.scan_dict scanned the comment or string 
completely, i.scan_dict might return an index *i* that is *past *the line 
that x.v2_gen_lines is handling.  Somehow, x.v2_gen_lines would have to 
re-sync to the next *complete* line. It could be done, but it's complex 
enough that I have been wary of that approach.

But as I was writing this post I suddenly saw a beautiful solution:

Aha: i.scan_dict doesn't need to scan strings and comments *completely*!
Just scan to the *end* of the present line, or the end of the string or 
comment,
whichever comes first.

This is so good.  It speeds up strings and comments almost as much as 
possible, without changing anything else. The line orientation of the 
importer remains exactly as it was.

This may be the way it is written in The Book.  i.scan_dict will do this 
soon.

*When can importer code ignore context?*

It's easy to get confused about this.  In fact, however, the principles are 
simple:

1. Importers that *only* count brackets, {}, (), and/or [], can 

*always ignore context.*The reason is simple: the scanner ignores brackets 
in strings, comments, etc., so those counts are *always* accurate.

2. Importers that use pattern matches to determine the start of classes, 
defs, etc., must avoid pattern matches within strings and comments.

That is, patterns should fail if the previous line ends in a context.

There probably are languages in which a pattern could match on a line 
*after* the close of a comment or string. (C comes to mind).  I'll deal 
with such pathologies only if someone files a bug report :-)



*Faux optimizations of the ScanState classes*I'm tempted to include all 
bracket counts, indentation levels, backslash/newline data into a single 
generic class. No need to create a dedicated class for each importer.  It 
might simplify the code.  

But no, it's just as likely to make it harder to understand.  It probably 
won't happen.

And we don't actually need to create a new ScanState instance for every 
line.  We could just swap the present/previous states when changing lines.

However, we would also have to remember to copy the present state when 
pushing it on the stack. Again, this looks like a dubious "improvement".  
Clarity, simplicity and robustness are likely more important than a bit 
less stress on the GC.

*Summary*

i.scan_dict is should speed up the import code by 5x or more.

i.scan_dict will soon scan to comments or strings up to the end of the 
present line. This trick will speed up the scan (a bit) without requiring 
changes to any other code.

More importantly, this trick proves that:

1. Dedicated, character-oriented string/comments scanners are not needed.
2. There is no need to entangle character-oriented code with line-oriented 
code.
3. The new Importer code is the simplest (and fastest!) code that could 
possibly work.

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 leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://gro