Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions Alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def run(self, edit):
settings = view.settings()
tab_size = int(settings.get('tab_size', 8))
use_spaces = settings.get('translate_tabs_to_spaces')
alignment_format = settings.get('alignment_format')
if alignment_format == None:
alignment_format = "key-varspace-separator-value"

# This handles aligning single multi-line selections
if len(sel) == 1:
Expand Down Expand Up @@ -151,20 +154,33 @@ def run(self, edit):

# If the next equal sign is not on this line, skip the line
if view.rowcol(matching_char_pt)[0] != row:
points.append(-1)
continue

points.append(insert_pt)

max_col = max([max_col, normed_rowcol(view, space_pt)[1]])

# The adjustment takes care of correcting point positions
# since spaces are being inserted, which changes the points
adjustment = 0
row = 0
for pt in points:
if pt == -1:
continue

textStart = view.text_point(line_nums[row], 0)
row += 1
pt += adjustment
length = max_col - normed_rowcol(view, pt)[1]
adjustment += length
if length >= 0:
view.insert(edit, pt, ' ' * length)
if alignment_format == "key-varspace-separator-value":
view.insert(edit, pt, ' ' * length)
elif alignment_format == "key-separator-varspace-value":
view.insert(edit, pt + 1, ' ' * length)
elif alignment_format == "varspace-key-separator-value":
view.insert(edit, textStart, ' ' * length)
else:
view.erase(edit, sublime.Region(pt + length, pt))

Expand All @@ -182,4 +198,4 @@ def run(self, edit):
view.insert(edit, region.b, ' ' * length)
if settings.get('mid_line_tabs') and not use_spaces:
convert_to_mid_line_tabs(view, edit, tab_size, region.b,
length)
length)
20 changes: 18 additions & 2 deletions Base File.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,21 @@
// of those must be kept next to the = for the operator to be parsed
"alignment_prefix_chars": [
"+", "-", "&", "|", "<", ">", "!", "~", "%", "/", "*", "."
]
}
],

// This plugin can align the selected lines in a number of ways.
// background-color: black;
// color: white;
// "alignment_format": "key-separator-varspace-value"

// ... or ...
// background-color: black;
// color: white;
// "alignment_format": "varspace-key-separator-value"

// ... or the default ...
// background-color: black;
// color : white;
"alignment_format": "key-varspace-separator-value"

}