Home Download Buy Blog Forum Support

Reindent after swap_line_up and swap_line_down

Reindent after swap_line_up and swap_line_down

Postby neogia on Wed Nov 07, 2012 9:47 am

I've been wanting this feature for awhile, and actually think it should be standard. For those of you wanting your selection to reindent itself when moving it up and down through your code, just add this line to the end of SwapLineUpCommand#run and SwapLineDownCommand#run in Packages/Default/swap_line.py:

Code: Select all
self.view.run_command("reindent")

Pretty simple. Now when swapping lines around you get this:

Code: Select all
if (true) {
}
return true;

swap "return true;" line up

Code: Select all
if (true) {
  return true;  <-- note the indentation
}

instead of the default behavior:

Code: Select all
if (true) {
}
return true;

swap "return true;" line up

Code: Select all
if (true) {
return true;  <-- note the indentation
}
neogia
 
Posts: 3
Joined: Fri Jun 29, 2012 7:54 pm

Re: Reindent after swap_line_up and swap_line_down

Postby bizoo on Wed Nov 07, 2012 10:26 am

Modifying Default packages is never a good idea, you will loose your modification at each ST2 update.
You had better to create macros and override the standard keybindings with a call to your sublime-macro:
Code: Select all
[
   {
      "args": null,
      "command": "swap_line_up"
   },
   {
      "args":
      {
         "single_line": true
      },
      "command": "reindent"
   }
]
bizoo
 
Posts: 873
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland


Return to General Discussion

Who is online

Users browsing this forum: Google [Bot] and 24 guests