X

Geertjan's Blog

  • May 16, 2012

Syntax Coloring for FreeMarker

Geertjan Wielenga
Product Manager

Without fail, each JavaCC file (and ANTLR file) I have ever found (e.g., for Clojure and Ceylon) has been beaten into submission via this tutorial, which includes a YouTube movie explaining everything:

http://platform.netbeans.org/tutorials/nbm-javacc-lexer.html

Here's FreeMarker in NetBeans IDE, after applying the above tutorial to this file, which I found on-line after googling for about 5 minutes:

https://raw.github.com/freemarker/freemarker/master/src/main/javacc/FTL.jj

Not as pretty nor as complete as it could be, but I've clearly gone some way to getting things to work together.

However, note that in line 6 and 7, I have selected the "p" tag across two lines, meaning that I can change related text across multiple lines, because the block selection feature is a standard part of all editors, including any new editor you create, such as the FreeMarker editor above.

Join the discussion

Comments ( 16 )
  • Alex Kochnev Thursday, August 30, 2012

    Geertjan - any chance that you could share the resulting project somewhere (github/googlecode) ?


  • Geertjan Thursday, August 30, 2012
  • Morten Saturday, November 10, 2012

    I just wish Netbeans would have proper Freemarker template editing support (syntax highlighting, navigation etc). Either built-in or as a maintained plug-in.

    But no progress seems to be made on that front. An issue has been created in 2008 http://netbeans.org/bugzilla/show_bug.cgi?id=144971 but the status is still "NEW". Shame!


  • Geertjan Saturday, November 10, 2012
  • jim d Thursday, November 29, 2012

    But the problem, Geertjan, is that it doesn't appear to install correctly. I've tried taking installing that .nbm on Netbeans 7.3beta2 but the installer dialog displays the mesage "The plugin Lexer to NetBeans Bridge is requested in implementation version 201207171143." And then the install goes no further (I only have the option to cancel).

    I don't "Lexer to NetBeans Bridge" in the list of available plugins. Any idea where I can find it? I have a feeling that I'm overlooking something obvious...


  • Geertjan Thursday, November 29, 2012

    You can see for yourself, Jim, that this blog entry was written in May of this year. Did NetBeans IDE 7.3 Beta 2 exist at that time?


  • Jim d Friday, November 30, 2012

    Thanks Geertjan. Sorry, I should have also mentioned that I tried this with Netbeans 7.2 and Netbeans 7.1.2 (which I asssume is the version you would have been working with, yes?) but unfortunately didn't have any luck. The result for 7.2 was identical to my 7.3beta 2 attempt, and for 7.1.2 there were several messages along the line of "the plugin xyz is requested in version >= 1.234 but only 1.123 was found". I even ran the "check for updates" process and tried again, but to no avail.

    Any thoughts on what I'm doing wrong?


  • Geertjan Friday, November 30, 2012

    Can you give me a clue where you're getting the plugin from? I.e., give me a URL pointing to where you're downloading the plugin, please...


  • guest Saturday, December 1, 2012

    Sure thing. First I drilled down to the versions/7.2/misc/ftl/release directory:

    http://java.net/projects/nb-api-samples/sources/api-samples/show/versions/7.2/misc/ftl/release?rev=425

    From there I just downloaded the nbm file:

    http://java.net/projects/nb-api-samples/sources/api-samples/content/versions/7.2/misc/ftl/release/org-ftl.nbm?rev=425

    Actually I have some good news. Instead of just trying the .nbm file I pulled the whole project and built the plugin with netbeans 7.2.1, and I was indeed able to install the resulting .nbm file. Yay! Colorful .ftl files!!

    I'm not sure why the above links did not work (the file sizes are rather different, 90k for the successful nbm and 40k for the unsuccessful nbm) But either way I'm happy that it's working now. Thanks!


  • mcmagi Thursday, December 13, 2012

    I'm also having the same issue as Jim D under NB 7.2.1. I also tried to download and build the ftl project as he suggested and used the resulting nbm, but it is still looking for the "Lexer to NetBeans Bridge" plugin when I try to install.

    Interestingly, org-netbeans-modules-lexer-nbbridge.jar is present under ide/modules, so I'm not sure why it's complaining.

    Any suggestions on how I could resolve this?


  • Geertjan Thursday, December 13, 2012

    Instead of just trying the .nbm file, pull the whole project and build the plugin with netbeans 7.2.1, and you'll indeed be able to install the resulting .nbm file.


  • mstewie Saturday, December 15, 2012

    Hi Geertjan - is there any way to stop this plugin screwing up my properties files fonts and colors preferences? I have messed with FontsAndColors1.xml and FreeMarkerUtils.java locally by prefixing "ftl-" in front of all the categories but when I open a .properties file, the foreColor is always magenta. When I look in my Fonts & Colors preferences for Properties files they are still correct by when I open a file then all fore ground colors are magenta. Any ideas? Thanks


  • mcmagi Monday, April 29, 2013

    Hi Geertjan - Finally coming back around to experiment with this since I've been doing a lot of freemarker work. I didn't have much luck with pulling the whole project and building the plugin. I still get the "Lexer to NetBeans Bridge" message when trying to install.

    What I think might be a clue is guest's comment (https://blogs.oracle.com/geertjan/entry/syntax_coloring_for_freemarker#comment-1354335170688) that their resulting file is 90k rather than 45k for the nbm packaged in the releases folder. When I build the project, the nbm in the build/cluster folder is still only 45k. Maybe the jar for the "Lexer to Netbeans Bridge" is not getting included in the nbm file?

    Thanks in advance for your help.


  • mcmagi Monday, April 29, 2013

    Finally coming back around to experiment with this since I've been doing a lot of freemarker work. I didn't have much luck with pulling the whole project and building the plugin manually. I still get the "Lexer to NetBeans Bridge" message when trying to install the nbm file in build/cluster.

    What I think might be a clue is guest's comment (https://blogs.oracle.com/geertjan/entry/syntax_coloring_for_freemarker#comment-1354335170688) that their resulting file is 90k rather than 45k for the nbm packaged in the releases folder. When I build the project, the nbm in the build/cluster folder is still only 45k. Maybe the jar for the "Lexer to Netbeans Bridge" is not getting included in the nbm file?

    Thanks in advance for your help.

    (sorry if this double-posts)


  • mcmagi Monday, April 29, 2013

    Okay, so I just got this to work if I choose "Install/Reload in Development IDE" within NetBeans.


  • Adnan Friday, March 27, 2015

    I wonder whether there's any tutorial to create support of some XML/HTML like language in Netbeans? For instance coloring of keywords in following code:

    <div id="new">Hi</div>


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.