Textmate Tips

## Add Line Breaks ##

On 20 Nov 2007, at 22:33, Robin Houston wrote:

On 20/11/2007, Frank Eves wrote:
– TextMate Soft Wrap set to 66 characters
– How do I Hard Wrap my document at 66 columns?

As far as I know, TextMate doesn’t have a built-in command to do this.
You can use Text > Filter Through Command… to run some external
formatter of your choice. Unfortunately the BSD version of fmt included
with OS X can’t quite be made to do the right thing […]

fold -sw66 though should do exactly what Frank wants. Or to make it actually use his soft wrap setting: fold -sw$TM_COLUMNS

### Using Perl:

If you don’t need to worry about dealing properly with (hard) tabs,
then you can easily write a short command to do the reformatting.

Set input to “Entire Document”, output to “Replace Document”, and put the code

#!/usr/bin/perl -p
print “$1\n” while s/(\S{$ENV{TM_COLUMNS}})//;
print “$1\n” while s/(.{0,$ENV{TM_COLUMNS}})\s//;

into the Command(s) box. This will treat a tab as though it took up a
single column, so if you have a lot of tab indents then it will leave
excessively long lines. Writing something that deals properly with
tabs would be a bit harder, but very possible.


## How to select something in a document by using a macro/command?

I found a way to select something – calculated on run-time – by using a normal macro (plus command) without TMTOOLS!!

The problem was if I have a script which outputs a text chunk or a regexp how can we select that text/regexp in a TM window?
The approach is actually very simple. I copy the text/regexp into the shared find pasteboard; place the caret to a proper location; and execute ‘findNext’. Thus I wrote a tiny C program which copies a string into the shared find pasteboard. OK, then I wanted to write a man page for that command on basis of the normal pbcopy man page, and I figured out that pbcopy is already able to do this 😉

Fine. The only problem was that if I write a tmcommand à la:

echo -en “FINDTEXT” | pbcopy -pboard find

it doesn’t work because “pbcopy -pboard find” is called from inside of TM. If I execute that in a Terminal, switch back to TM it works. The solution: I have to execute this in a new bash environment.

The basic tmcommand (example name “SELECTTEXT”):

export RESULT
/bin/bash -c ‘echo -en “$RESULT” | pbcopy -pboard find’
#place the caret to a proper location to be able to execute ‘findNext’!
open “txmt://open/?line=$LINE&column=$COLUMN”

After executing that command the string $RESULT is in the shared find pasteboard, and the caret is set.

Next step > the macro:
Before we can execute ‘findNext’ (= APPLE+G) we have to set the parameters of the find panel, meaning whether we want to do a regexp search or not; ignore case or not.

Thus record a macro à la:

1) open find panel, set the desired parameters, and do a dummy search for something which is NOT in the document -e.g. look for \xFFF3; and close it

2) execute the command “SELECTTEXT”


That’s it. The nice side-effect is that the macro changes nothing within TM’s find panel 😉
And the macro does not affect the undo buffer, it does not change the text etc., and the selection is done instantly.

But attention:
The only tricky point : Be aware of correct escaping!!

On that basis I wrote the “Select XML/HTML balanced tags” script which will come as soon as possible. I only have to fix some tiny things.


### Addition:

To minimize the escaping one can use:

/bin/bash -c ‘echo -n “$RESULT” | pbcopy -pboard find’

instead of:

/bin/bash -c ‘echo -en “$RESULT” | pbcopy -pboard find’

### Addition II:

To get rid of the utf8 encoding one can use:

/bin/bash -c ‘export __CF_USER_TEXT_ENCODING=0x1F5:0x8000100:0x8000100;echo -n “$RES” | pbcopy -pboard find’

On 5. Apr 2007, at 16:26, Digital Rust wrote:

Hi, the tidy feature used to create an xtml compliant document. Since I upgraded to 1.5.5 it now creates an HTML 4.01 doc. How can I change this back to XTML?

Set TM_XHTML to ” /” in Preferences → Advanced → Shell Variables, that should both make inserted tags XHTML and make Tidy default to XHTML as output.

I’ve just been trying TextMate, trying to move away from TextEdit and
TextWrangler. One thing which is really bugging me is the way it underlines
hyperlinks on the ‘Plain Text’ setting. If I wanted that kind of behaviour
I’d use Microsoft Word! Is there a way I can set it up so that plain text is
exactly that, completely plain vanilla typing?


Go to the Bundle Editor (Bundle -> Bundle Editor -> Show Bundle Editor)
and open the Text Bundle (click on the triangle). Then to scroll down to
the object “Plain Text” with a gray L in front of it. If you want to
remove all markings then just delete everything. If you just want to
remove the underlined links then delete the following:

{ begin = ‘^([ \t]*)(?=\S)’;
end = ‘^(?!\1(?=\S))’;
patterns = (
{ name = ‘markup.underline.link’;
match = ‘(?x)
( (https?|s?ftp|ftps|file|smb|afp|nfs|(x-)?man|gopher|txmt)://|mailto:)