Howtos

Table of Contents:


Please add all your clever howtos, if you discovered what it takes.

How to use current date and full user name in templates: http://one.textdrive.com/pipermail/textmate/2004-October/000472.html

How to launch TextMate from the shell reading from stdin: http://one.textdrive.com/pipermail/textmate/2004-October/000323.html

How to embed the word/selection in an arbitrary start/stop tag: http://one.textdrive.com/pipermail/textmate/2004-October/000362.html

How to obtain beta versions: http://one.textdrive.com/pipermail/textmate/2004-October/000491.html

Useful Commands

  • Double Slash Comments
    • sed 's/^.*/\/\/&/'
    • A simpler way: sed 's=^=//='
  • Double Slash UnComment
    • sed 's/^[ \t]*\/\/\(.*\)/\1/'
    • A simpler way: sed 's=^[ \t]*//=='

Sum all numbers following a '$', useful for adding costs - Jim Bagrow

This just goes through the selected text and adds up all the numbers that follow a '$', simple way to add up costs. Wrote it in python, I'm sure it can be done MUCH more compactly in something more appropriate. Feel free to improve!

  
- Save: Nothing
- Command:  #!/usr/bin/python

            import os
	    import re

	    # get selected text from shell:
	    text = os.getenv('TM_SELECTED_TEXT')

	    # find all numbers following a $ in selection:
	    p = re.compile('\$[-+]?([0-9]*\.[0-9]+|[0-9]+)')

	    result = p.findall(text)
	    sum_num = sum([float(i) for i in result])
	    result = ["$"+i for i in result]

	    output_str = " + ".join(result)

	    print "Sum of costs in selected text:"
	    print output_str, "= $"+str(sum_num)

- Std In: Selected text
- Std out: Insert after selected text
 

Add prefix and suffix to lines - Sune Simonsen

  
- Save: Nothing
- Command:  sed 's/^/${1:prefix}/' | sed 's/$/${2:suffix}/' 
- Std In: Selected text
- Std out: Insert as snippet 
 

Clickable Function List - Eric Hsu

A command to give you a clickable function list in a seperate window. Replace "^sub " with whatever pattern is applicable for your language.

  
- before: Do Nothing
- Command:  grep -n "^sub "
- Std In: Entire document
- Std out: Show in separate win
- Pattern: ^(\d+):(.*)$
  [this parses out the grep output so we can identify the line part]
- Format: $2
- Line:1
 

Here's a version of that more useful with PHP 5 (compatible w/ PHP 4 functions, too)... Sorry the pattern's so wide; anyone with a bit more regexp experience think they can cut that down a bit? I couldn't get \s to work with grep. =/

  
- Before: Do Nothing
- Command: grep -n '^[[:space:]]*\(public\|private\|protected\)\?\([[:space:]]\+static\|
           [[:space:]]\+abstract\)\?[[:space:]]\+function'
- Std In: Entire Document
- Std out: Show in separate win
- Pattern: ^(\d+):\s(public|private|protected)?(\s+static|\s+abstract)?
           \s+function\s+([_A-Za-z][_A-Za-z0-9]*)\s*[(](.*)[)]
- Format: $2$3 $4\( $5 \)
- Line: 1
 

Automatically backup your file each time you save - Michael Lehmkuhl

A command to enable automatic backup copies of edited files, a la BBEdit's "Make Backup Before Saving" preference.

The Setup: Set up a TM_BACKUP_DIR environment variable in the Advanced / Shell Variables
section of the TM preferences. Set it to the directory where you'd like your backups to be saved.
Use the full path (i.e., /Users/michael/Documents rather than ~/Documents).
Save: Current File
Command(s):
# Save a copy of this file to the backup directory
THEDATE=`php -r 'print date('Ymd');'`
THETIME=`php -r 'print date('His');'`
mkdir -p "$TM_BACKUP_DIR/$THEDATE"
perl -e 'while (<STDIN>) { print $_; }' > "$TM_BACKUP_DIR/$THEDATE/$TM_FILENAME.$THEDATE.$THETIME.backup"
Std In: Entire Document
Std Out: Discard
Activation: Key Equivalent Cmd-S

