Category: TextMate
Toggling Between Main Window and Drawer in TextMate
Sometimes it pays to read the Key Bindings listing. Today I found out that ⌥⌘` (or ⌥⌘~) toggles between the main editor window and the project drawer. Since I use the Subversion bundle heavily while in TextMate, being able to switch back and forth between the two contexts is great.
Another tip that I never knew about was the “Edit in TextMate” command (installed via the TextMate bundle) that works with most programs on OS X (I use it mainly in Mail.app, although I tried it on the Wordpress editing window in Safari to write this post). I clicked in the form field, hit ⌃⌘E (Control+Command+E), and it launched an editor window in Textmate. Probably not worth the hassle for short posts/emails, but for longer writing stretches it’s nice to work in the environment in which I spend the most time. Saving in TextMate dumped the text back to the input form in Safari (although only when that window is in focus). This is all very geek-tastic.
A Quick RubyAMF Test
Update 2007-10-22: Updated the line with the RubyAMF installer to point to the new googlecode location. Updated the link to the SSR library.
Update 2007-08-30: Seth's comment below revealed the need for a cross-domain policy file in /public when testing this via the browser. I did all my testing from the flash debug player and the IDE, so I didn't run into this while writing this up. Aaron has said that he'll include the crossdomain policy file as part of the RubyAMF installer in the future.
Back from my Seattle/Portland vacation with Jordan (details on that to follow, but photos are up on Flickr).
Another quick Rails experiment, this time checking out RubyAMF. I wanted to run the RubyAMF gateway as a Rails plugin, so I used this Flex/Rails screencast on the RubyAMF blog as a reference for getting the Rails part done. You might want to view my earlier post on setting up Locomotive with MAMP.
I first created a new Rails app in Locomotive called test_hello_world (I also switched the port from 3001 to 3000). Once that was done I simply replicated the steps in the screencast:
Download RubyAMF.Create a rubyamf folder in the test_hello_world/vendor/plugins directory.Copy the contents of the RubyAMF download to the rubyamf directory.Copy the rubyamf/services/rubyamf_controller.rb file to the test_hello_world/app/controllers directory.- As per Aaron's note below, use the rails installer. Type ruby script/plugin install http://rubyamf.googlecode.com/svn/trunk/rubyamf
- Start the Rails app from Locomotive.
- Test the RubyAMF gateway at http://localhost:3000/rubyamf/gateway.
- Generate TestWorld controller. This can be done by opening a Terminal/iTerm session in the current Rails app context via the Locomotive > Applications > Open Terminal (Command-T) item. Once that's done you can type: ruby/script/generate controller TestWorld
- Define a hello_world method in the controller to return the text string "Hello World!"
At this point the screencast goes into Flex, but I decided to make use of the Super-Simple Remoting (SSR) library from RubyAMF. I copied the source files to a folder containing my test AS3 script RemotingTest.as. Here's the contents of RemotingTest.as:
-
package
-
{
-
import flash.net.Responder;
-
import flash.display.Sprite;
-
import org.rubyamf.remoting.ssr.*;
-
-
public class RemotingTest extends Sprite
-
{
-
private var rs:RemotingService;
-
-
function RemotingTest()
-
{
-
init();
-
}
-
-
private function init():void
-
{
-
trace("RemotingTest::init() ");
-
rs = new RemotingService("http://localhost:3000/rubyamf/gateway", "TestWorldController");
-
rs.hello_world([], onResult, onFault);
-
}
-
-
private function onResult(re:ResultEvent):void
-
{
-
trace("RemotingTest::onResult() " + re.result.toString());
-
}
-
-
private function onFault(fault:FaultEvent):void
-
{
-
trace("onFault: " + fault);
-
}
-
-
}
-
}
Note that when we create an instance of the Remoting service we pass it the path to the gateway, and the name of the controller which we just created (TestWorldController). Once that is defined we can then just call methods in that controller like so:
rs.hello_world([], onResult, onFault);
The empty array parameter is there because the method accepts no parameters.
I merely had the result piped to trace output, but you can have it piped to an onscreen text field as well if you don't have logging set up.
I was using the still-in-development AS3/Flex bundle (more on installing/modifying that in a following post) to compile RemotingTest.as into a SWF, but you should be able to link it as a document class to an FLA and generate the SWF that way.
Locomotive on Rails, with MAMP as a Caboose
Update 2008-07-14: Looks like Locomotive is no longer being distributed, since OS X 10.5 now ships with Ruby on Rails installed.
Pretty soon we'll have a framework called "ChooChoo" just to take this metaphor to its logical demise. I've just started dipping my toe into Ruby on Rails, and have found it relatively easy to get up and running on OS X. I've been using a combination of MAMP and Locomotive. MAMP, of course, is the Macintosh/Apache/MySQL/PHP app that takes the pain out of setting up those respective components and allows you to focus on writing code. Locomotive is similar in that it takes care of setting up your Rails environment so you can start developing. In this situation MAMP is only being used for the MySQL component. I have a feeling Locomotive will eventually have this as part of its package, making things even easier.
There were two things I needed to do to get my setup working smoothly:
- Tell Locomotive to use MAMP for MySQL. I did this by going to Locomotive > Preferences > Terminal and putting "/Applications/MAMP/db/mysql/" in the Additional Paths field.
- From this tip at aralbakan.com: adding a socket definition to my database config file - “socket: /Applications/MAMP/tmp/mysql/mysql.sock”
I like that you can open up a terminal session from Locomotive and it'll set the context to be the Locomotive Rails environment - this way I don't have to mess with setting up my PATH to point to the Locomotive's Ruby instead of the default OS X one.
TextMate, of course, makes working with Ruby/Rails quite easy. I've been spending some time in Flex Builder lately, and coming back to the TextMate environment is a breath of cleaner, simpler air.
This was the tutorial I started out with: Using Ruby on Rails for Web Development on Mac OS X.
I also ran through the Merb/AIR tutorial here: Merb on AIR - Drag and Drop Multiple File Upload. Merb isn't Rails per se, but the example illustrates the way that Ruby apps can be used with AIR/Flash applications.
AS3/Flex Review Bundle Installation
This will probably be in the next official release of TextMate, but until then I've been testing out the AS3/Flex bundle that's in development. Instructions for installation are available here. The only catch was that I had to explicitly set the path to my svn command in the script to '/usr/local/bin/svn'.
The bundle itself is nice. It's good to have more snippets and autocompletion options (especially for stuff like method and variable declarations). The debug menu also can pop open the flashlog.txt file in the console, which is nice for tracing from the browser.
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:
-
#!/usr/bin/env ruby
-
#
-
# Ale Muñoz <ale@bomberstudios.com> - 2006-11-25
-
# Feel free to use and improve...
-
-
require "#{ENV["TM_SUPPORT_PATH"]}/lib/web_preview"
-
require "rexml/document"
-
-
WORD = ENV['TM_CURRENT_WORD']
-
HELPDIR = ENV['TM_FLASH_HELP']
-
HELPTOC = 'help_toc.xml'
-
-
# Help dir not set?
-
if !HELPDIR
-
puts html_head(
-
:title => "Error!",
-
:subtitle => "Find in ActionScript Dictionary"
-
)
-
puts <<HEREDOC
-
<h1>Search failed for #{WORD}</h1>
-
<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>
-
<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>
-
<p>Macromedia have made this tricky and the files arent always in the same place.</p>
-
<p>Try clicking the following links:
-
<ul>
-
<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>
-
<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>
-
<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>
-
<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>
-
</ul>
-
<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.
-
HEREDOC
-
html_footer
-
else
-
-
# Open TOC...
-
toc_lines = IO.readlines(HELPDIR + "/" + HELPTOC)
-
-
# ...find matching lines...
-
search_results = []
-
toc_lines.each do |line|
-
search_results <<line.strip if line[/name=\"#{WORD}/]
-
end
-
puts html_head( :title => "Documentation for ‘#{WORD}’", :sub_title => "ActionScript Dictionary" )
-
# ...parse results for links...
-
links = []
-
puts "<ul>"
-
search_results.each do |line|
-
xml_line = REXML::Document.new(line)
-
puts "<li><a href=\"tm-file:///#{HELPDIR}/#{xml_line.root.attributes['href']}\">#{xml_line.root.attributes['name']}</a></li>"
-
end
-
puts "</ul>"
-
-
# ...or display error if no matches
-
puts "No results :(" if search_results.size == 0
-
-
html_footer
-
-
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.







