A Temporary Solution To <cfscript /> Syntax Highlighting In TextMate and E-TextEditor

June 12th, 2008 | by Shayne |

I had a co-worker ask me recently - is there any syntax support for <cfscript /> in TextMate/E-TextEditor. In short - I don’t think so, or at least my Google searching didn’t reveal anything immediate. In lieu of going back with nothing - I decided to patch up a solution that would work in the mean time.

What I did was add an entry to the tmLanguage file for ColdFusion syntax - that adds JavaScript syntax highlighting to <cfscript /> blocks. It’s not perfect - but better than all one color.

To use - open up your ColdFusion bundle, and find the ColdFusion.tmLanguage file. Within the XML tree, paste the following snippet and reload your bundles. It doesn’t matter where you paste it so much - as long as it fits within the structure.

Enjoy

        <dict>
        <key>begin</key>
        <string>(?:^\s+)?<((?i:cfscript))\b(?![^>]*/>)</string>
        <key>captures</key>
        <dict>
            <key>1</key>
            <dict>
                <key>name</key>
                <string>entity.name.tag.cfm</string>
            </dict>
        </dict>
        <key>end</key>
        <string></((?i:cfscript))>(?:\s*\n)?</string>
        <key>name</key>
        <string>meta.tag.any.cfm</string>
        <key>patterns</key>
        <array>
            <dict>
                <key>include</key>
                <string>#tag-stuff</string>
            </dict>
            <dict>
                <key>begin</key>
                <string>(?<=>)</string>
                <key>end</key>
                <string>(?=</(?i:cfscript))</string>
                <key>name</key>
                <string>meta.tag.any.cfm</string>
                <key>patterns</key>
                <array>
                    <dict>
                        <key>include</key>
                        <string>source.js</string>
                    </dict>
                </array>
            </dict>
        </array>
    </dict>

Tags: ,

7 Responses to “A Temporary Solution To <cfscript /> Syntax Highlighting In TextMate and E-TextEditor”

  1. By Adam Cox on Jun 16, 2008

    To do this through the bundle editor. Open bundle editor and find the language file(black L circle) under Coldfusion. Copy this text into your language file. please be aware of leading and trailing commas
    {
    "begin" : "(?:^\\s+)?(]*/>)",
    "patterns" : [
    {
    "include" : "#tag-stuff"
    },
    {
    "begin" : "(?<!)",
    "patterns" : [
    {
    "name" : "comment.line.double-slash.js",
    "match" : "(//).*?((?=</cfscript)|$\\n?)",
    "captures" : {
    "1" : {
    "name" : "punctuation.definition.comment.js"
    }
    }
    },
    {
    "begin" : "/\\*",
    "name" : "comment.block.js",
    "captures" : {
    "0" : {
    "name" : "punctuation.definition.comment.js"
    }
    },
    "end" : "\\*/|(?=</cfscript)"
    },
    {
    "include" : "source.js"
    }
    ],
    “captures” : {
    “1″ : {
    “name” : “punctuation.definition.tag.html”
    },
    “2″ : {
    “name” : “entity.name.tag.script.html”
    }
    },
    “end” : “(</)((?i:cfscript))”
    }
    ],
    “name” : “source.js.embedded.html”,
    “endCaptures” : {
    “2″ : {
    “name” : “punctuation.definition.tag.html”
    }
    },
    “end” : “(?<=)(?:\\s*\\n)?”,
    “beginCaptures” : {
    “1″ : {
    “name” : “punctuation.definition.tag.html”
    },
    “2″ : {
    “name” : “entity.name.tag.script.html”
    }
    }
    }

  2. By Charles G. on Jun 25, 2008

    I’m just not having any luck getting either of these solutions to work. When I try editing the tmLanguage file and installing the bundle, the language entry disappears from the list and all text formatting is lost.

    When I try implementing the solution posted in the comments above, I keep getting the following error:

    Error Parsing Language Grammar
    line 236:1: expecting EOF, found ‘{’

    I’m new to TextMate and would really love to get this to work, any suggestions?

  3. By Shayne on Jun 25, 2008

    @Charles

    My best guess is that you’re inadvertently breaking the syntax of the tmLanguage file. With either the XML or Adam’s approach, you need to make sure you don’t break the layout and syntax of the file. It needs to fit in specifically.

    That is to say, don’t just add either one of these sections to the bottom of the file, instead - take some time to study the layout of the file and I am sure you’ll see where it should fit.

  4. By Charles G. on Jun 25, 2008

    Shayne,

    Thanks for the quick response.

    I’m sorry, I’m very familiar with XML and I’ve tried pasting the block you have above in several places that seem to make sense within the root element. However, when I reload the bundle it still seems to ignore the language file and all syntax is lost.

    I’ve checked out the latest copy of the bundle from the macromates subversion repository so that I can revert back to the original whenever a change I make doesn’t work. Would you be willing to share your tmLanguage file for comparison’s sake so that I know I’m not going crazy? =)

  5. By Shayne on Jun 25, 2008

    @Charles

    Sure, here’s the URL to the paste: http://pastebin.ca/raw/1055902

  6. By adam on Jun 28, 2008

    I should say that my version that’s in JSON format is only for e. textmate editor looks to do it in a script

  7. By adam on Jun 28, 2008

    this one works better: (Note that “include coldfusion-functions” is a separate pattern that may not be in your language file)
    {
    “begin” : “(?:^\\s+)?]*/>)”,
    “patterns” : [
    {
    "include" : "#tag-stuff"
    },
    {
    "begin" : "(?)",
    "patterns" : [
    {
    "include" : "text.html.cfm"
    },
    {
    "include" : "#coldfusion-functions"
    },
    {
    "include" : "source.js"
    }
    ],
    “name” : “source.sql.embedded”,
    “end” : “(?=</(?i:cfscript))”
    }
    ],
    “name” : “meta.tag.cfscript.cfm”,
    “captures” : {
    “1″ : {
    “name” : “entity.name.tag.cfscript.cfm”
    }
    },
    “end” : “(?:\\s*\\n)?”
    },

Post a Comment