Home Download Buy Blog Forum Support

Multi-Selection Alignment

Multi-Selection Alignment

Postby wbond on Tue May 31, 2011 2:06 am

Sublime Alignment is a plugin that aligns multiple selections and multi-line selections. When aligning multi-line selections, all lines are first indented to the same level. Upon subsequent execution, all equal signs are aligned to the same column. When aligning multiple selections, all selection points are aligned to the same column.

Please see http://wbond.net/sublime_packages/alignment for full documentation, including installation instructions, settings, key bindings, etc.

Bugs should be reported at https://github.com/wbond/sublime_alignment/issues.

Updates

Version 2.0.0

  • Removed the old ctrl+shift+a key binding for Windows/Linux and cmd+shift+a for OS X to prevent conflicts with the Expand to Tag command key binding. ctrl+alt+a should be used on Windows/Linux and ctrl+cmd+a on OS X.

Version 1.1.3

  • Added settings file for CSS to align on : characters also

Version 1.1.2

  • Fixed the indentation import to work when this package is loaded before the Default package

Version 1.1.1

  • Fixed a math error when converting mid-line spaces to tabs

Version 1.1.0

  • Added mid_line_tabs settings
  • Fixed handling of mid-line alignment when align_indent is false and indentation is done via tabs
  • Added an additional key binding, ctrl+alt+a (Windows, Linux) or cmd+ctrl+a (OS X) that doesn't conflict with the new Expand Selection to Tag command from Sublime Text b2102

Version 1.0.6

  • Fixed a bug with mid-line tabs causing incorrect mid-line alignment

Version 1.0.5

  • Fixed a bug with multi-selection alignment

Version 1.0.4

  • Added align_indent, alignment_chars, alignment_space_chars and alignment_prefix_chars settings
  • Enhanced plugin to not indent blank lines when setting to trim trailing white space is enabled

Version 1.0.3

  • Added Preferences menu entries and command palette commands for preferences

Version 1.0.2

  • Enhanced plugin to remove extra whitespace not necessary for alignment
  • Fixed handling of equal signs without whitespace before them

Version 1.0.1

  • Added multi-line alignment functionality

Version 1.0.0

  • Initial release
Last edited by wbond on Mon Sep 19, 2011 3:19 am, edited 5 times in total.
wbond
 
Posts: 528
Joined: Mon Feb 28, 2011 5:33 am

Re: Multi-Selection Alignment

Postby bizoo on Tue May 31, 2011 6:53 am

Thanks for this nice and useful plugin.

Actually it doesn't work cos the decorator @handles_not_found is not declared, I have to remove this line:

Code: Select all
class AlignmentCommand(sublime_plugin.TextCommand):
   @handles_not_found
   def run(self, edit):

to
Code: Select all
class AlignmentCommand(sublime_plugin.TextCommand):
   def run(self, edit):
bizoo
 
Posts: 889
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Multi-Selection Alignment

Postby wbond on Tue May 31, 2011 1:50 pm

@bizoo

Thanks for pointing that out. I had fixed it in my local copy, but I forgot to commit and push it to github.
wbond
 
Posts: 528
Joined: Mon Feb 28, 2011 5:33 am

Re: Multi-Selection Alignment

Postby adzenith on Tue May 31, 2011 5:39 pm

Thanks! I plan on using this all the time. :)
adzenith
 
Posts: 1217
Joined: Mon Oct 19, 2009 9:12 pm

Re: Multi-Selection Alignment

Postby jbrooksuk on Thu Jun 02, 2011 8:12 am

Sweet!

If you could change this slightly to not have to place the cursor, but instead select the code, then keypress. Awesome!

Also, it doesn't quite work right in this case;
Code: Select all
var test = 1,
   anothertest = 2,
   testme = "another var";

"anothertest" gets left behind.
jbrooksuk
 
Posts: 781
Joined: Sun Apr 11, 2010 10:37 am
Location: England

Re: Multi-Selection Alignment

Postby wbond on Thu Jun 02, 2011 5:19 pm

I was thinking of adding a mode for a single multi-line selection that would indent all of the lines to the same level. It sounds like this is what you are looking for, correct?

For your example of failure, where are your cursors placed?
wbond
 
Posts: 528
Joined: Mon Feb 28, 2011 5:33 am

Re: Multi-Selection Alignment

Postby jbrooksuk on Fri Jun 03, 2011 8:02 am

wbond wrote:I was thinking of adding a mode for a single multi-line selection that would indent all of the lines to the same level. It sounds like this is what you are looking for, correct?

Correct!
wbond wrote:For your example of failure, where are your cursors placed?

Beginning of each identifier.
jbrooksuk
 
Posts: 781
Joined: Sun Apr 11, 2010 10:37 am
Location: England

Re: Multi-Selection Alignment

Postby wbond on Sat Jun 04, 2011 10:52 pm

@jbrooksuk

I've updated the plugin to be a bit more powerful. I believe the issue you were having with alignment is that the plugin was intended for aligning things like equal signs in the middle of lines, do it always inserted spaces. The way that sublime measures columns of characters, only a single space would have been inserted if you use tabs for indenting.

That said, I've updated the plugin to do what I think you were intending to do, which is to align the left edge of each line to the same indent level. If you have a multi-line selection, the plugin will cause all lines to be indented to the same level. As a bonus, if you run it a second time, the first set of equal signs with be aligned using spaces.

The original functionality for multiple selections still exists and functions that same way.

If any of what I described is confusing, please see the readme for examples.
wbond
 
Posts: 528
Joined: Mon Feb 28, 2011 5:33 am

Re: Multi-Selection Alignment

Postby wbond on Thu Jun 09, 2011 1:12 pm

New update:

The multi-line selection mode now properly handles equal signs that do not have a space before them. Equal signs are aligned to the left-most column possible while leaving at least one space to the left of each equal sign/operator.

https://github.com/wbond/sublime_alignm ... all/master
wbond
 
Posts: 528
Joined: Mon Feb 28, 2011 5:33 am

Re: Multi-Selection Alignment

Postby senzo on Mon Jul 04, 2011 10:42 am

It would be useful for javascript to check not only for '=' but for ':' too. The equal sign could have precedence.

Nice Plugin
senzo
 
Posts: 106
Joined: Tue May 24, 2011 9:17 am

Next

Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 11 guests