Update: TEA for Coda documentation and other information has now moved over to One Crayon:
Textmate is a fantastic editor. Every once in a while I try a different text editor, but none of them allow me to get even close to the speed and productivity that I enjoy with Textmate.
However, I recently took another look at Coda when it was updated to version 1.5 because the update came out at the same time that a project which benefited a lot from Coda’s all-in-one interface hit my plate (gotta love remote editing with SSH access in the other split). Although nothing can salvage Coda’s craptastic CSS editing (nothing but a straight-up duplication of CSSEdit‘s fantastic auto-complete and intelligent indentation, that is) with a little Applescript I was able to emulate four of the functions from Textmate that I find absolutely critical to my coding happiness and productivity. Without further ado, I give you the Textmate Emulation Applescripts for Coda:
TEA for Coda currently offers four of my favorite actions from the Textmate HTML and Hyperlink Helper bundles (in slightly less elegant and feature-rich implementations, of course, given that it’s Applescript and Coda’s less-powerful editing environment):
- Insert Open/Close Tag: this is the functionality that I can’t live without. Just type the tag you want and run the script to have the tag automatically created and your cursor inserted inside (you can also type a tag with attributes, select it, and the script will intelligently exclude the attributes from the closing tag). The only thing that makes me sad is that Coda doesn’t have Textmate’s intelligent text indentation, so adding divs with the script is still a little frustrating.
- Tidy HTML: this runs Tidy HTML optimized to correctly indent your code rather than clean up messy code (Coda lacks automatic code indentation, and I write clean code anyway; see the Read Me for info on changing Tidy’s default options if you’d rather use it to fix Word HTML, for instance).
- Wrap Selection in Link: this mimics the basic functionality of Textmate’s Hyperlink Helper Wrap Word as Link, but without the cool automatic title attribute generation or tab controls. It will automatically grab whatever’s on the clipboard, though, making it easy to create links if you’ve copied them from elsewhere.
- Wrap Selection in Tag: use this script to wrap the selected text in an arbitrary tag. Like Textmate, it allows you to enter attributes but doesn’t stick them in the closing tag. Unlike Textmate, it forces you to use enter the tag in a dialog box; about the same speed, but much less elegant.
Make sure after installing the scripts that you customize yourself some shortcuts either using the System Preference Keyboard and Mouse area, or with a utility like FastScripts. The ReadMe includes a list of the default Textmate shortcuts for your reference if you’re a Textmate user.
Hopefully these scripts will help other people who want to leverage the awesome HTML editing capabilities of Textmate along with the all-in-one sweetness of Coda. If you’re an Applescript ninja and decide to improve on or add to the scripts, please let me know! I’d love to implement better solutions to my own workflow, and I’m a bit of an Applescript noob so the scripts could doubtless be improved.
As far as my own plans for the bundle go, I intend to add a script to emulate Textmate’s Wrap Each Selection in Open/Close Tag and I’m also hoping to increase the intelligence of some of the scripts by offloading some of the logic to shell scripts; just need to work on my Python-fu or something before that can happen.
While Coda is still a jack of all trades and master of none, the TEA for Coda bundle has at least made it usable for me on those projects where its collection of features and awesome split abilities make it a better choice than Textmate. I just hope that Panic will implement some intelligent indentation for a future version, as that’s still the most glaring omission when trying to perform basic text editing, even with TEA for Coda installed.
Minor update Sept. 1, 2008: With thanks to Brian Haslanger, Format with Em (menu title: Em) and Format with Strong (menu title: Strong) are now a part of the TEA for Coda. If you’ve already installed the bundle, just redownload, copy the
HTML/Format folder into your
~/Library/Scripts/Applications/Coda/HTML folder, and add the cmd-I and cmd-B shortcuts in System Preferences.
Minor update Sept. 2, 2008: TEA for Coda now includes the most recent version of Tidy (the HTML Tidy site provides binaries that are several years out of date). Additionally, the Tidy script will now accept selected text and only tidy that text (without inserting a bunch of useless body tags and so forth). If you don’t select any text, it will tidy the entire document. I’ve also revised the tidy_config.txt file to some more sensical defaults. Updating procedure is the same as before.
Minor update Sept. 25, 2008: TEA for Coda now has a dedicated landing page; please reference that for the most up-do-date information about the scripts. I’ve also updated the scripts with bug fixes and more, but I won’t be updating this post any more when I update the scripts down the road.
Minor update Nov. 10, 2008: So I lied about never updating this again; since this post continues to be a popular landing spot for Google, I wanted to let folks know that TEA for Coda now includes a Universal Binary version of Tidy HTML. If you’re using a PPC, definitely grab the download above and update (more info on updating in the Read Me, or here).
Minor update Nov. 11, 2008: TEA for Coda now requires Coda 1.6 (which is a free update for all Coda users), and the scripts will now perform their actions in the active document, even if there are multiple windows open.
Great work!! Thank you for giving us TEA, it is going to be very useful for me
Posted 6:18 AM on Sep. 2, 2008 ↑
Glad to hear it! Definitely let me know if you run into any problems or have any desires for future additions to the scripts; I’ll be trying to add new functionality and refine what I’ve got as time goes on.
Posted 7:11 AM on Sep. 2, 2008 ↑
Nice job! These scripts are definitely going to make my Coda life much much easier.
Posted 11:41 AM on Sep. 3, 2008 ↑
Finally! I have been lamenting the wrap selection in tag feature not being implemented.
Thanks a bunch.
Posted 3:48 PM on Sep. 3, 2008 ↑
Wow! Really, really useful, thanks. This adds to Coda a few of the Dreamweaver features that I was starting to miss; especially HTML Tidy, and the shortcuts for tags liks <strong> and <em>, which are easily duplicated to include , , and so on. Excellent. Looking forward to more updates!
Posted 8:34 PM on Sep. 3, 2008 ↑
You can add a Cocoa key binding to add tags like that in any browser. (See site linked to my name).
Assuming your comment box properly escapes < symbols:
Posted 1:41 AM on Sep. 4, 2008 ↑
Alas, it doesn’t. Well that basically said:
Posted 1:42 AM on Sep. 4, 2008 ↑
Jacob: I’d never stumbled across custom keybindings as a way to implement HTML tools before; that is indeed an interesting way to gain some powerful text editing functionality across programs.
Sadly, WordPress accepts simple HTML, so it doesn’t escape < or >. HTML entities are necessary to output HTML code.
Posted 7:09 AM on Sep. 4, 2008 ↑
I do not have a ~/Library/Scripts/ folder. Do I create one?
Posted 9:55 PM on Sep. 5, 2008 ↑
First thing to do is launch Coda, open the Preferences and in the General tab check “Show Scripts menu”. If my experience is representative, this should install the proper directory structure.
If it doesn’t, then go ahead and create the Scripts folder; that’s a common location for Applescripts to go.
Posted 6:50 AM on Sep. 6, 2008 ↑
@Ian That worked.
Thanks for the help and the scripts.
Posted 2:12 PM on Sep. 6, 2008 ↑
Ian – This script is a GODSEND! It’s nuts that Coda doesn’t support keybindings out of the box, so this goes a long way to rectify that.
One issue I have: when I use Tidy, I get this error: “sh: line 120: /Users/…/.lib/tidy: Bad CPU type in executable”
I’m on a dual G5, sounds like a compiling issue with Tidy or something?
Posted 5:36 PM on Sep. 6, 2008 ↑
Damn, I forgot about the CPU being a potential problem; I compiled Tidy on an Intel Mac using the default makefile, and I guess that made it Intel-only. Unfortunately I don’t have the know-how to compile it in a CPU-independent version (and I don’t have access to a PowerPC computer).
If you’re fairly comfortable with the command line, I can walk you through downloading and compiling Tidy for yourself on the G5. I will also take a look around the interwebs and see if I can find some help for compiling a non-Intel specific version on an Intel computer. It would be nice if I could just drop a new binary into the package and have it work for everyone.
As a last gasp solution, you could also download the several-years-out-of-date version on the Tidy website. If you do, you’ll probably need to remove some of the newer stuff in the tidy_config.txt file (not all of it is compatible with the old version of Tidy). Let me know if you need help with this.
Posted 7:48 PM on Sep. 6, 2008 ↑
Brilliant! Thanks Ian. I deal more with xml and xslt files so I duplicated your Tidy HTML script and changed the set shellscriptString line to:
set shellscriptString to "echo " & quoted form of someText & " | xmllint –format – 2>&1"
This results in Textmate equalling greatness :-)
Posted 12:04 AM on Sep. 7, 2008 ↑
These are some incredibly useful scripts. TidyHTML was exactly what I was looking for. Thank you so much for putting these out.
Posted 4:03 PM on Oct. 28, 2008 ↑
Like Steve, I’m getting the “Bad CPU” error as I am utilizing a G5 as well. My laptop is Intel but my main system for the time being is a G5 iMac.
At your leisure, I would love assistance with the command line steps to compiling an HTML Tidy version for my computer. Thanks in advance!
Posted 11:58 AM on Nov. 6, 2008 ↑
David: I’ll send you an email with compilation instructions and so forth. If we’re able to get a working PPC version of Tidy, I’ll make sure to migrate it into the TEA for Coda package.
Posted 9:42 AM on Nov. 8, 2008 ↑
Just a quick note for anyone subscribed to this comment stream: I’ve updated TEA for Coda with a Universal Binary version of Tidy. If you’re using a PPC, you should definitely grab the new version. Let me know if you run into any problems! It worked great for David (above), but I don’t have any way to test it myself.
Posted 9:25 AM on Nov. 10, 2008 ↑
thank you very much for those very handy scripts!
Coda is getting better and betterâ€¦ :-)
Posted 8:06 AM on Dec. 5, 2008 ↑
Name’s Ian, actually, but I’m glad you’re finding them useful!
Posted 9:13 AM on Dec. 5, 2008 ↑
Thanks so much for making TEA for Coda. I love Coda, but this definitely makes up for some things I miss in TextMate. I have a question for you about implementing the keyboard shortcuts for these scripts.
How many of the TextMate keyboard shortcuts for these commands were you able to replicate via the Keyboard Shortcuts preference pane?
I couldn’t manage to enter the TextMate shortcuts for “Indent New Line” or “Insert BR”, since the preference pane seems to ignore Return as a possible key combination.
I was able to get most of the other ones entered into the preference pane, and the shortcuts show up fine in the Scripts menu in Coda, but the only ones that actually work seem to be “Wrap Each Selected Line in Tag” and “Wrap Selection in Link”. These also happen to be the only two commands with the Command key.
Posted 9:14 AM on Feb. 4, 2009 ↑
Actually, all of them work for me. System preferences picks up the return key just fine on my end, and shortcuts without the command key are working great in Coda. There must be a configuration difference between your system and mine. Some possible problems:
– Running 10.4? I only have 10.5 to test on, and it’s possible Apple changed which shortcuts are considered valid.
– Are your shortcuts competing with Coda shortcuts? This is unlikely, but I know in the case of the Bold script I had to redefine the Balance shortcut in System Preferences before it would work.
– Using a non-standard keyboard setup (or non-English)? I don’t know if this would affect anything, but I know Dvorak users, for instance, often have trouble with keyboard shortcuts that Qwerty users take for granted.
I wish Coda had an in-program way to define shortcuts; it’s not only ridiculous that you have to go to the System Preferences, but there’s a bunch of stuff in Coda that doesn’t have a menu equivalent that I’d like to add shortcuts to and handling conflicts via System Preferences is a painful trial and error experience.
If you aren’t able to figure out what’s going on, feel free to drop me an email via the About page. I probably won’t be able to help much (since I can’t reproduce the problem), but I’m always willing to bounce ideas around.
Posted 9:29 AM on Feb. 4, 2009 ↑
Thanks for all the great ideas! I am still on 10.4, so that may be it. I decided to just get creative and change the shortcut keys, and they’re all working fine. Not worth wasting a day on :)
Posted 6:47 AM on Feb. 5, 2009 ↑
Another alternative. PHP Plugin on the Coda Plugins page has HTML Tidy built in.
Posted 7:04 AM on Apr. 29, 2009 ↑
I get an error “the command exited with a non-zero status” when trying to tidy..any idea? Thanks.
Posted 12:57 PM on May. 4, 2009 ↑
I love it!
Posted 2:30 AM on Jul. 10, 2009 ↑
Damn it, “that’s me” fail.
Posted 7:21 PM on Sep. 20, 2009 ↑
Given that you are not me, I’d say that’s a “that’s me” success.
Posted 9:53 PM on Sep. 20, 2009 ↑
Thanks for taking the time and writing useful scripts! I was debating weather to buy Coda or Textmate and went with Coda. The lack of html formatting really is a disappointment.
I have one problem though and it’s just like Annie’s.
I’m also getting an error “the command excited with a non-zero status”. Any ideas?
Posted 1:10 PM on Oct. 16, 2009 ↑
Odds are you’re running an OS/architecture combination that I didn’t compile for. I’m not really sure how to debug this problem, though, since I don’t have many architectures to test on and have in any case ceased to support HTML Tidy in my most recent version of TEA for Coda:
If Tidy’s an important part of your workflow, please let me know through the One Crayon contact form and I’ll help you come up with a workaround via email:
Posted 8:19 AM on Oct. 17, 2009 ↑
Thanks for the reply. Indeed, you are correct. I’m using Coda at work and my mac version is 10.4.1 so obviously this is most likely why I’m getting this “error”. I’ll try it at home, there I have the recommend OS. I’ll get back to you shortly concerning a workflow work. I appreciate your time and help!!!! Thanks!
Posted 6:27 AM on Oct. 19, 2009 ↑
cannot seem to find a html folder to follow instructions for enabling the tidy module..
ended up using coda php module to get tidy http://www.chipwreck.de/blog/software/coda-php/
Posted 10:45 AM on Dec. 30, 2009 ↑
I spent a while looking at the code for the default shortcuts, and i was wondering how to change the text expander from the default ctrl+, to a more friendly ctrl+return (^+return). i cant seem to grasp it.
if anyone has any ideas, please let me know.
Posted 9:23 PM on Feb. 5, 2010 ↑
Although I’m planning to implement a preferences screen to allow people to control this kind of thing in TEA for Coda 2, I haven’t had a chance to get it up and running yet. In the meantime, you can edit this file to change the shortcut (after right clicking the plugin and clicking Show Package Contents):
You’ll have to give another shortcut to Insert Linebreak to prevent a conflict with control-enter, too.
Posted 9:12 AM on Feb. 6, 2010 ↑
Ian, I figured out where the controls where set but I cannot figure out how to set the return as the key. It is a wonderful little plugin and just sorting this would make it even better for me. It is just that hitting the comma seems slightly strange to me.
Posted 10:04 AM on Feb. 6, 2010 ↑
oh, disregard that last comment. I figured it out. =]
Posted 10:09 AM on Feb. 6, 2010 ↑