Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created March 19, 2010 16:07
Show Gist options
  • Save cowboy/337716 to your computer and use it in GitHub Desktop.
Save cowboy/337716 to your computer and use it in GitHub Desktop.
Better indentation for TextMate
### Indent with opt-tab
### http://benalman.com/grab/6e0f7b.png
#!/usr/bin/perl -w
$tab_soft = ' ' x $ENV{'TM_TAB_SIZE'};
$tab_hard = "\t";
$tab = $ENV{'TM_SOFT_TABS'} eq "YES" ? $tab_soft : $tab_hard;
while (<STDIN>) {
s/(?:^|\G)(?:$tab_soft|$tab_hard)/$tab/g;
print "$tab$_";
}
### Un-Indent with shift-tab
### http://benalman.com/grab/ac29aa.png
#!/usr/bin/perl -w
$tab_soft = ' ' x $ENV{'TM_TAB_SIZE'};
$tab_hard = "\t";
$tab = $ENV{'TM_SOFT_TABS'} eq "YES" ? $tab_soft : $tab_hard;
while (<STDIN>) {
s/(?:^|\G)(?:$tab_soft|$tab_hard)/$tab/g;
s/^(?:$tab_soft|$tab_hard)//;
print $_;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment