[TxMt] Re: Difficulty using TextMate as external editor

Steve King sking at arbor.net
Tue Jan 4 16:49:10 UTC 2011

On 2011-01-03 16:39, Ian Greig wrote:
> The "mate" command question
> Another way devised by Tinderbox users involves using a macro to call the
> "mate" command. That brings me full circle. I do not seem to be able to make
> this work, even by invoking the command line directly in Terminal. I would
> like some help with this please.

I know nothing about Tinderbox, but that's not going to keep me from 
jumping in here...

The very first thing you have to do is to install the 'mate' command.  
You say that you "do not seem to be able to make this work, even by 
invoking the command line directly in Terminal." That suggests to me 
that this first step has not been taken.  Refer to the blog posting at 
http://blog.macromates.com/2005/textmate-shell-utility-tmmate/ for 
details, but you'll need to execute these commands:

    mkdir ~/bin
    ln -s /Applications/TextMate.app/Contents/Resources/mate ~/bin/mate

There are other niceties too, but that's the basics.  Now type 
'~/bin/mate /tmp/test' at the Terminal command line.  Does it open a new 
Textmate window editing the file /tmp/test? If so, congratulations! 
You're halfway there.

In general, there are two ways to invoke 'mate' as an external editor.  
The first is as described above, by having Tinderbox (or whatever other 
app) write a temporary file and calling 'mate' to edit it.  You'll 
probably want to give 'mate' the '--wait' option. Without that option, 
the Textmate window is opened and control immediately returns to the 
caller.  Unfortunately, that's the end of the transaction. There's no 
way for the calling program to know when you're done editing.  The 
'--wait' option tells 'mate' not to return control to the caller until 
you've closed the window.  This will signal the calling program that 
it's time to read the temp file back in to get your changes.

To do it this way you'll need to write a macro in Tinderbox that does this:

    save to /tmp/filename
    mate --wait /tmp/filename
    load /tmp/filename

Since I don't know anything about Tinderbox I'm afraid I can't be any 
more specific.

The second way to use 'mate' as an external editor is similar, but 
instead of writing to a temporary file you feed the file to mate on its 
standard input and read the changes back from its standard output. 
"Standard input" (stdin) and "standard output" (stdout) are generic Unix 
terms meaning "what the program reads in from the Terminal" and "what it 
writes back to the Terminal". Only, "Terminal" doesn't have to literally 
be Terminal.app, it can be any other program. If you run the command 'ls 
| less' at the Terminal prompt you're using the pipe ("|") character to 
send the standard output of the 'ls' command to the standard input of 
the 'less' command, instead of sending the output of 'ls' directly back 
to the Terminal window. Piping stdout from one program to the stdin of 
another is the fundamental basis of almost all Unix command-line 
programing. You can chain any number of commands together this way. Try 
typing: 'echo "hello, world" | mate --wait | less' to see what I mean.

To apply this to Tinderbox you'll need to tell it to write to mate's 
standard input and read from mate's standard output. Again, I don't know 
what the syntax would be as a Tinderbox macro, but conceptually 
something like:

    mate --wait
    write file to mate's stdin
    read file from mate's stdout

I can't give you cookie-cutter directions, but hopefully this gives you 
enough understanding of what's going on to figure the rest out yourself.

Steve King
Sr. Software Engineer
Arbor Networks
+1 734 821 1461
www.arbornetworks.com <http://www.arbornetworks.com/>

More information about the textmate mailing list