(Commands to do the same thing without invoking PHP or Perl.)

Now each time you save with Cmd-S, TM will also save a copy of the file into your $TM_BACKUP_DIR. It will also organize them into folders for each day at save time.

You may want to run some sort of cron job to clean out the older files in the directory.

Or you add a "du -hd 0 "$TM_BACKUP_DIR"" and output to a tooltip to keep track of the size of you backupdir.

Scratch another item off my TextMate wishlist.

Automatically back you files to a RCS repository each time you save. - Gautam Dey

This based on the Backup On Save tip. However, I wanted my backup to use RCS, which comes pre-installed on the OS X. (At least with Tiger. Don't know about the older versions.) So, I wrote up this command, at current it creates an RCS directory in the same folder as the file, and check's in the file to that directory. It also rechecks out the file. following command:

  Save: Current File 
Command(s):
# Check to see if the directory exists, if not create it. [[ -d RCS ]] || mkdir RCS # Ask for a Log message. res=$(CocoaDialog inputbox \ --title "Message for rcs" \ --informative-text "Message for rcs:" \ --button1 "Okay" \ --button2 "Cancel") # If user canceled exit. [[ $( (tail -r <<<"$res") | tail -n1) == "2" ]] && \ exit_discard res=$(tail -n1 <<<"$res") ci -l -m"$res" $TM_FILEPATH

Std In: None
Std Out: Show as Tooltip
Activation: Key Equivalent Cmd-S

Now every time you save with Cmd-S, TM will prompt you with a dialog box asking for a log message and checkin the file, and recheck it out. If you include the $Id$ and $Log$ tags you can see the information about the revision and pervious log messages.

Automatically strip trailing whitespace each time you save - Albert Davidson Chou

In every editor I use that has a setting to strip trailing whitespace on save, I enable it. TextMate doesn't have one, but it does have a command to strip trailing whitespace, so you can make a copy of that command and set its key equivalent to Cmd-S to get the same functionality:

Save: Nothing
Command(s):
perl -pe 's/[\t ]+$//g'
Std In: Entire Document
Std Out: Replace Document
Activation: Key Equivalent Cmd-S

The command above only strips whitespace. ie the file never gets saved. Following script should strip the whitespace and then save (Note: requires rb-appscript gem)

Save: Nothing
Command(s):

require 'rubygems'
require 'appscript'
class TextMate
  include Appscript
  def self.save_current
    doc = Application.by_name('TextMate').documents[0]
    if doc.modified.get
      doc_alias = MacTypes::Alias.path(doc.path.get)
      doc.save(:in => doc_alias)
    end
  end
end

doc_text = STDIN.read
puts doc_text.gsub(/[\t ]+$/, '')

TextMate.save_current

Std In: Entire Document
Std Out: Replace Document
Activation: Key Equivalent Cmd-S

Look up the current word at www.dict.org. - johnatl

 The word does not have to be selected.

You will need to install the dict command. This is simple with port from DarwinPorts. Once dict is installed, create a New Command with the following:

  
Save: Nothing
Command(s): dict "$TM_CURRENT_WORD"
Input: Selected Text or Word
Output: Show as Tool Tip
 

I use Ctrl+Help as the Key Equivalent.

Change Leading Spaces To Tabs - M Spreij

Bit of PHP code that does what the title says.. you can change the number of spaces one tab will replace. Leftover spaces will stay put.
Input: Selected Text
Output: Replace Selected Text

  
#!/usr/bin/php
<?php
# set this to what you want
$tablength = 2;

while ($fetch = fread(STDIN, 1000)) $data .= $fetch;
if (! $data) exit;

$output = '';
foreach(explode("\n", $data) as $line) {
  $len = floor(strspn($line, " ") / $tablength);
  $output .= str_repeat("\t", $len) . substr($line, $tablength * $len) . "\n";
}
echo substr($output, 0, -1);
?>

Change the tabsize of soft-tab files - Arnar Birgisson

This python command takes every 3 spaces at the beginning of a line and adds one more, effectively moving from 3sp soft-tabs to 4sp ones. Change the numbers at will, although you need to change it more if you want to decrease the tabsize.
Input: Selected Text or Document
Output: Replace Selected Text

  
#!/usr/bin/env python

import os
import re
from sys import stdout, stdin, exit

r = re.compile('^( +)')

for line in stdin:
    m = r.match(line)
    if m:
        c = len(m.group(1))
        stdout.write(' ' * (c/3))
    stdout.write(line)

Decode a block of quoted-printable text - Michael Lehmkuhl

This command gives you a quick way to decode quoted-printable text, like if you copy it from the source of a multi-part email message, for example. download the command

Time Tracking

matewatch

You can use *matewatch* to automatically track time spent in documents in Textmate. For more info go here

TimeTap

TimeTap: the unobtrusive time tracking for TextMate It stays in background and presents your stats in a useful web interface. Install it from Rubygems.org.

Template Authoring

Formatting Dates in Templates

Default templates contain this code:

TM_DATE=`date +%Y-%m-%d`

which produces a date like "2008-10-07"

To format your own dates (such as "10/7/2008"), use the formatting codes for the Unix date command. See Wikipedia.

To put spaces in your formatting code (such as in "7 October 2008"), you need to wrap your formatting codes in double quotes:

TM_DATE=`date +"%e %B %Y"`

To the uninitiated (such as myself) that doesn't look like it should work, but it saves the day.

PHP Tricks

PHP code completion - Ian White

I've created a couple of scripts that give the effect of code completion. Description and download at http://ian.ardes.com/phpcc

PHP documentation command for selected word:

  
Before running command: do nothing
Command(s): open http://nl.php.net/$TM_CURRENT_WORD
Standard in/output: None/Discard
 

PHP Documentation - M Spreij

I created a PHP shell script that will get just the first few lines (function name, php versions and syntax format) from http://php.net, it was a snap to tie it to a tooltip command as well:

  
Before running command: do nothing
Command(s): ~/bin/pdoc $TM_CURRENT_WORD
Standard input: Selected Text
Standard output: Show as tooltip
 

Example image

And this opens the doc page in the browser:

  
Before running command: do nothing
Command(s): open http://php.net/$TM_CURRENT_WORD
Standard in/output: None/Discard
 

Update: I have updated M.Spreij's pdoc to further refine this great functionality. You can grab the source here.


PHP Project Functions - Dion Almaer

Goes through the project directory and groks out all functions. If you select some text it will narrow it to that.

  
Before running command: Nothing
Command(s): grep -E -n -r --include=\*.php --exclude=.svn "function ${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}\w+\s*\(" ${TM_PROJECT_DIRECTORY:-$TM_DIRECTORY}
Standard input: None
Standard output: Show in separate window
Pattern: ^(.+):(\d+):(.*)$
Format String: $1, line $2: $3
File Register: 1
Line: 2
 

Run PHP, show as HTML - M Spreij

Runs the PHP code in the [unsaved] HTML document, then shows the result rendered as HTML.

  
Input: Entire Document
Output: Show as HTML
Scope selector: text.html, source.php

Command:
#!/usr/bin/php
<?php
$data = '';
while ($tmp = fread(STDIN, 1000)) $data .= $tmp;
if (! $data) return false;

$data = "?>$data<?php";
eval($data);
 

List Functions in Page - M Spreij

Collects all defined functions (name+params) in the document and inserts a commented-out list of them at caret's position, right padded with spaces lined up to 5 columns after the longest name+(params).

  
Input: Entire Document
Output: Insert as Text
Scope: source.php, source.js

Command:
#!/usr/bin/php
<?php

while ($fetch = fread(STDIN, 1000)) $data .= $fetch;
if (! $data) exit;

if (preg_match_all("/function (.*) {/", $data, $matches)) {
  unset($matches[0]);
  $matches = $matches[1];
  echo "/** -- Functions -------------------------\n * \n";
  $postfix = max(array_map('strlen', $matches)) + 7;
  foreach($matches as $match) {
    echo str_pad(' * '. $match, $postfix) . "\n";
  }
  echo " * \n * \n**/\n";
}
 

Applescript

Open Terminal Here - Sam Stephenson

Opens a Terminal window in the current file's directory.

Before running command: Do nothing
Command(s):
osascript -e "tell application \"Terminal\"
activate
set dir to \"$(echo $TM_DIRECTORY | sed 's,[\\"],\\&,g')\"
do script \"cd \" & quoted form of dir
end tell"
Standard input: None
Standard output: Discard

