autocmd with scripting api

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

autocmd with scripting api

Chris Grebeldinger

Hi,

            I haven’t found anything about this in the scripting API files, I was wondering if there is any way to have a script run when a document is saved.  Similar to what you would get with vim:

 

autocmd BufWritePre call MyFunc

 

 

Chris Grebeldinger

 


_________________________________________________
Wing IDE users list
http://wingware.com/lists/wingide
Reply | Threaded
Open this post in threaded view
|

Re: autocmd with scripting api

Wing IDE Support
On Wed, 27 Jul 2005, Chris Grebeldinger wrote:
>             I haven't found anything about this in the scripting API files,
> I was wondering if there is any way to have a script run when a document is
> saved.  Similar to what you would get with vim:

Yes, although it's not as simple.  You need to connect to either the
'presave' or 'save-point' signal on the CAPIDocument object.  
Something like:

doc.connect('presave', mycallback)

The args sent to the callback are documented in the wingapi.py file.

You can use gApplication.GetAllDocuments() on the app API to connect
initially to already-open docs and the 'editor-open' signal on the app
to connect to newly opened ones.

One caveat:  I think 'presave' my not work in Wing 2.0.3 -- you may
need to add 'presave' to the list passed to the CDestroyable.__init__
in the CAPIDocument.__init__.

Also, note that the save-point signal is emitted also when an editor
leaves the save point by being modified, and it is emitted w/ 1
(arrived at save point) also if an undo gets you back to the state
that the buffer matches disk.  If that's a problem, please let me
know.  The API is still somewhat in flux.

Thanks,

Stephan Deibel

--
Wingware
Wing IDE for Python
Advancing Software Development

www.wingware.com
_________________________________________________
Wing IDE users list
http://wingware.com/lists/wingide