Use the bridge, Luke

61 views
Skip to first unread message

Edward K. Ream

unread,
Jun 18, 2019, 1:07:38 PM6/18/19
to leo-editor
Integrating pyzo into Leo fails because pyzo's shell can't control Leo's gui.  However, such scripts could access the data in Leo outlines using Leo's bridge.  That is, Leo's bridge supports restricted Leonine scripts.  This in no way tempts me to embed pyzo's shell, debugger, etc. into Leo ;-)

It is easy to start Leo's bridge from pyzo, or IPython, or any other python environment. It's an alternative to leo --ipython, for example.

I have just created #1213: support Leo's bridge in vim.  This would be a separate from Leo's vim.py plugin, and might have advantages for some vim users. It would be written in vim script. Anyone interested in this project? I'll be glad to answer any questions you may have.

Edward

Terry Brown

unread,
Jun 18, 2019, 1:38:51 PM6/18/19
to Leo list
A lot of vim plugins are written in Python, so perhaps you could use that instead of vimscript.

Cheers -Terry

--
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+...@googlegroups.com.
To post to this group, send email to leo-e...@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/2a72fe65-4817-40fa-b48a-32902dfce416%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Edward K. Ream

unread,
Jun 18, 2019, 2:31:30 PM6/18/19
to leo-editor


On Tuesday, June 18, 2019 at 12:38:51 PM UTC-5, Terry Brown wrote:
A lot of vim plugins are written in Python, so perhaps you could use that instead of vimscript.

Thanks. I didn't know that. In that case the entire vim plugin would be based on this.  Care to give it a go?

Edward

Terry Brown

unread,
Jun 18, 2019, 3:22:32 PM6/18/19
to leo-e...@googlegroups.com
On Tue, 18 Jun 2019 11:31:30 -0700 (PDT)
"Edward K. Ream" <edre...@gmail.com> wrote:

>
>
> On Tuesday, June 18, 2019 at 12:38:51 PM UTC-5, Terry Brown wrote:
> >
> > A lot of vim plugins are written in Python, so perhaps you could
> > use that instead of vimscript.
> >
>
> Thanks. I didn't know that. In that case the entire vim plugin would
> be based on this <http://leoeditor.com/leoBridge.html#the-basics>.
> Care to give it a go?

Not without much more specific objectives ;-)

vim doesn't always come with Python support installed, but I'm guessing
more often than not. Also it's not hard to compile vim from scratch,
so in cases where Python's missing, it's probably not hard to add.

Given that, I don't think any RPC / client-server vimscript <->
leo_bridge_server.py plumbing would be worth the effort, just write the
vim part in Python, and therefore just use leoBridge as usual.

So then what? vim can use a Leo file as a data structure, but how does
it navigate the Leo file? vim's https://github.com/scrooloose/nerdtree
and https://github.com/majutsushi/tagbar#screenshots plugins both
implement tree navigation, but I haven't looked at either enough to
know if they can be re-purposed. I feel that this looks like possibly
low hanging fruit, but would turn into a bigger project. And there are
other options for editing Leo files. Leo, for example ;-)

Cheers -Terry

Edward K. Ream

unread,
Jun 18, 2019, 6:20:48 PM6/18/19
to leo-editor
On Tue, Jun 18, 2019 at 2:22 PM Terry Brown <terry...@gmail.com> wrote:

> Thanks. I didn't know that. In that case the entire vim plugin would
> be based on this <http://leoeditor.com/leoBridge.html#the-basics>.
> Care to give it a go?

Not without much more specific objectives ;-)

The objective is simply to be able to access Leo outline from either python or vim script.  In python, all that is needed is access to c and g.  From c, we get c.p and all the generators.

Edward

Terry Brown

unread,
Jun 18, 2019, 7:27:34 PM6/18/19
to leo-e...@googlegroups.com
On Tue, 18 Jun 2019 17:20:37 -0500
"Edward K. Ream" <edre...@gmail.com> wrote:

Then I'm not sure that there's really anything to do. Python's
well integrated into vim, so you can just use leoBridge as usual. I
assume - I guess I can do something to verify that, but I can't see why
it wouldn't work.

Cheers -Terry

Edward K. Ream

unread,
Jun 19, 2019, 1:53:04 AM6/19/19
to leo-editor
On Tue, Jun 18, 2019 at 6:27 PM Terry Brown <terry...@gmail.com> wrote:

Then I'm not sure that there's really anything to do.   Python's
well integrated into vim, so you can just use leoBridge as usual. 

Cool.
I guess I can do something to verify that, but I can't see why it wouldn't work.

Please do.  That would be helpful.

Edward

Terry Brown

unread,
Jun 19, 2019, 8:38:49 AM6/19/19
to leo-e...@googlegroups.com
On Wed, 19 Jun 2019 00:52:54 -0500
"Edward K. Ream" <edre...@gmail.com> wrote:

Ok, this script appends the outline headlines, indented, to the current
vim buffer:

import leo.core.leoBridge as leoBridge
import vim

controller = leoBridge.controller(
gui='nullGui',
loadPlugins=True, # True: attempt to load plugins.
readSettings=True, # True: read standard settings files.
silent=True, # True: don't print signon messages.
verbose=False, # True: print informational messages.
)

g = controller.globals()
c = controller.openLeoFile("/home/tbrown/.leo/del.leo")


def dent(node, result, level=0):
result.append(' ' * level + node.h)
for child in node.children:
dent(child, result, level + 1)
return result


result = []
dent(c.hiddenRootNode, result)

vim.current.buffer[-1:] = result


It can be invoked with

:py import leodent

assuming it's in a file leodent.py and on the Python path.

Cheers -Terry

Edward K. Ream

unread,
Jun 19, 2019, 10:15:07 AM6/19/19
to leo-editor
On Wed, Jun 19, 2019 at 7:38 AM Terry Brown <terry...@gmail.com> wrote:

Ok, this script appends the outline headlines, indented, to the current
vim buffer:

Many thanks for this!  I'll add this to scripts.leo and Leo's bridge chapter.

Edward
Message has been deleted

Edward K. Ream

unread,
Jun 20, 2019, 9:38:24 AM6/20/19
to leo-editor


On Thursday, June 20, 2019 at 8:36:34 AM UTC-5, Josef wrote:

Support for vim-script may add additional functionality if it would support vim plugins, as there are many available. For me, there are currently just a few reasons for using vim in parallel to Leo: vim starts up fast, has syntax highlighting for just about anything with good print support, comes with every linux version, but the main reason is it is the only editor with some decent support for TaskJuggler. That support is available as plugin, and I guess it is vim-script.
Just supporting the language, without being able to "just use" plugins will not do much, though. In that case I agree with Terry, that it may be better to use Python.

Thanks for this.  I rely on vim users to improve how Leo interacts with vim.

Edward
Reply all
Reply to author
Forward
0 new messages