Skip to content

Instantly share code, notes, and snippets.

@vanrijn
Created February 6, 2013 02:04
Show Gist options
  • Save vanrijn/4719604 to your computer and use it in GitHub Desktop.
Save vanrijn/4719604 to your computer and use it in GitHub Desktop.
Patch to sublime_alignment to place spaces at front of line instead of in the middle
diff --git a/Alignment.py b/Alignment.py
index dfcb1ca..e0b8158 100644
--- a/Alignment.py
+++ b/Alignment.py
@@ -43,6 +43,7 @@ class AlignmentCommand(sublime_plugin.TextCommand):
settings = view.settings()
tab_size = int(settings.get('tab_size', 8))
use_spaces = settings.get('translate_tabs_to_spaces')
+ add_mid_line_whitespace = settings.get('add_mid_line_whitespace')
# This handles aligning single multi-line selections
if len(sel) == 1:
@@ -151,20 +152,31 @@ class AlignmentCommand(sublime_plugin.TextCommand):
# 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 add_mid_line_whitespace:
+ view.insert(edit, pt, ' ' * length)
+ else:
+ view.insert(edit, textStart, ' ' * length)
else:
view.erase(edit, sublime.Region(pt + length, pt))
@@ -182,4 +194,4 @@ class AlignmentCommand(sublime_plugin.TextCommand):
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)
\ No newline at end of file
+ length)
diff --git a/Base File.sublime-settings b/Base File.sublime-settings
index b3f02f7..9a1fc66 100644
--- a/Base File.sublime-settings
+++ b/Base File.sublime-settings
@@ -24,5 +24,11 @@
// of those must be kept next to the = for the operator to be parsed
"alignment_prefix_chars": [
"+", "-", "&", "|", "<", ">", "!", "~", "%", "/", "*", "."
- ]
-}
\ No newline at end of file
+ ],
+
+ // This plugin can either align the selected lines by adding spaces
+ // between the "alignment_chars" and the text to the left of it
+ // (mid_line whitespace) or by adding the spaces to the left of the
+ // entire line (which doesn't add whitespace to the middle of the line).
+ "add_mid_line_whitespace": true
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment