ANN: Leo 3.11b1 outlining editor

Edward K. Ream edream at tds.net
Mon Feb 24 09:55:13 EST 2003


> The mod_open_with.py plugin has an "idle" hook that checks for changes in
> > the outline and updates node the outline if only the external file has
> > changed.  If _both_ the external outline and the corresponding node in
the
> > outline have changed there is a conflict, and the plugin will ask you
what
> > you want to do.
>
> Well, this already works if you modify the node both in the outline and
> in vim.
>
> The point is:
> 1) click on an icon to open the node in vim
> 2) modify the node only in the _outline_
> 3) click again on the icon to update the node in vim
>
> This doesn't update anything in vim because Leo reopens the temporary
> file created during the operation number 1 above.

> Is there a way to tell Leo that in such a case the temporary file should
> be discarded an recreated with the new outline contents?

As I have often said before, the answer to all such questions must be yes.
Indeed, it is straightforward to override any aspect of Leo's operation in a
hook, as various of the sample hooks show.  This is due primarily to
Python's flexibility and power.

In this case, the place to start looking for ideas is the
<< update v's body text >> section in the on_idle in mod_open_with.py.
The idea in that code is that v's body text has changed if the update flag
gets set.

Aside: the code creates a new attribute of vnodes, namely v.OpenWithOldBody,
that is not normally part of Leo's vnodes.  This ability to add attributes
to object instances at runtime is one of Python's many strengths.

In short: it is straightforward to check whether v's text has changed since
the last time the external file has changed.

The only remaining task is to update the external file.  The top level of
the on_idle hook shows how to go about doing this.  app().openWithFiles is a
list of Python dictionaries.  Each dict describes an open file.  The outline
of the code you want is very much like the present on_idle code, but you
want to check all files in the app().openWithFiles list, not just the files
that have changed externally.

I hope these hints will be enough for you to do what you want.  I'll be
happy to answer further questions if you get stuck.  When you get something
that works please post your solution here.  Thanks.

Edward
--------------------------------------------------------------------
Edward K. Ream   email:  edream at tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------







More information about the Python-list mailing list