AlignTab icon indicating copy to clipboard operation
AlignTab copied to clipboard

Multiple alignments with single keybinding

Open georgecrawford opened this issue 10 years ago • 6 comments

Hi @randy3k. Thanks so much for this plugin.

What I'd really like is to align whichever code block my cursor is in, using the same keybinding each time. So in a JS var statement:

var a = 'a',
long = 'long';

...would be transformed to:

var a    = 'a',
    long = 'long';

... but when in a JSON object context, the same keybinding would transform:

var a = {
    b: 'b',
    long: 'long'
}

to:

var a = {
    b:    'b',
    long: 'long'
}

I've seen example patterns for both, but is there a way I can run them using the same keybinding, dependent on the context?

Thanks!


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

georgecrawford avatar Nov 05 '14 12:11 georgecrawford

it is tough..it may not be possible to do it with one single regexp.

randy3k avatar Nov 05 '14 21:11 randy3k

:+1: for this feature. What if instead of a single regex, it looped through a dictionary of regex's? It would loop through until a match was found and the user could define the order of precedence.

lifehackett avatar Jan 26 '15 21:01 lifehackett

this is interesting, perhaps, we can define something like the following in named_patterns

  "named_patterns": {
    "js" : {
        "match_all": false,
        "regex" : [
            "regex1", 
            "regex2"
        ]
    }
}

If match_all is false, it will loop through until a match is found. If it is true, then it will loop through all regex.

randy3k avatar Jan 27 '15 20:01 randy3k

Just created a pull request #59 that allows you to declare user_input as a list and it will run through each regexp in the list. It still will take a string, so no previous functionality is lost.

I didn't see this thread until @randy3k pointed it out a bit ago, so I didn't think of the "match_all" option. I'll try and add it in.

KroniK907 avatar Jan 22 '16 06:01 KroniK907

@KroniK907 thanks for the input.

randy3k avatar Jan 22 '16 06:01 randy3k

Updated pull request #59
Added the match_all argument that was mentioned above.

KroniK907 avatar Jan 22 '16 06:01 KroniK907