De-sucking Textmate indentation
Saturday, September 27th, 2008I really, really like Textmate. It is fast, powerful, and incredibly easy to script and customize.
But it has a few incredibly annoying weaknesses. The worst of these is an abysmal indentation model. (The second worst is terrible support for large files and projects, but I haven’t solved that yet.)
Happily, I ran across this nice post to indent R files using Emacs in batch mode from Textmate. A very simple and effective idea (Emacs afficionados are of course scoffing, why not use Emacs? Why not? Because I still haven’t found the button to zap-phrase-long-counter-intuitive-command-names-out-of-the-1970s-and-into-a-modern-ui).
I did a reworking in Ruby that can handle any file type for which an Emacs mode is installed, which is specified as a command-line argument to the script. So just put the Ruby script somewhere (it probably should go in a Textmate support directory, but I just put it in a personal script dir), and then create a ‘Tidy’ command in Textmate for each desired language, specifying an appropriate file ending to tell Emacs the language. For example:
/path/to/tidy.rb cpp # C++
/path/to/tidy.rb java # Java
/path/to/tidy.rb ml # OCaml
Voilà!
Again, the script (you’ll need to rename and make executable): tidy.rb