Improving Leo using pyzo code

76 views
Skip to first unread message

Edward K. Ream

unread,
Jan 7, 2017, 8:21:19 AM1/7/17
to leo-e...@googlegroups.com
Good Artists Copy; Great Artists Steal--unknown/various

tl;dr: pyzo is the work of a programming genius.  I'll use that genius to improve Leo.

Pyzo contains absolutely brilliant code that I shall be "borrowing" freely.  The pyzo code is covered by the new BSD license, so that will have to be reflected in various places.  No big deal.

After studying pyzo briefly, four or five areas for improving Leo present themselves:

ipython integration

pyzo defines and uses the yoton client/server library.  Leo will likely use yoton just like pyzo does. This will be a major project, but imo it is the future of Leo. It will make Leo a first-class IPython/Jupyter editor, just as pyzo is. This project should reduce or eliminate the need for Leo's IPython bridge.

syntax coloring

pyzo's syntax coloring looks to be more than 10x faster than Leo's.  And it's so much simpler. Leo simply must use this scheme.  It will take considerable adapter code.

In particular, pyzo uses brilliantly simple token-based parsers to guide syntax coloring. These parsers use regex's to generate tokens.  At present, pyzo can only colorize python and c. Leo will have to generate regex's for each language using files in leo/modes.

This project is worth any amount of work. It should allow us to remove the odious "big text" buttons.

autocompletion

pyzo's autocompletion is simpler, faster and just plain better than Leo's. I'm not sure yet whether it depends on ipython, but I'll use as much of the pyzo code as possible.

key handling

Parts of Leo's key handling code are scandalously complex.  The pyzo code is much simpler.  I'll check whether the front end of Leo's key handling code can be simplified using the pyzo code as a model.

Tree handling

pyzo's tree handling code is super simple, but that's because the pyzo code doesn't need to do much. In particular, the pyzo code need only respond to mouse clicks and standard keys--it doesn't have to deal with events generated by custom keys or python scripts.  Still, the code will be worth a close look, to see if Leo's code could be improved.

Edward

Edward K. Ream

unread,
Jan 8, 2017, 10:15:29 AM1/8/17
to leo-editor
On Saturday, January 7, 2017 at 8:21:19 AM UTC-5, Edward K. Ream wrote:

> pyzo is the work of a programming genius.  I'll use that genius to improve Leo.

The leo/external/pyzo folder now contains copies of the pyzo code pertaining to syntax coloring. I had to repackage some things.  Originally, importing any pyzo file started pyzo itself!  The culprit was pyzo/__init__.py. Overall, the changes are minor.

Some test code (not pushed yet) defines a wrapper class that integrates the pyzo code into Leo's existing colorizing scheme. The code now appears to work, except that everything is colored black.  That's actually a nit ;-)

This is exciting. Among other things, the default colors are (will be) solarized colors!  The code works directly on QTextEdit widgets, so it should work as is with the LeoQTextBrowser class that holds Leo's body pane.

There is lots of interesting and useful code in pyzo.   Pyzo can change margins, handle auto-completion, paren matching, etc.  And Pyzo integrates that code with QTextEdit directly, unlike Leo's existing code where the various wrapper classes get in the way.

So Pyzo code should indeed simplify major parts of Leo.  For now, I'll focus on syntax coloring.  If that can be made to work I'll leave other improvements on the back burner.  Integration with IPython and Jupyter seems like a higher priority.  But long term, Pyzo points the way to much better editor code for Leo.

Edward

john lunzer

unread,
Jan 8, 2017, 3:17:59 PM1/8/17
to leo-editor
So awesome that you made this discovery, I've wanted to try Pyzo out for some time now. You may be aware that the author of Pyzo is also the author of Flexx. It's great to see great artists getting inspiration from other great artists. Can't wait to see what comes of these developments. The syntax highlighting speed is one of the last big warts, would love to see it lopped off.

john lunzer

unread,
Jan 8, 2017, 3:33:20 PM1/8/17
to leo-editor
Just had to post again after reading the other recent post with Offray. Everything you talked about integration into Leo will be amazing. Full IPython/Jupyter integration will super charge Leo. If all of Leo's internals are exposed via a fully integrated IPython kernel the interactivity of Leo will be astounding.

Very excited Edward.

Satish Goda

unread,
Jan 9, 2017, 5:29:12 AM1/9/17
to leo-editor
Hello Edward.

Really nice to see that you are moving forward with this. I am very happy and glad that I referred Pyzo, although I was a bit reluctant to mention it with the assumption that it would disrupt the Leo/PlantUml discussion.

One use case in Pyzo that I really used a lot in my previous movie project was the multiple interpreters feature in Pyzo. After looking at Leo, Leo could support multiple interpreters in the same session be defining them across two trees in the same outline. The Top level could define the interpreter settings etc and nodes below that could be cells.

Edward K. Ream

unread,
Jan 11, 2017, 6:43:44 AM1/11/17
to leo-editor
On Sun, Jan 8, 2017 at 3:17 PM, john lunzer <lun...@gmail.com> wrote:
So awesome that you made this discovery, I've wanted to try Pyzo out for some time now. You may be aware that the author of Pyzo is also the author of Flexx.

​No I didn't know that. Almar Klein is a busy guy.
 
It's great to see great artists getting inspiration from other great artists. Can't wait to see what comes of these developments. The syntax highlighting speed is one of the last big warts, would love to see it lopped off.

I'll be working on this off and on until it is finished.

Edward

Satish Goda

unread,
Jan 11, 2017, 10:21:37 PM1/11/17
to leo-editor
I installed Flexx yesterday and it is brilliant!

john lunzer

unread,
Jan 12, 2017, 12:23:24 PM1/12/17
to leo-editor
Happy to point somebody in the direction of Flexx. It is an amazing piece of software. I am very excited for it. I believe that it too (along with parts of Pyzo) has a future with Leo some day.
Reply all
Reply to author
Forward
0 new messages