Changing TextMate JavaScript reformat tab size

TextMate has an beautify command built into its default JavaScript bundle ⌃⇧H (Ctrl+Shift+H). To change the tab size used by the beautifier:

  1. Crack open the Bundle Editor. Bundles > Bundle Editor > Show Bundle Editor or ⌃⌥⌘B (Ctrl+Cmd+Opt++B)
  2. Select JavaScript > Reformat Document / Selection
  3. Add a second argument for the number of spaces to js_beautify($input)

For mine, with two space tabs, it looks like:

print js_beautify($input,2);

If you want to hack the PHP script that makes it all happen, you’ll find it in /Applications/TextMate.app/Contents/SharedSupport/Bundles/JavaScript.tmbundle/Support/lib/beautify.php

Thanks to help from Ryan Stout.

oppositeOf object

Clever pattern by Ryan Stout to get the opposite value for strings.

var oppositeOf = {
  'up' : 'down',
  'down' : 'up',
  'left' : 'right',
  'right' : 'left',
  'black' : 'white',
  'white' : 'black'
};

oppositeOf['left'];
// => 'right'

Phil Dokas:

…That’s the memento design pattern. That’s how Undo in OS X is implemented :)