Category: TextMate


Tuesday 2007/04/24
3:16 PM

Categories:

Flash/Actionscript, TextMate

Enabling Actionscript Help in TextMate

(Update 2007-06-15): James's comment below reminded me of something I found while tinkering with this further: if you set the TM_FLASH_HELP variable with a full path including your hard drive the third slash in asd.rb is usually unnecessary. I've noted this below.

(Update 2007-05-17): It appears that this may not work with some versions of the asd.rb file, leading to the error described by Aaron in the comments section. I've added my version of asd.rb below)

For AS2 projects I've relied on the excellent Flash help file utility XASH. However, since XASH doesn't support AS3 yet, I revisited the help utility in the TextMate Actionscript bundle to see if I could get it to work. As I understand it, the bundle help scripts read the contents of the help_toc.xml file that sits with the Flash help html pages. It then renders a list of the matches to your selected word to a screen, which when clicked should bring up the web page for that match. Unfortunately,Sometimes this doesn't quite work out of the box. Two simple modifications are needed to get this to work Here's what I tried:

1) The shell variable TM_FLASH_HELP needs to point to /Volumes[Hard Drive Name]/Library/Application Support/Adobe/Flash CS3/en/Configuration/HelpPanel/Help/ActionScriptLangRefV3. You define this in TextMate > Preferences > Shell Variables. Originally I was setting this to //Library/Application Support... but this necessitated the change to asd.rb detailed below. Note that if you want to get this to work for AS2, you can point TM_FLASH_HELP to //Users/Shared/Library/Application Support/Macromedia/Flash 8/en/Configuration/HelpPanel/Help/ActionScriptLangRef.

The change below is no longer needed if you use a full path with your hard drive volume included for TM_FLASH_HELP.

2) The file asd.rb needs to be modified. The file is located in /Applications/TextMate.app/Contents/SharedSupport/Bundles/ActionScript.tmbundle/Support/Tools/asd.rb. To open it you'll need to right-click on the TextMate app, and select "Show Package Contents". Within that window browse to the Actionscript.tmbundle, and again right-click and show the package contents. My copy of asd.rb looks like this:

CODE:
  1. #!/usr/bin/env ruby
  2. #
  3. # Ale Muñoz <ale@bomberstudios.com> - 2006-11-25
  4. # Feel free to use and improve...
  5.  
  6. require "#{ENV["TM_SUPPORT_PATH"]}/lib/web_preview"
  7. require "rexml/document"
  8.  
  9. WORD    = ENV['TM_CURRENT_WORD']
  10. HELPDIR  = ENV['TM_FLASH_HELP']
  11. HELPTOC  = 'help_toc.xml'
  12.  
  13. # Help dir not set?
  14. if !HELPDIR
  15.     puts html_head(
  16.         :title => "Error!",
  17.         :subtitle => "Find in ActionScript Dictionary"
  18.     )
  19.     puts <<HEREDOC
  20.     <h1>Search failed for #{WORD}</h1>
  21.     <p>In order for this command to work TextMate needs to know where to find the ActionScript Dictionary index file. This is set in <strong>Preferences> Advanced> Shell Variables</strong>.</p>
  22.     <p>Click <strong>+</strong> and name the variable <code>TM_FLASH_HELP</code> with value of the path to the directory containing the help_toc.xml file on your system.</p>
  23.     <p>Macromedia have made this tricky and the files arent always in the same place.</p>
  24.     <p>Try clicking the following links:
  25.     <ul>
  26.     <li><a href="txmt://open?url=file:///Users/Shared/Library/Application Support/Macromedia/Flash 8/en/Configuration/HelpPanel/Help/ActionScriptLangRef/help_toc.xml">//Users/Shared/Library/Application Support/Macromedia/Flash 8/en/Configuration/HelpPanel/Help/ActionScriptLangRef</a></li>
  27.     <li><a href="txmt://open?url=file:///Library/Application Support/Adobe/Flash CS3/en/Configuration/HelpPanel/Help/ActionScriptLangRefV3/help_toc.xml">//Library/Application Support/Adobe/Flash CS3/en/Configuration/HelpPanel/Help/ActionScriptLangRefV3</a></li>
  28.     <li><a href="txmt://open?url=file:///Users/Shared/Library/Application Support/Macromedia/Flash MX 2004/en/Configuration/HelpPanel/Help/ActionScriptLangRef/help_toc.xml">//Users/Shared/Library/Application Support/Macromedia/Flash MX 2004/en/Configuration/HelpPanel/Help/ActionScriptLangRef</a></li>
  29.     <li><a href="txmt://open?url=file:///Applications/Macromedia Flash MX 2004/First Run/HelpPanel/Help/ActionScriptDictionary">/Applications/Macromedia Flash MX 2004/First Run/HelpPanel/Help/ActionScriptDictionary</a></li>
  30.     </ul>
  31.     <p>If any of the links work (TextMate will open the help_toc.xml file) then copy and paste the link, omitting the /help_toc.xml on the end, to the path of the shell variable.
  32. HEREDOC
  33.     html_footer
  34. else
  35.  
  36.     # Open TOC...
  37.     toc_lines = IO.readlines(HELPDIR + "/" + HELPTOC)
  38.  
  39.     # ...find matching lines...
  40.     search_results = []
  41.     toc_lines.each do |line|
  42.         search_results <<line.strip if line[/name=\"#{WORD}/]
  43.     end
  44.     puts html_head( :title => "Documentation for ‘#{WORD}", :sub_title => "ActionScript Dictionary" )
  45.     # ...parse results for links...
  46.     links = []
  47.     puts "<ul>"
  48.     search_results.each do |line|
  49.         xml_line = REXML::Document.new(line)
  50.         puts "<li><a href=\"tm-file:///#{HELPDIR}/#{xml_line.root.attributes['href']}\">#{xml_line.root.attributes['name']}</a></li>"
  51.     end
  52.     puts "</ul>"
  53.  
  54.     # ...or display error if no matches
  55.     puts "No results :(" if search_results.size == 0
  56.  
  57.     html_footer
  58.  
  59. end

Once you have asd.rb open, you need to make one small change. Line 52 builds the url(s) to the help file html page(s). Add an extra slash to the "tm-file:" prefix. It should now read "tm-file:///" instead of "tm-file://". Without this fix, you'll get a listing of matches to your selected word, but the link won't work.

Save asd.rb, rRestart TextMate, and you should now be able to highlight a word in your code and hit control-H to look for that word in the Flash help files. For example, try highlighting "MovieClip". You should get a listing for both the MovieClip class, and the MovieClip() constructor.

One quirk of the bundle's reliance on the help_toc.xml file is that the words show up twice in the xml, and thus you'll see the listing of matches to your word twice. Still, it's a small price to pay for a quicker help lookup than the IDE's sluggish help panel.


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...