Open iTerm Here - William Scott

Opens an iTerm tabbed window in the current file's directory.

Before running command: Do nothing
Command(s):
osascript <<EOF
tell application "iTerm"
make new terminal
tell the first terminal
activate current session
launch session "Default Session"
tell the last session
write text "cd '$TM_DIRECTORY'; clear; pwd"
end tell
end tell
end tell
EOF
Standard input: None
Standard output: Discard

Finder Toolbar Icon - William Scott

Save this as an AppleScript application, give it a nice icon, and put it in the Finder toolbar. Clicking it opens a TextMate project corresponding to the directory displayed in the Finder.

  
try
	tell application "Finder" to set the source_folder to (folder of the front window)
on error -- no open folder windows
	set the source_folder to path to desktop folder as alias
	set source to source_folder as alias
end try

if kind of source_folder = "folder" then
	set source to source_folder as alias
	set ThePath to (POSIX path of the source as string)
else
	set the source_folder to the folder of source_folder
	set source to source_folder as alias
	set ThePath to (POSIX path of source as string)
	set the result to ThePath
end if
set TheCommand to "open -a TextMate  " & quoted form of ThePath
do shell script TheCommand
 

Applescript to open the current file in an arbitrary application - Jeroen van der Ham

Perhaps this is peanuts for people who know Applescript, but I searched for a couple of hours before I could find how to use Unix-style filepaths in an applescript:

  
osascript -e "tell application \"Preview\"
	activate
	open POSIX file \"${TM_FILEPATH\"
