Home Download Buy Blog Forum Support

auto-indentation on Sublime 2?

auto-indentation on Sublime 2?

Postby deitch on Sat Jan 28, 2012 10:02 pm

New user (attempter?) on ST2, seeing it as a possible alternative to TM. Still evaluating. Some questions:

1) Auto indent on copy-paste does not seem to work? Take the following JS:
Code: Select all
var f = function() {
  var a = 1;
};
var q = 2;


Now cut and paste the "var q = 2;" line to sit just below the "var a = 1;" What I want is:

Code: Select all
var f = function() {
  var a = 1;
  var q = 2;
};


But I get
Code: Select all
var f = function() {
  var a = 1;
var q = 2;
};


2) Is there any way to select a chunk of text and just auto-indent the whole thing? E.g. if I have
Code: Select all
    var f = function() {
      var a = 1;
var q = 2;
     };


I should be able to select it all, hit some menu item or command, and get automatically:

Code: Select all
var f = function() {
  var a = 1;
  var q = 2;
};


Any way?

3) Auto-comment doesn't work cleanly? If I create a comment

Code: Select all
/*
*/


And then go to the end of the first line and hit enter, I expect to get
Code: Select all
/*
  *
  */


But instead I get:
Code: Select all
/*

*/


So I manually have to tab over and enter the * ?
deitch
 
Posts: 4
Joined: Sat Jan 28, 2012 9:57 pm

Re: auto-indentation on Sublime 2?

Postby spadgos on Sun Jan 29, 2012 10:28 pm

For the first issue (paste while keeping indentation): the shortcut key is Ctrl+Shift+V

For the second issue (automatically adding a leading * inside docblocks), you should have a look at my DocBlock plugin: https://github.com/spadgos/sublime-jsdocs#readme It does that and a heap more. All the info is in the readme.
spadgos
 
Posts: 121
Joined: Thu Oct 06, 2011 12:49 am

Re: auto-indentation on Sublime 2?

Postby deitch on Mon Jan 30, 2012 2:30 pm

Hmm, Ctrl-Shift-V (or Cmd-Shift-V) works better, but it still gets the indentation wrong.

1) Regular paste: keeps the original indentation, which makes no sense (not even sure why this is the default). E.g. if I cut/copy from where indent level is 1 to where it should be 4, it puts in the pasted line with indent level 1. Default should not be this.
2) Indent paste: tries to align to the new indent level, but still gets it off by one level about half the time, depending on if you paste it at the same line as an indent-changer or before.. E.g.

Code: Select all
// copy this
var a = 1;

if (true) {
  q = 5;
  // if you paste it here, it works
}  // if you paste it here, it gets confused by the } and thinks it should be back one, when really it should be indented



It messes it up
deitch
 
Posts: 4
Joined: Sat Jan 28, 2012 9:57 pm

Re: auto-indentation on Sublime 2?

Postby deitch on Fri Feb 03, 2012 12:00 pm

Bump?
deitch
 
Posts: 4
Joined: Sat Jan 28, 2012 9:57 pm

Re: auto-indentation on Sublime 2?

Postby mattsawyer77 on Tue Feb 07, 2012 10:43 pm

PHP auto-indent has been broken for the last several updates.

typing the following:
Code: Select all
    public function foo() {

and then hitting enter will produce the following:
Code: Select all
    public function foo() {

}


The same problem happens for if, else, while, foreach, switch, etc.
mattsawyer77
 
Posts: 3
Joined: Thu Feb 02, 2012 5:48 pm

Re: auto-indentation on Sublime 2?

Postby deitch on Wed Feb 08, 2012 10:26 am

So I am not alone here, eh? I like a lot of what ST2 offers, the price is slightly steep. I even managed to get jslint working the way I want it in ST2. But So much of what we do is indenting, I cannot buy it unless auto-indenting works correctly.
deitch
 
Posts: 4
Joined: Sat Jan 28, 2012 9:57 pm

Re: auto-indentation on Sublime 2?

Postby vitaLee on Wed Feb 08, 2012 11:22 am

@mattsawyer77 can you check if you have auto_indent:false specified in either your User/Base File.sublime-settings or PHP/PHP.sublime_settings (if existing) ?
vitaLee
 
Posts: 150
Joined: Tue Dec 27, 2011 11:10 pm

Re: auto-indentation on Sublime 2?

Postby mattsawyer77 on Wed Feb 08, 2012 8:49 pm

@vitaLee I have auto_indent:true in my base file settings, don't have a PHP.sublime_settings anywhere...should I?

FYI the auto-indentation is happening, just not correctly. Here is perhaps a more specific example:

Code: Select all
if($something) {
    if($somethingElse) {
        if($anotherThing) { // here is where I hit enter
       
    } // and here is the bracket auto-inserted/indented one level less than it should've been
    }
}
mattsawyer77
 
Posts: 3
Joined: Thu Feb 02, 2012 5:48 pm

Re: auto-indentation on Sublime 2?

Postby vitaLee on Wed Feb 08, 2012 9:09 pm

it's not necessery to have PHP.sublime_settings. you can create it yourseld and define settings applicable just for php files.
i got your problem and tested both your exmaples and can confirm i dont have your problem. it indents properly (how you expect it) for me.
maybe it's related to some package you installed.
as i read in other thread you can try to nail the conflicting package (if any) by moving them one by one from the package folder till it indents ok for you.

EDIT: just realised you're probably talking about the latest dev builds. i personally stick to official releases and am using 2165.
vitaLee
 
Posts: 150
Joined: Tue Dec 27, 2011 11:10 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], spinecrawler and 21 guests