ANN: Leo 3.11b1 outlining editor
Andrea Galimberti
andrea_galimberti at tin.it
Tue Mar 4 08:11:09 EST 2003
Edward K. Ream wrote:
>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.
Thank you for your hints. I completed the new version of the plugin. Now
if the node contents are changed in the outline the temporary file is
discarded, recreated and opened in VIM.
Here I have pasted the output of the "Write @file nodes" command. Hope
this format is suitable for you.
\bye, Andrea
----------- plugin ---------------
#@+leo
#@+node:0::@file mod_vim.py
#@+body
#verbatim
#@ignore
#@@language python
#@<< mod_vim declarations >>
#@+node:1::<< mod_vim declarations >>
#@+body
"""vim handler"""
# Contributed by Andrea Galimberti.
# To use this plugin do the following:
#
# - Start VIM as server: vim --servername "VIM"
# The name of the server *must* be "VIM".
#
# - Single-click on a node's icon to open that node in VIM.
#
# - Leo will update the node in the outline when you save the file in VIM.
from leoPlugins import *
from leoGlobals import *
import os,tempfile
#@-body
#@-node:1::<< mod_vim declarations >>
#@+others
#@+node:2::open_in_vim
#@+body
def open_in_vim (tag,keywords):
if top():
v=keywords['v']
# find dictionary with infos about this node
this=filter(lambda x: id(x['v'])==id(v), app().openWithFiles)
# retrieve the name of the temporary file (if any)
if this != []:
path=this[0]['path']
else:
path=''
if os.path.exists(path):
# get previous node contents
try:
old=v.OpenWithOldBody
except AttributeError:
old=''
# if something changed
if v.bodyString() != old:
# delete old temp file
os.remove(path)
# remove old temp file from list
app().openWithFiles=filter(lambda x: x['path']!=path, app().openWithFiles)
# update old body with new contents
v.OpenWithOldBody=v.bodyString()
# open the node in vim (note the space after --remote)
top().frame.OnOpenWith(("os.system", "vim --remote ", None))
#@-body
#@-node:2::open_in_vim
#@-others
if 1: # Register the handlers...
registerHandler("iconclick2", open_in_vim)
es("...vim v1.2")
#@-body
#@-node:0::@file mod_vim.py
#@-leo
-----------------------------------END-----------------------------------
More information about the Python-list
mailing list