开发者

textmate reformat with 2 spaces

I've set textmate to use softtabs 2 spaces on my file. But when I try to reformat the entire document, it uses 2 hard tabs as the indents.

Regular indents work as I want it to, just the document format d开发者_运维技巧oesn't. Anyway to get textmate to be obedient?

Thanks.


The JavaScript bundle's "Reformat Document / Selection" command is passing the document's text to the js_beautify function in the bundle's beautify.php file (found on my system and probably by default at /Applications/TextMate.app/Contents/SharedSupport/Bundles/JavaScript.tmbundle/Support/lib/beautify.php). If you take a look at the function definition you'll see that there's a second parameter, $tab_size, with a default value of 4. There's a line in the bundle that reads print js_beautify($input);. Change this to print js_beautify($input, 2); and you should, I expect, get tab stops with two spaces.

To make it a bit more flexible, use the TextMate environment variable TM_TAB_SIZE, as in print js_beautify( $input, getenv('TM_TAB_SIZE' ) );, which should update how the command operates if you ever change your tab size.

Note, I've tested none of this. :) Just took a look at the bundle and tracked down what seems to be necessary.


So, I tried chuck's suggestion and it gave me an error. I did this to "fix it". I'm sure it could be done more elegantly, but this worked for me.

Open up the same file Chuck says to open up, line 50 (or so) should look like this:

function js_beautify($js_source_text, $tab_size = 4)

change $tab_size to 1

function js_beautify($js_source_text, $tab_size = 1)

Now, around line 56 where it says:

$tab_string = str_repeat(' ', $tab_size);

change the space to a tab like so:

$tab_string = str_repeat("\t", $tab_size); 

That worked for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