Wednesday, March 22, 2006

Scripting Pydev with Jython

Ok, the new release already has its 'feature-set' defined, and among its new features is the possibility of scripting Pydev with Jython.

-- This will be added to the Open Source version.

I've already implemented a first example, and it seems to work ok. You can check it at this link.

Basically, I create a PythonInterpreter (from jython) that keeps listening to the Editor (so, it receives notifications of setting actions, document, disposing, etc). That script is always called when a notification is sent, with some 'locals' that are put, such as the editor that launched the notification and the command received.

For the integration, all the scripts in the jysrc folder that start with 'pyedit' will be compiled and ran. And if you change it, it will automatically 'know' that it changed and will reload it... pretty neat ;-)

In the example, it only cares about the 'onCreateActions' notification, and binds an Action to an activation code (in the case, Ctrl+'.').

I know it is still a simple example, and the scripting engine has a long way to go (I didn't even test if more than one script would be able to communicate to the other, nor did I add the jython Lib to the path), but should be a good initial step for that integration ;-)

Also, making code-completion in Jython with Eclipse internals is something that I still have to define better (it would be insane adding all the Eclipse jars to the project). Hopefully, in the future, you'll just be able to say that it is a plugin project with Jython files, and it will be able to get all that (until then, all the imports will be undefined while editing it, so, no code-completion for it)... On the other way, you can already have code-completion for Jython-related stuff if you configure your project correctly.



No comments: