Category: TextMate


Monday 2007/03/26
11:39 AM

Categories:

Apple, TextMate

Encrypting Files with TextMate

I love the way TextMate doesn’t bludgeon you over the head with its feature set, instead presenting a super-clean UI that belies the extensive amount of features and utilities under the hood. One of the little bits that I’ve just stumbled upon was the file encryption command under the Text bundle (Bundles -> Text -> Encryption). I’ve been looking for a quick-and-dirty way to keep some URLs and passwords encrypted when backed up to an offsite server, and this looks like it’ll do the trick.

For a more generic utility a coworker of mine suggested Crypt, which should work with any file.


Tuesday 2007/02/06
12:48 PM

Categories:

Flash/Actionscript, TextMate

ActionScript Support for TextMate’s TmCodeBrowser Plugin

Update 2007-05-30: Added support for const vars

One of the things I've been searching for ever since I switched over to using TextMate for ActionScript development has been code browsing of classes/properties/methods. TextMate has the method list in the status bar, but that's it. I found the TmCodeBrowser plugin recently, and it worked...for everything except for ActionScript. After some back-and-forth emails with Gerd Knops, the author of TmCodeBrowser, here's how I extended it to support AS files.

  1. Download and install the TmCodeBrowser plugin.
  2. Create a file named .ctags.tmcodebrowser in your home directory (Note the period before the name). TmCodeBrowser will read in the ActionScript search patterns in this file in addition to the default spec for the other languages.
  3. Paste in the following lines into .ctags.tmcodebrowser. YOU MUST add a linebreak after the last line; for some reason the last regex is ignored without the linebreak.
  4. CODE:
    1. --langdef=ActionScript
    2. --langmap=ActionScript:.as
    3. --regex-ActionScript=/^[ \t]*package[ \t]*([A-Za-z0-9_\ \.]*)[ \t]*/\1/package/
    4. --regex-ActionScript=/^[ \t]*[(private|public|static|protected|internal|\ )( \t)]*function[ \t]+([A-Za-z0-9_]+)[ \t]*\(/\1/method,methods/
    5. --regex-ActionScript=/.*\.prototype\.([A-Za-z0-9 ]+)=([ \t]?)function([ \t]?)*\(/\1/m,method,methods/
    6. --regex-ActionScript=/^[ \t]*[(public|private|static|protected|internal|\ )]+[( \t)]*(var|const)[ \t]+([\$]*[A-Za-z0-9_]+)[ \t]*/\2/p,property,properties/
    7. --regex-ActionScript=/^[ \t]*[(public|private|static|protected|internal|\ )]*[( \t)]*class[ \t]+([A-Za-z0-9_.]+)[ \t]*/\1/c,class,classes/

  5. Save .ctags.tmcodebrowser and relaunch TextMate.

Gerd explained to me that TmCodeBrowser updates after saving a file. I realized this after opening an AS file and the CodeBrowser panel came up empty. Saving the file refreshed the CodeBrowser.


Thursday 2006/11/30
10:49 AM

Categories:

TextMate

Textmate Blogging Bundle Test

If you're seeing this, blogging from TextMate has succeeded. For some reason WordPress returns an invalid size header, which causes the configuration to fail. Commenting out the else if block on line 551 of /usr/lib/ruby/1.8/xmlrpc/client.rb solved the issue.


Tuesday 2006/09/12
4:24 PM

Categories:

Flash/Actionscript, TextMate

TextMate and AS3

Continuing on the TextMate scripting tip, here's a quick and dirty compile command I whipped up for compiling AS3. This is based on a post at the Vixiom Axioms blog. Read on for the code, my Wordpress template won't render it properly on the front page... More...


Monday 2006/09/11
5:11 PM

Categories:

Flash/Actionscript, TextMate

TextMate/MTASC/XTrace Revisited

A couple of months ago I switched over to TextMate as my full-time AS editor. Previously I'd been using XCode with the PixelConsumption AS 2 framework. Although Textmate doesn't have the nice code-hinting of that XCode framework, it does have an Actionscript bundle and autocomplete for strings already present in your document. TextMate's snippets have also proved useful, allowing me to set up skeleton code for common things like private/public methods. There's even the ever-useful Command-Enter hotkey to kick you over to the Flash IDE for compiles. The only thing that drives me batty is the well-documented project drawer refresh issue with mounted drives (a nifty workaround is described here).

I came upon this post at Wimer Hazenberg's Monokai blog describing a TextMate/MTASC/XTrace workflow a while back, tried it, and shelved it when I couldn't get XTrace to work with files I'd placed on a webserver. I've since worked out the XTrace issue (a crossdomain policy served from my Mac's localhost did the trick) so I decided to take some time to re-investigate the workflow. So here are two Textmate Actionscript commands that I whipped up based on that Monokai post. My goals were not to do project-level compiles, but instead incremental syntax checks with MTASC and simple single-swf compiles. These commands assume that you have MTASC and XTrace installed and working (see the Monokai post for more on both of those). Note that I placed the MTASC folder in /Users/domanistudios/opt/, which you can see from the variable declarations in the commands.

The first command calls MTASC with no output swf, and dumps the first error to an HTML ouput window (I believe mtasc only reports the first error it encounters during a compile). Using the built-in TextMate url functionality, clicking on the error will return you to the document you were editing, at the line where the error was encountered (so far haven't figured out how to get it to go to the proper character, though). Note that you can also modify the actual line that does the compile to add/delete arguments (like -strict).

I've set it up this way:

Save: Current File
Input: None
Output: Show as HTML
Key Equivalent: Control-Command-M (scoped to source.actionscript)

CODE:
  1. FLASHPLAYER=SAFlashPlayer
  2. MTASC=/Users/domanistudios/opt/mtasc/mtasc
  3. CLASSES=/Users/domanistudios/Library/Application\ Support/Macromedia/Flash\ 8/en/Configuration/Classes/
  4. SOURCE="$TM_FILEPATH"
  5. OUTPUT=test.swf
  6. HEADER=550:400:40:ffffff
  7. VERSION=7
  8. TRACE=-trace\ com.mab.util.debug.trace
  9. TMPFILE=/tmp/domanistudios.err
  10.  
  11. compileResult=$( $MTASC 2>&1 -cp "$CLASSES" -main "$SOURCE" -header $HEADER -wimp $TRACE -strict)
  12. echo "
  13.     <style type='text/css'>
  14.         body {margin: 10px; font-family: Courier New; font-size: 14px;}
  15.         a {color: #000000; text-decoration: none;}
  16.         a:hover {color: #666666;}
  17.     </style>
  18.     <script type='text/javascript'>
  19.         function closeWin() {
  20.             self.close();
  21.         }
  22.     </script>
  23. "
  24.  
  25. if test -n "$compileResult"
  26. then
  27.     errorLine=`echo $compileResult | sed 's/.*:\([0-9]*\):.*/\1/'`
  28.     echo "<a href='txmt://open?url=file://$TM_FILEPATH&line=$errorLine' onclick='closeWin();'>$compileResult</a>";
  29. else   
  30.     echo "<body onload='closeWin()'></body>"
  31. fi

The second one is essentially the same, except that it allows you to enter the name of the output swf you want to generate. As an added bonus you can add on any additional arguments not contained in your "base" compile command, so you could enter "tuto.swf" or "tuto.swf -strict", for instance.

I've set it up this way:

Save: Current File
Input: None
Output: Show as HTML
Key Equivalent: Shift-Control-Command-M (scoped to source.actionscript)

CODE:
  1. FLASHPLAYER=SAFlashPlayer
  2. MTASC=/Users/domanistudios/opt/mtasc/mtasc
  3. CLASSES=/Users/domanistudios/Library/Application\ Support/Macromedia/Flash\ 8/en/Configuration/Classes/
  4. SOURCE="$TM_FILEPATH"
  5. HEADER=550:400:40:ffffff
  6. VERSION=7
  7. TRACE=-trace\ com.mab.util.debug.trace
  8.  
  9. res=$(CocoaDialog inputbox --title "Output SWF Name" \
  10.     --informative-text "Please name your output swf:" \
  11.     --button1 "OK" --button2 "Cancel")
  12.  
  13. [[ $(head -n1 <<<"$res") == "2" ]] && exit_discard
  14.  
  15. OUTPUT=$(tail -n1 <<<"$res")
  16. #echo "You entered: $OUTPUT"
  17.  
  18.  
  19. compileResult=$( $MTASC 2>&1 -swf $OUTPUT -cp "$CLASSES" "$SOURCE" -wimp -keep $TRACE)
  20.  
  21. echo "
  22.     <style type='text/css'>
  23.         body {margin: 10px; font-family: Courier New; font-size: 14px;}
  24.         a {color: #000000; text-decoration: none;}
  25.         a:hover {color: #666666;}
  26.     </style>
  27.     <script type='text/javascript'>
  28.         function closeWin() {
  29.             self.close();
  30.         }
  31.     </script>
  32. "
  33.  
  34. if test -n "$compileResult"
  35. then
  36.     errorLine=`echo $compileResult | sed 's/.*:\([0-9]*\):.*/\1/'`
  37.     echo "<a href='txmt://open?url=file://$TM_FILEPATH&line=$errorLine' onclick='closeWin();'>$compileResult</a>";
  38. else       
  39.     echo "<body onload='closeWin()'></body>"
  40.     osascript -e "tell application \"$FLASHPLAYER\" to quit"
  41.     open -a $FLASHPLAYER $OUTPUT
  42. fi

If there's an error, it does the same thing as the first command - displays the error which can be clicked to bring you back to the document. If no error is reported, it compiles the swf and opens it up in the standalone Flash player.

One issue with both commands is that if the error is in an imported class, clicking on the error will not take you to that class - I suppose I could do more path-munging to get this to work, but for now I've just made a not of which class generated the error, and then I go to that class before resuming debugging.