end tell"
 

This command be useful for example when editing .tex files, running latex over it and previewing the resulting PDF in one go. In which case you need to replace the extension as well, so then you should use the line below.

  
	open POSIX file \"${TM_FILEPATH%/.tex/.pdf}\"
 

This didn't work for me. I used:

  
        open POSIX file \"${TM_FILEPATH%.tex}.pdf\"
 

instead.

Applescript to trigger Interarchy Auto Upload with command - Provided by Alan Odgaard

This neat line of code sends the active TextMate file to Interarchy. If the file is on an auto-upload path, you can publish the file with a simple keystroke.

  
osascript -e 'tell app "Interarchy" to open POSIX file "'"$TM_FILEPATH"'"'
 

Applescript to trigger Transmit "DockSend" with command - Provided by natebeaty

This line of code sends the active TextMate file to Transmit. If the file is on a path specified in a DockSend-enabled favorite, the file will be automatically uploaded to the server.

  
osascript -e 'tell app "Transmit" to open POSIX file "'"$TM_FILEPATH"'"'
 

Look up current word (doesn't need to be selected) in dictionary (10.4+ only) -- Provided by pbx

There's a more simpleminded way to do this, namely the dict:// pseudo-protocol, but it requires Dictionary to be already running and it fails when an exact match is not found. This solution overcomes both those problems.

Input: none; Output: Do Nothing

  
    # Adapted from: http://daringfireball.net/2005/05/dictionary_bbedit
    osascript -e "tell application \"Dictionary\" to activate
       tell application \"System Events\"
          tell process \"Dictionary\"
             tell text field 1 of group 1 of tool bar 1 of window \"Dictionary and Thesaurus\"
                keystroke \"$TM_CURRENT_WORD\"
                keystroke return
             end tell
          end tell
       end tell"

osascript, shell script, UTF-8 - Hans-Jörg Bibiko

TextMate's internal encoding is UTF-8. This is also true for the Bundle Editor. But, how to deal with UTF-8 encoded text files or variables by writing a shell command in the Bundle Editor if osascript only expects data encoded in MacRoman?

Example:

  • Read the UTF-8 encoded content of a file and insert it into an other document window without loosing the focus.

Before running command: Do nothing
Command(s):
# open/activate the target
mate ~/target.txt

# read the UTF-8 encode text coming from ~/test.txt
TXT=$(cat ~/test.txt)

# now comes the trick
cat <<-AS | iconv -f UTF-8 -t MACROMAN | osascript --
tell application "TextMate" to insert "$TXT"
tell application "System Events" to keystroke "\`" using (command down)
AS
Standard input: None
Standard output: Discard

osascript expects AppleScript commands encoded in MacRoman. This is simply done by using iconv. The actual UTF-8 data stored in $TXT are passed to osascript simply by bash shell's variable expansion facility.

HTML

Get Image Size

This gets an image's width/height using a command and puts it into a tooltip. (make sure you select the image filename relative to the current document)

  
- Before command: do nothing
- Command: sips -g pixelWidth -g pixelHeight $TM_SELECTED_TEXT
- Standard Input: Selected Text  
- Standard Output: Show as tooltip
 

-- Ben Parzybok

Wrap All Paragraphs with p

If you're switching to TextMate from BBEdit and you do a lot of HTML content creation, you may be bummed to find that the "wrap selection in open/close tags" bundle item wraps the whole selection in p, rather than detecting each individual paragraph, as BBEdit does. To make this work as expected, open the Bundle editor. Select the bundle "Wrap each selected Line in Open/Close Tag" and duplicate it. Rename it something like "Wrap paragraphs." Edit the duplicate to use p rather than li. Give it a key equivalent (I use Cmd-P, since this is such a common action). -- S Hacker

Access Color Palette

TextMate doesn't have a color palette under one of the menus, but you can use the one from the Preferences.. Open the Preferences, go to "Fonts & Colors", click any of the color rectangles *twice* - once to bring up the color palette and again to deselect the rectangle - and close the Preferences window again. Now you can use the color palette to choose a color and drag it into the editing window as a Web #RGB code! -- M Spreij

If you have Interface Builder (part of the dev tools) you can open up TextMate's MainMenu.nib and create a menu item that opens the color window. It's easiest to open a "new" IB nib selecting the "cocoa application" template, go copy the menu item you want "show colors" and then paste it into TextMate's menu nib. Save and open TextMate and test it out. -- Tim Martin

There is an "Insert color…" command in the CSS bundle that surely works also for other scopes. Selecting a color hex code and calling upon Cmd-Shift-C will bring up a color selector with that color with which one can change the color. Clicking okay will replace the old hex code. Besides the occasional beach ball it is working fine for me. --anarchitect

Reformat HTML-TextMate

Here's my modification of FHTML, a Perl script that re-formats HTML to be more human readable.

(I give it the key command: Command-Option-Shift-F to match BBEdit's "reformat HTML code" command.) Note the new link to Snipplr.

http://snipplr.com/view/28256/fhtml-for-textmate/

Preview in Safari - Yvan BARTHÉLEMY

If you want a JavaScript aware previewer, you probably want to use Safari or Firefox to preview your page rather than the built-in previewer.

First, copy this shell script somewhere on your filesystem

#!/bin/bash --posix
tee /tmp/saf_tmp.html

osascript -e "tell application \"Safari\" to open location \"file:///tmp/saf_tmp.html\""

Of course you might replace Safari with any browser of your choice, and modify this script to allow choosing browser using a command-line argument.

Then, open the TextMate Web Preview, check the checkbox : Pipe Text trough,

then paste 'sh' followed with the path to your script (e.g. 'sh ~/Documents/script/browser.sh')

Actionscript

Macromedia AS Dictionary integration

The following link is broken, if someone has another resource, please post it.
http://www.partlyhuman.com/wordpress/archives/2005/02/07/textmate-flash-help-integration/

A new link for AS Dictionary integration: http://www.dirtystylus.com/blog/2007/04/24/enabling-actionscript-help-in-textmate/

The following two links are also broken, if someone has another resource, please post it.
!!! Building a Project in Flash http://www.partlyhuman.com/wordpress/archives/2005/02/07/building-flash-in-textmate/ An update of the apparently deprecated method described here. Requires flashcommand: http://weblogs.macromedia.com/mesh/archives/2004/02/flashcommand_fl_1.cfm

Using Textmate, MTASC and XTrace to build Flash projects

http://www.monokai.nl/blog/2006/07/14/using-textmate-mtasc-and-xtrace-to-build-flash-projects-in-mac-osx/

Create Getters/Setters - Jason Froderman

  
- Save: Nothing
- Command:
## Run preg_replace to take variable declarations
## and create getter/setter method

php -r 'echo preg_replace("|(\w+) (\w+) (\w+):(\w+);|e", '"\npublic function get".ucfirst($3)."():$4 {\n\treturn $3; \n}\n\n$1 function set".ucfirst($3)."($3:$4):Void {\n\tthis.$3 = $3;\n}"', file_get_contents("/dev/stdin") );'; 
- Input: Selected text
- Output: Insert as text 
 

http://froderman.com/index.php?option=com_content&task=view&id=25&Itemid=48

Create Getters/Setters 2 - Marc Bauer

Another way to create getters/setters in ActionScript2 described here

LaTeX

Case-insensitive BibTeX search terms

One very useful command in the LaTeX bundle is "Citation based on current word/selection" (bound by default to Option-Escape). BibTeX entries, however, typically have all meaningful words capitalized, meaning that in order for "Citation based on current word/selection" to work properly in its default configuration, you must capitalize your search term, as the search functionality uses grep. If you'd like to be able to use this function in a case-insensitive way, there are (at least) two options, each of which involves editing the command in the Bundle Editor. (1) You can make the search case-insensitive by adding a parameter to the grep command: edit the line that begins items = items.grep(/#{phrase}/) so that it instead begins items = items.grep(/#{phrase}/i). (2) You can have TextMate capitalize your current word/selection before performing the BibTeX search. To do this, edit the fifth line in the command: instead of phrase = STDIN.read.chomp, change it to phrase = STDIN.read.capitalize.chomp. Note, though, that this second method will miss any search terms that aren't capitalized in your .bib file, so the first method is probably preferable. Either way, you should now be able to use "Citation based on current word/selection" without having to worry about capitalizing your BibTeX search terms. --Nick Fleisher

Find class or method definition

 - Input: Selected Text or Word
 - Command: grep "[def|class] $TM_SELECTED_TEXT" -l -n -d recurse $TM_PROJECT_DIRECTORY
 - Output: Show as tooltip
 - Activation: Key Equivalent: Cmd+F1

Lookup class or method definition (2)

- Input: Selected Text OR Word

- Command:
 #!/bin/bash
SEARCHPATH=$(test -x "$TM_PROJECT_DIRECTORY" && echo "$TM_PROJECT_DIRECTORY" || echo $(dirname "$TM_FILEPATH") )
STARTPATTERN="^([[:space:]]|;)*(def|class)([[:space:]]|;)+$TM_CURRENT_WORD([^A-Za-z0-9_].*)*$"
ENDPATTERN="^([[:space:]]|;)*end([[:space:]]|;)*"
(egrep -ns "$STARTPATTERN" "$TM_FILEPATH" || egrep -nsR "$STARTPATTERN" --exclude="*.svn*" "$SEARCHPATH") |cut -d: -f-2
find "$TM_FILEPATH" "$SEARCHPATH" -type f -name '*.rb' -exec sed -En "/$STARTPATTERN/,/$ENDPATTERN/p" {} \; |sed -E "/$ENDPATTERN/q" 
 - Output: Show as tooltip
 - Activation: Key Equivalent: CTRL+]

Check this post: http://claudiofloreani.blogspot.com/2011/10/add-shortcut-to-textmate-to-lookup.html

Python

Textmate-Ropy AutoCompletion - Ikuta Lin

 - Install rope
 - hg clone http://bitbucket.org/agr/rope/
 - sudo easy_install rope
 - Install  Textmate-Ropy 
 - svn checkout http://textmate-ropy.googlecode.com/svn/trunk/ textmate-ropy-read-only
 - C-P - Autocompletion
 - C-] - Search class or methond defination

