sublime_alignment
sublime_alignment copied to clipboard
Space before aligned // (double slash)
Despite of configuring alignment_space_chars, when aligning with // (double slash), the outcome's longest line has no space before it. While other characters just work fine.
This block of code,
sample(
$shrt, // comment
$longer, // comment
$longest // comment
)
ends up like this.
sample(
$shrt, // comment
$longer, // comment
$longesttt// comment <--- notice that there's no space before
)
I've also run across this. I've got an interesting use case where I'm trying to align the model definitions in ember-data. So to do this I've add "DS."
to alignment_chars
and alignment_space_chars
. It works as expected except for the missing space as seen above.
My user settings file
{
"align_indent": true,
"mid_line_tabs": false,
"alignment_chars": ["=", "DS."],
"alignment_space_chars": ["=", "DS."],
"alignment_prefix_chars": [
"+", "-", "&", "|", "<", ">", "!", "~", "%", "/", "*", "."
]
}
This
# coffeescript
User = DS.Model.extend
avatar: DS.attr('string')
email: DS.attr('string')
firstName: DS.attr('string')
Turns into
# coffeescript
User = DS.Model.extend
avatar: DS.attr('string')
email: DS.attr('string')
firstName:DS.attr('string') # Missing space before 'DS.'
This bug bites for any entry in alignment_space_characters
that is more than one character long. I tracked down the problem and created a fix; the problem is in the code that checks against the alignment_space_characters
entries only compares each against a single character. Unfortunately I haven't yet mastered Github (don't hate me!), so I can't make a pull request.
The offending code is these two lines in Alignment.py
# if view.substr(matching_char_pt) in alignment_space_chars:
# space_pt += 1
I've replaced them with the following, and now it works as expected
# adds space if alignment char is in alignment_space_chars
# original code fails for multi-character entries in alignment_space_chars
# if view.substr(matching_char_pt) in alignment_space_chars:
# space_pt += 1
for asc in alignment_space_chars:
# check if correct-length substr matches current alignment_space_chars entry
if (view.substr(sublime.Region(matching_char_pt,matching_char_pt+len(asc)))) in alignment_space_chars:
space_pt += 1
break