• Howto enable syntax-highlighting for Groovy/Grails in Smultron

    Posted on April 18th, 2009 Nattl 6 comments

    I recently started playing around with Groovy and Grails. As I usually prefer simple & lightweight text-editors for coding rather  than complex IDEs like eclipse (doing all the ruff stuff like compiling at the command line) I wanted to use it with my favourite text-editor on the Mac: Smultron. Unfortunately the current version of Smultron (3.5.1) does not support Groovy syntax.  Googling around I found out that I’m not the only person that wants to use Smultron for Groovy/Grails, there is even a feature request for it. Peter Borg, the developer said that he will add groovy-syntax-highlighting if someone sends him a syntax definition. Thats fine, but I don’t want to wait for the next version… I want to use it NOOOOW ;) !!!

    So again it seems that a woman is needed to do a mans work. I looked around a little bit and found this description on adding custom syntax highlighting for smultron.  Basically its very easy to add a new syntax definition. If you installed the Apple developer tools on your Mac its super-easy as you can use the Property List Editor which can be found at Macintosh HD/Developer/Applications/Utilities/Property List Editor.app. If you don’t have the Developer tools installed it is still possible to create the syntax definition, but you need some XML-knowledge. I will only show the first way so I strongly recommend that install the Property List Editor (as a Developer you should have installed the Mac Development Tools anyway ;) ).

    Basically the Groovy-language derives from Java, even if the syntax looks different. So the Groovy-keywords are similar to the Java-Keywords plus any, as, def, in & with. This is everything you need to know to create a new syntax-definition for Smultron.

    Creating the definition with the Property List Editor

    1. Open your Application-folder (or whereever else you have installed Smultron) and right-click on Smultron.app.
    2. In the context menu choose “Show Package Contents”.
      A new Finder-window showing the package content appears.
    3. Direct the Finder to Contents/Resources/Syntax Definitions and choose the file java.plist. Double click it.
      The Property-List editor opens the file.

    4. Change the following properties:
      • beginFirstMultiLineComment from “/*” to “” (empty)
      • endFirstMultiLineComment from “*/” to “” (empty)
      • functionDefinition from “^\s*(static|public|private|protected|internal).*\(.*\).*\n?\s*\{” to “^\s*.*\(.*\)\n?\s*\{“
    5. Unfold the keywords-properties and add the keywords
      • any
      • as
      • def
      • in
      • with

      by adding items for them (In the Toolbar you have the Add Item-Icon)

    6. We could add now autocompleteWords, but the Java-definition doesn’t have them and I also don’t need them. If you use Smultron’s autocomplete-feature you could add them here ;)
    7. Save the file (File/save as) in the directory <currentUserName>/Library/Application Support/Smultron as groovy.plist
    8. Create a new plist file with File/new.
    9. Change the Root-element to type “Array”.
    10. Add a new item (‘Item 1), change its type to Dictionary.
    11. Add three items to Item 1:
    12. Save the file (File/save as) in the directory <currentUserName>/Library/Application Support/Smultron as SyntaxDefinitions.plist
    13. Start Smultron. Gratulations! From now on it will automatically recognize Groovy-files with the .groovy extension and will allow you to change the syntax-coloring by using Text/Syntax Coloring/Groovy in the menu. There is a small defective appearance as custom syntax definitions appear on the end of the list and not on the alphabetically correct position.

    For the lazy who don’t want to do all this editing work I have created a .zip-file containing both plist-files . Download it and extract its contents to <currentUserName>/Library/Application Support/Smultron. BTW, I also sent the definition to Peter Borg, and he told me that he will include the definition in the next release of Smultron :) .

     

    6 responses to “Howto enable syntax-highlighting for Groovy/Grails in Smultron” RSS icon


    Leave a reply