Geany syntax for MooseX::Declare


Picking an editor is often not only a matter of "what suits me better" but also a religious thing. I tend to only look to the first aspect and - after using many different editors (Eclipse, Komodo, vim, emacs, ...) I decided to stick with Geany. It's a multiplatform GUI editor which is lightweight, handy to use, and offers the features I need. When I do not have a GUI available (fex. when working via SSH) I still use vim.

With MooseX::Declare (and CatalystX::Declare and Sub::Curried and many other modules) we now have new keywords in Perl, some of which were much awaited. It would be for Geany to show them highlighted with the proper colour. To achieve this, we can (easily) tweak the syntax highlighting system.

My explanation here applies to Unix system, but it's valid everywhere provided you use the correct system-specific paths.

If you just want the file and skip the explanation, click here to download the patched filetypes.perl (original from Geany 0.18 dist). :-)

Syntax definitions are kept in a system-wide directory (it's /usr/share/geany in my system) and are named in a filetypes.language fashion, fex. filetypes.haskell. If you edit these files directly, they will affect all users in the system: it is, however, a discouraged practice as upgrading to a new Geany version could mangle your changes depending on how your package manager works. The best option is to copy one of those files in your ~/.config/geany/filedefs directory; in our case:

cp /usr/share/geany/filetypes.perl ~/.config/geany/filedefs/

The file in your home directory will override the system-wide one. To add highlighting for the new keywords look for the:


section in the file and add whatever you want to the primary variable. I added:

class, method, extends, before, after, around, override, augment, role, with

At this point, you're done: just launch Geany again.

It looks like it's not possible to specify a regular expression for a keyword, like /is\s+mutable/. This would allow to give colour also to is mutable and is dirty. I'll ask the Geany community about that.

On Geany upgrades, be careful to check if there were changes in the original filetypes.perl and merge them.

You can also download the patched filetypes.perl (original from Geany 0.18 dist). For more information, read this section of the Geany user manual.


The MooseX::Declare docs already point at options for syntax highlighting for both vim and emacs. Feel free to add Geany as well :-)

Regarding regular expressions in syntax keywords, after investigation it seems like it is Scintilla which need to be hacked on. Geany uses it as syntax highlighting component.

Leave a comment

About this Entry

This page contains a single entry by Michele Beltrame published on September 24, 2009 8:04 AM.

Pragmatic Version Control using Git was the previous entry in this blog.

A review of Real World Haskell by a Perl programmer is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.



OpenID accepted here Learn more about OpenID
Powered by Movable Type 5.14-en