Home Download Buy Blog Forum Support

Alternate indentation

Alternate indentation

Postby pixycz on Fri Dec 14, 2012 5:01 pm

I would like to switch to SublimeText, but I can't find out if/how alternate code indentation styles are possible.

I prefer different bracketing/indentation style, mostly I use the Ratliff style: http://en.wikipedia.org/wiki/Indent_style#Ratliff_style – I use it in Javascript, CSS, Less etc. I need auto-indetation, I want to use snippets, but all these features force me to use your indentation style. Though I want the closing bracket to be indented like this:

Code: Select all
function some(arr) {
   var i, str = '';
   for (i=1;i<=arr.length;i++) {
      str += arr[i] + i;
      }
   return str;
   }

or

Code: Select all
body {
   background: white;
   }

Is it possible to work like this with SublimeText? I really don't want to indent each closing bracket manually… :(
pixycz
 
Posts: 3
Joined: Fri Dec 14, 2012 4:41 pm

Re: Alternate indentation

Postby pier on Fri Dec 14, 2012 5:15 pm

Snippets are not part of Sublime Text, they are from packages (add ons). It's true that ST comes with some default packages, and that confuses a lot of people.

If you don't like how those snippets work, make your own or modify the ones you use. It's really easy and you will start scratching the surface of what ST is capable of.

For example:

Code: Select all
<snippet>
    <content><![CDATA[
${1:tagName} {
    $2
    }
]]></content>
    <scope>source.css</scope>
    <tabTrigger>css declaration</tabTrigger>
</snippet>


http://docs.sublimetext.info/en/latest/ ... ppets.html
pier
 
Posts: 92
Joined: Fri Jun 15, 2012 2:47 am

Re: Alternate indentation

Postby pixycz on Sat Dec 15, 2012 12:10 am

Well, maybe it can be fixed in snippets. But it doesn't solve normal code typing.

#1: If you type a closing bracket on an indented position on a new line, ST2 automatically moves it one position back to the left:

Code: Select all
xxx {
   aaa
   bbb
   }

is immediatelly changed to:

Code: Select all
xxx {
   aaa
   bbb
}

#2: If you put the cursor inside empty curly brackets and press enter, it's formatted like this:

Code: Select all
{
   |
}

I can't avoid it. What I need is this:

Code: Select all
{
   |
   }

or at least this (Coda or BBEdit do this, I just hit the Enter twice to have what I need):

Code: Select all
{
   |}
pixycz
 
Posts: 3
Joined: Fri Dec 14, 2012 4:41 pm

Re: Alternate indentation

Postby pier on Sat Dec 15, 2012 5:54 am

Everything you are saying is true, and I really can't help you if you don't want to use snippets.

What I don't understand, is why you'd prefer to write "manually" those repetitive code structures that involve using braces (css declarations, function, if else, etc), instead of using snippets. It would save you a lot of time, and you could have the code exactly the way you want it... isn't that the point of using ST?
pier
 
Posts: 92
Joined: Fri Jun 15, 2012 2:47 am

Re: Alternate indentation

Postby pixycz on Sun Dec 16, 2012 11:57 pm

Yes, I totally agree with you. Most of the new code can be written using snippets, and they will solve my problem in 99 % here. There's a bit different situation on editting an existing code, where snippets can't be used so often.

OK anyway. I'll try and create a basic set of snippets and I'll try ST2 in my workflow for a couple of days if it could work. (Though I still think making indetation parametric and supporting other alternate indentation styles in the editor would be nice.)
pixycz
 
Posts: 3
Joined: Fri Dec 14, 2012 4:41 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 16 guests