Introduction to building a Komodo extension

Posted by trentm on 2007-09-06 15:16

Update: A lot of this information has been superceded by
http://docs.activestate.com/komodo/8.5/extensions.html

(A while ago Jaroslaw Zabiello asked a question on the komodo-discuss list that motivated me to finally write up a beginner intro to using the Komodo sdk tools for creating new Komodo language extensions. Here is my slightly edited response.)

Jaroslaw Zabiello wrote:

is there any chance for syntax colouring for Mako templates ...

This is certainly possible with Komodo's UDL (User-Defined Languages) system:
http://docs.activestate.com/komodo/7.0/udl.html

Eric also wrote up a (long) intro to writing UDL definitions a while back on his blog:
http://www.activestate.com/blog/2007/01/adding-new-languages-komodo-udl

Here is how packing up the Mako UDL into a Komodo extension works. Komodo includes a SDK in its install tree. On Linux and Windows this is found at "installdir/lib/sdk", and for a Mac it's found at "komodo.app/Contents/SharedSupport/sdk". That SDK includes a koext helper tool in the /lib/sdk/bin directory:

koext       a command line tool for working with Komodo extensions

Put the SDK bin dir on your PATH and you should be able to run koext at the command line. Similar to tools like cvs or svn, these are tools with multiple sub-commands. (If running these doesn't work for you, then please let us know so we can make the environment setup more smooth. There is currently a dependency on having a Python 2.6 installation -- which we should be able to remedy if necessary.)

  1. Start your extension source dir (with `koext startext'):

    $ koext help startext
    ...prints instructions on using this command...
    $ koext startext mako_language
    ...follow instructions for other extension meta-data...
    
  2. You should now be able to build your extension:

    $ cd mako_language     # cd in to source dir
    $ koext build
    

    This will build an .xpi file that you can install into your Komodo. However, the extension doesn't yet do anything.

  3. Generate stubs for defining a new language for Komodo:

    $ cd mako_language
    $ koext help startlang
    ...
    $ koext startlang Mako --ext .mako --is-html-based
    

    This will generate a few files that you'll then need to fill out with appropriate information for Mako template files. Namely:

    udl/mako-mainlex.udl
        The lexing/syntax-coloring UDL definition for Mako.
    components/koMako_UDL_Language.py
        The PyXPCOM component that defines the language for
        Komodo.
    

Properly filling these out is a big topic beyond the scope of this document. Your best references are:

  • The UDL reference in the Komodo documentation.
  • Eric's blog post for UDL.
  • Check out the example Maya extension, which uses UDL:
  • A Komodo macro that can visually show styling information
  • Example .udl files in the Komodo source and sdk directory (lib/sdk/udl/...)
  • Look at other ko*_UDL_Language.py files in your Komodo installation, as many of the languages supported in Komodo are based on UDL and work in the exactly same way as the Mako language component. Look for PHP, RHTML, Smarty, HTML, TemplateToolkit, and Mason. They should be quite similar.

Note: Komodo also has a project template "Project > New Project from Template > Komodo Extension" that you could use for starting an extension, however this template does not include any language (koext) facilities.

I realize that this isn't quite as smooth a process as it could be yet, but with the help of the Komodo users, we hope to get there in subsequent releases.

toddw
ActiveState Staff
Thu, 2010-01-07 20:14

Note: You can use this Komodo helper macro to visualize the document styling:
http://community.activestate.com/faq/debug-udl-language-styling

Cheers,
Todd

pyrokinesis | Mon, 2010-02-22 01:49

This has been really great thanks for all your efforts.
I would like to take this a few steps further, but i'm not exactly sure how. Here is the functionality I would like to add...

maya.cmds.ls()
When typing the parenthesis we get tool tips, but they are empty...
Support the available flags for each command, example...

maya.cmds.ls(sl=True, dag=True, exactType=True)

Generate tips and auto-complete options for all of the flags.
Also the option to show tips when auto complete pops up.

Can anyone advise on how we might proceed with this functionality for both Mel and Python?

Thank you very much.

toddw
ActiveState Staff
Mon, 2010-02-22 17:11

You'd need to edit the Maya API catalog file maya.cix that resides in the Maya extension:
http://community.activestate.com/forum/maya-python-cix-extension

updating the "signature" and "doc" attributes in the XML file should give you what you need.

BTW, the CIX schema is available here as the "cix-2.0.rng" attachment:
http://community.activestate.com/faq/codeintel-cix-schema

Cheers,
Todd

sergiol | Sun, 2010-10-10 05:10

These paths are not correct or do not reflect the current version.
We have koext.py and luddite.py now in the bin subdirectory as python scripts.

So it is needed to do python koext.py or do you know sthg more straight to call those scripts?

toddw
ActiveState Staff
Tue, 2010-10-12 21:33

You should be able to run koext directly (it resides in the sdk/bin directory) - as long as it's on your system PATH. I.e.:

/opt/Komodo-IDE-6/lib/sdk/bin/koext help

Cheers,
Todd