Tricks for Japanese users

You can input a backslash on a Japanese keyboard by holding option and pressing the yen (¥) key.

Integration with Firefox

You can use TextMate to edit text areas (forms) in Firefox. This comes in handy when you have to work a lot with CMS software that is only programmable via web interfaces.

  1. get a hacked-up version of mozex from https://nic-nac-project.de/~kaosmos/mozex107-en.html and install it by dragging the .xpi onto the browser
  2. get mozex-helper from http://www.noctua.org.uk/paul/software/, read the documentation and install it;
    set editor_command to "/usr/bin/mate -w %s"
  3. in Firefox->Tools->Extension Manager->mozex->Preferences set up the temp directory according to your setting in "mozex-helper.py" and the text area editor to the "mozex-helper" wrapper
  4. done, you can edit text areas with TextMate by right-clicking->mozex->Edit textarea

--Karsten W Rohrbach

Addendum to integrating with Firefox 1.5

  1. Go to http://mozex.mozdev.org/development.html and download the (currently development version) MozEx 2.0 and install it into Firefox.
  2. Go into the extension preferences (Firefox->Tools->Extension Manager->mozex->Preferences). In the "Textarea" tab put: "/usr/bin/mate -w %t" (or whichever path you chose when you created the symbolic link to mate through TextMate).

