jarod2d/sublime_valign

Alignment issue in complex objects

ilyakam opened this issue · 7 comments

obj = 
  key: complex: value
  function: (params) => assignment = value 

Is incorrectly aligned as:

obj = 
  key: complex: value
  function: (params) = > assignment = value 

That's because it finds the equals sign in the fat arrow before it finds the first colon that it's supposed to align against.

I have the same issue but in a different context

$defaults[] = array(
    'id' => 'name',
    'name' => __( 'Title', 'jigoshop' ),
    'type' => 'text',
    'desc' => __( 'This controls the title which the user sees during checkout.', 'jigoshop' ),
    'std' => __( 'Dwolla', 'jigoshop' )
);

Doing the command adds a space like so = > when it aligns.

+1, I get the space between "=" and ">" too.

Yeah, that happens because the plugin only accounts for prefixes on an alignment character (so >= would be aligned properly but not =>). I'll add support for "postfixes" at some point, although I unfortunately don't have much free time at the moment so I likely won't get around to it for a little while.

Any way I can add support myself even if it means hard coding?

On Feb 11, 2013, at 3:21 AM, Jarod Long notifications@github.com wrote:

Yeah, that happens because the plugin only accounts for prefixes on an
alignment character (so >= would be aligned properly but not =>). I'll add
support for "postfixes" at some point, although I unfortunately don't have
much free time at the moment so I likely won't get around to it for a
little while.


Reply to this email directly or view it on
GitHubhttps://github.com//issues/2#issuecomment-13371477..

Sure, you can edit valign.py to make it do whatever you want (although your changes will get overwritten whenever the plugin is updated, so be sure to keep a backup somewhere). If you look in that file at around line 123, you can see where it's compensating for prefixes. Right after that you should be able to do something similar for postfixes. Ideally this would be configurable in the same way prefixes are.

If you get it working I'd be happy to merge in a pull request.

Okay cool, I got it working by just changing the settings to:

self.alignment_chars = settings.get("va_alignment_chars", [
    {
        "char":        ">",
        "alignment":   "right",
        "left_space":  True,
        "right_space": True,
        "prefixes":    ["="]
    },

Is there another way to modify the settings than to alter the .py file? Is there no separate thing?

Hmmm...that will get around this particular issue, but it will cause some weird behavior in some cases because it's now going to try to align on > characters. If that doesn't affect you then this is a good temporary fix, though.

You can modify the settings in your settings file rather than inside the code. Just press Cmd + Comma if you're on a Mac or open the command palette and look for Preferences: Settings - User. Inside the JSON object you can add properties for any settings you want to customize -- in this case "va_alignment_chars". Doing it this way will make sure that your changes don't get overwritten when the plugin updates.