pedzsanReddit · 2022-10-13 13:32
Is there a repository of patterns or rules to be used with `align`? I'm frequently tempted to dig in and write something but I usually end up just doing it by hand.
github-alphapapa · 2022-10-13 18:23
Your question is missing some context. :)
7890yuiop · 2022-10-13 19:38
Other than `align-rules-list` you mean? Because there's a bunch of use-cases defined there. But I imagine you're well aware of that already. I'm not aware of anything external (but I've also never gone hunting for such a thing).
pedzsanReddit · 2022-10-13 19:47
Yes. Every time I try `align`, it does nothing. In today's case, I have code using Ruby's old style of hash because the keys are strings. The original table looked like:
```ruby
Header = {
"Type:Bank" => [ NoninvestmentFields, Noninvestment],
"Type:Cash" => [ NoninvestmentFields, Noninvestment],
"Type:CCard" => [ NoninvestmentFields, Noninvestment],
"Type:Invst" => [ InvestmentFields, Investment],
"Type:Oth A" => [ NoninvestmentFields, Noninvestment],
"Type:Oth L" => [ NoninvestmentFields, Noninvestment],
"Account" => [ AccountFields, Account],
"Type:Cat" => [ CategoryFields, Category ],
"Type:Class" => [ ClassFields, Klass],
"Type:Memorized" => [ MemorizedFields, Memorized],
"Type:Security" => [ SecurityFields, Security],
"Type:Budget" => [ BudgetFields, Budget],
"Type:Payee" => [ PayeeFields, Payee],
"Type:Prices" => [ PricesFields, Price],
"Option:AutoSwitch" => NoFields,
"Option:AllXfr" => NoFields,
"Clear:AutoSwitch" => NoFields
}.freeze
```
rather than
```ruby
Header = {
"Type:Bank" => [ NoninvestmentFields, Noninvestment],
"Type:Cash" => [ NoninvestmentFields, Noninvestment],
"Type:CCard" => [ NoninvestmentFields, Noninvestment],
"Type:Invst" => [ InvestmentFields, Investment],
"Type:Oth A" => [ NoninvestmentFields, Noninvestment],
"Type:Oth L" => [ NoninvestmentFields, Noninvestment],
"Account" => [ AccountFields, Account],
"Type:Cat" => [ CategoryFields, Category ],
"Type:Class" => [ ClassFields, Klass],
"Type:Memorized" => [ MemorizedFields, Memorized],
"Type:Security" => [ SecurityFields, Security],
"Type:Budget" => [ BudgetFields, Budget],
"Type:Payee" => [ PayeeFields, Payee],
"Type:Prices" => [ PricesFields, Price],
"Option:AutoSwitch" => NoFields,
"Option:AllXfr" => NoFields,
"Clear:AutoSwitch" => NoFields
}.freeze
```
For me personally, `align` does nothing almost every time I try it. It just seems like over the years, there would be a huge repository of great language specific patterns.
Aminumbra · 2022-10-13 20:13
I'm pretty sure "language specific" would be too vague, as there are often several viable ways to align stuff in any given language. On the other hand, `align-regexp` & other such functions already exist; using your example and calling it on the regexp `=>` aligns the "arrows" as needed; a second call with *e.g.* `\w+\ *\]` (space included to match the 8th entry, where "Category" has a space after it before the closing square bracket) aligns the keys of the hash-table.
It *might* be long; but it really is not that long once you get used to Emacs regexp (which are slightly different from some other, well-known ones) and the way `align(-regexp)` works.
pedzsanReddit · 2022-10-13 20:37
Yea. I probably need to take the time to learn, just once, how to write a pattern. That would probably help with `align-regexp` too since it is probably the same concepts. I'm fine with regular expressions although I often need to run to the documentation for the lesser used constructs.
Thanks!