Jason Kim
Jason Kim

Reputation: 19041

Textmate, automatically closing indentation when closing html tag

I love Textmate, but this is a small oddity that always bothered me.

I am currently using Version 1.5.10.

I use Command + Option + Dot to close a html tag, but when I do the result is this.

<html>
  </html>

I wish Textmate knew how to do this instead. Automatically de-indents when closing tag is added.

<html>
</html>

This works well for Ruby code by the way. Textmate de-indents when end is typed.

Upvotes: 3

Views: 234

Answers (1)

Jamie
Jamie

Reputation: 4078

The Insert Close Tag (⌘⌥.) command in TextMate (along with every other command in the Bundles menu) is completely customisable through the Bundle Editor.

If you open up the Bundle Editor ( Bundles > Bundle Editor > Show Bundle Editor (⌃⌘⌥B)), and find the 'Insert Close Tag' command in the list on the left, you should be able to view and edit the code in that command.

To implement your un-indenting functionality, find this chunk of code (at the end of the file):

else
    print "</#{stack.pop}>"
end

And modify it so that it looks like this:

else
    print "</#{stack.pop}>"
    %x{ osascript -e 'tell application "System Events" to key code 33 using command' }
end

This extra line of code tells TextMate that after inserting the closing tag, it should perform the Shift Left command, by simulating the a press of the key combination ⌘[ - thus un-indenting your code.

Upvotes: 2

Related Questions