In OS X: In the "Textarea" tab put:

   
/Applications/TextMate.app/Contents/Resources/mate -w %t 
 

You can now edit textareas by right clicking and choosing MozEx ->Edit textarea. The text will open up in TextMate which you can then edit. When you have finished and saved the file, you just need save the file or, click in the textarea for the contents to update with the changes you made in TextMate video game parts.

Addendum to the addendum (works in FF2, FF3)

  1. Go to https://addons.mozilla.org/en-US/firefox/addon/4125 and install the current version of It's All Text!
  2. Once you've restarted Firefox, go to the prefs for It's All Text! and set the editor path to "/Applications/TextMate.app/Contents/Resources/mate".

Is there any way to persuade this to work with the CSS Editor (in the Web Developer extension) ?

Unclear - this would make temporary changes to the currently-loaded page's style? How sweeping do such edits need to be (that is, do they require TextMate)?

Integration with Thunderbird

You can use TextMate to edit emails from Thunderbird.

  1. Get a copy of the External Editor extension from http://globs.org/articles.php?lng=en&pg=2 and install it from the Tools -> Extensions dialog in Thunderbird
  2. Follow the installation instructions on the page
  3. Set the editor to /usr/bin/mate -w in the extension preferences

How to extend an existing bundle

If you want to extend a language grammar and/or change the behavior of one bundle without actually modifying that bundle itself (i.e. you would like to keep your changes separate from the bundle's original code) you will need to do the following:

  1. create a new bundle
  2. create a new language grammar. give it a scope name of your.original.scope.someextension:
    e.g. scopeName = 'text.plain.mail.custom';
  3. add your own language grammar, possibly overriding stuff that is in the bundle
  4. at the end of the language grammar include the original bundle like this:
    { include = 'text.plain.mail'; },

How to set the default language for new (untitled) documents

Instructions are in this letter from the mailing list.

How to re-open with more than the default encodings

This can be done by using iconv, see this letter for an example bundle which adds new re-open with encoding commands through a bundle.

Subversion Checkout

Not sure how useful this is to other people. But I have written a command for the Subversion bundle that lets me do a checkout. It asks for the url and then where to save it. Progress bar appears while checkout happens. Once done, then opens project in TextMate. The url format I have for my host is svn-ssh:// not sure how similar that is for other users.

Save: Nothing
Command(s):

  
# Setup Dialog asking for host
url=$(CocoaDialog inputbox \
    --title "Checkout..." \
    --informative-text "Enter the host:" \
    --text "svn+ssh://" \
    --button1 "Checkout" \
    --button2 "Cancel")

# If user canceled exit.
[[ $( (tail -r <<<"$url") | tail -n1)  == "2" ]] && \
         exit_discard

# url contains the url entered
url=$(tail -n1 <<<"$url")

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #

# Setup Dialog asking where to save
location=$(CocoaDialog fileselect \
    --text "Select Folder to Checkout to" \
    --select-only-directories \
    --with-directory "~/")

# If user canceled exit.
[[ $( (tail -r <<<"$location") | tail -n1)  == "2" ]] && \
         exit_discard

# location contains the location selected
location=$(tail -n1 <<<"$location")

res=$({
    cd $location
    svn checkout --quiet $url
} > >(CocoaDialog progressbar \
    --indeterminate \
    --title "Checking Out" \
    --text "Please wait, this could take some time"))

project=`basename $url`

open -b com.macromates.TextMate "$location/$project"

Std In: None
Std Out: Insert as Snippet
Activation: Key Equivalent Ctrl-Shft-A

Any queries contact my gmail.com account. avenjamin is the username. (You guys are smart enough to work out my email address from that)

How to edit remote files using macfuse and sshfs - Christian Tan

One major annoyance for me was being unable to use textmate project management for files on my server. I used to use cyberduck with textmate, which works ok, but this one is more conveniant:

Install macfuse

Mount your remote server using sshfs:

 sshfs user@servername:/ ~/mnt/servername -o'ping_diskarb,volname=servername'

Now on the commandline on my laptop, I go to any file in ~/mnt/servername/ and do: mate <filename> and I can just add files to a projectdrawer in textmate. Best of all is that you do not need to prepare anything on your server if it is already running ssh.

If you are done, unmount the Volume by clicking on the regular eject icon in Finder or type the following in your Terminal:

 umount ~/mnt/servername

If you have problems with TextMate and sshfs (more sshfs than TextMate) crashing your computer, turn off the sshfs cache by adding 'cache=no,' to the above command before 'volname'. Later versions of sshfs can cache file changes for up to 20 seconds, which is often annoying.

How to exclude files and folders from the Project Drawer

Textmate naturally doesn't display certain files and folders in the project view. For example, .svn and .git folders, and .pyc files.

1. Select the root folder of your project within the project drawer.

2. Click the 'i' button in the bottom right of the project drawer.

3. There are two text areas for regular expressions which control the files and folders displayed.

Example regex: to hide all compiled java classes (.class files), use this regex as a File Pattern: !\.class$

Steve King adds: You can do this globally instead of project-by-project by opening the Preferences window and going to "Advanced", "Folder References".

How to use timed autosave with Textmate

Textmate doesn't include timed autosave. I thought that feature would simplify my workflow with typing LaTeX documents.

In conjunction with latexmk, autosaving allows almost for an WSIWYG environment (More details about the continuous monitoring ability of latexmk: http://jon.smajda.com/blog/2008/03/08/latexmk/). You avoid the need save the document yourself and by that invoke latexmk.

Make autosaving work with Textmate:

1. Get the freeware Eversave from http://www.tool-forcesw.com/eversave/ and install it

2. In preference of Eversave: Under "When should Eversave save:" pick "Time-controlled"

3. Under "Automatically save these applications" pick Textmate

4. Under "Timer" set how fast you want it to be saved (for the LaTeX application I mentioned earlier, it should be <5s)

5. CRUCIAL: under "Please choose a save method" pick "Save by simulating save shortcut (more compatible)" as the other method does NOT work with Textmate (it will invoke the "Save as" command instead of the "Save" command, which is useless for our (most) purposes).

That's it.

LaTeX

Whole word search

Whole word search meaning that when searching for "Message" you will not find "sendMessages" too, just occurrences where "Message" is the whole word.

This can be done by searching for a regular expression where "\b" (word separator) is prepended and appended to the searched word. i.e searching for "\bMessage\b" instead of "Message".

How To Cut Short the Wait for TextMate 2

Are you fed up with waiting for TextMate 2?
Would you like to run the mythical editor right now?

Here's how to do it on Mac OS X. Just follow these three easy steps:

1. Design and code a clone of TextMate. Be careful! Your app needs to run as well as the present one and include all announced new features to really be called TM2.

2. Put your code in a directory containing TextMate.xcodeproj

3. Compile using XCode and copy the result to /Applications.

It's as simple as that. And remember, Beethoven wrote his second symphony 6 years after his first.

-O.B.C Hashfunk's Featherweight Folio of Worthwhile Workarounds and Decorative Stitches