seasmith / AlignAssign

Align the assignment operators within a highlighted area.
76 stars 14 forks source link

Guess the operator to align #4

Closed gadenbuie closed 6 years ago

gadenbuie commented 6 years ago

First, thank you for this addin! I use it daily and it's saved me a bunch of time. I've made a few changes to the addin based on my workflow, and I figured I'd at least offer my changes as a PR. If you're interested I can also update README and other things, if not then no worries and feel free to close this.

Given that I use the addin a lot, I decided to streamline the interface a bit and I added a heuristic to guess the operator that should be aligned. With the heuristic in place, I can just select "Align Assign" and the addin chooses the most reasonable operator to align.

For disambiguation, I also renamed the addins in the menu:

The heuristic is basically the following rules applied in this order:

  1. If only one of the operators appears exactly once in all selected lines, align that operator, else...
  2. If only one of the operators appears at all in the the selected lines, align that operator, else...
  3. If only one of the operators is duplicated in any of the selected lines, align the other operator, else...
  4. If one operator appears more often than the other, align that operator, else..
  5. Fall back to <- with warning message in the console.
seasmith commented 6 years ago

Looks great! Since you did quite a bit of work, I will add you as an author.

This technique seems very relevant to the newer (and very experimental) AlignRegex package. I'm dreadfully slow at these things, so it may be a few weeks before I started experimenting around with that package.