Showing posts with label jython scripting. Show all posts
Showing posts with label jython scripting. Show all posts

Saturday, January 09, 2010

Templates on Pydev (with Jython scripting)

One really nice feature that has just been added to Pydev (available in the nightly build) is the possibility of extending the variables that are available for templates through Jython scripting.

It opens lots of possibilities, as when it's resolved it has access to the python code being edited (and all the available modules and Pydev APIs).

Some default templates were added already taking advantage of that (see: pytemplate_defaults.py as a reference -- the docstring explains how to create your own templates).

The image below shows the variables created in the defaults (already using Jython scripting -- note that when multiple superclasses are available, the ${superclass} variable enables the user to choose which one to use):





This enabled the print template to work as expected (giving only 'print ' in python 2.x and 'print()' in python 3.x, as it can 'know' which grammar you are using).

To finish, 2 other templates were creating taking advantage of the context:
super : super(MyClass, self).CurrentMethod()
super_raw : MySuperClass.CurrentMethod(self)

If anyone has other 'must have' template suggestions now that this is available, those are very welcome.

On a side note, the current nightly build is pretty stable (and should be the new released version unless there's some critical error lying there found in the next 2-3 days), so, it should be safe to get it to experiment with those.