5

Initial buffer

&ei = wFSXYvnUEvaL6dsP9f2HsAE
&ip = 195.201.109.29
&id = o-AD7SgDnv171kT3qy-KSuSbDZ3zX4YR5X7cS6Mmq237oY
&itag = 22
&source = youtube
&requiressl = yes
&vprv = 1
&mime = video%2Fmp4
&cnr = 14
&ratebypass = yes
&dur = 193.863
&lmt = 1481782852831520
&fexp = 24001373,24007246
&c = ANDROID
&sparams = expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Ccnr%2Cratebypass%2Cdur%2Clmt
&sig = AOq0QJ8wRQIhAOEaQvJ6d6Z3qVjvnAkqv_MOdyBwYGU3zYA2VGQMjvzlAiB8LLsH0WW-SFB2XuxZndVzMeLU4DEZYZUomM6TfEjfGA%3D%3D
&host = rr4---sn-4g5lznez.googlevideo.com
&title = y2meta.com%20-%20%D8%A7%D9%84%D8%AC%D8%B2%D8%A7%D8%A6%D8%B1%20:%20%D8%AC%D8%A7%D8%A6%D8%B2%D8%A9%20%D9%86%D9%88%D8%A8%D9%84%20%D9%81%D9%8A%20%D8%A7%D9%84%D9%85%D9%87%D8%B2%D9%84%D8%A9%20%D9%87%D9%87%D9%87%D9%87%D9%87%D9%87%D9%87
&cm2rm = sn-5abxgpxuxaxjvh-5abs7s,sn-hgnlz7l
&req_id = f665c13668b4a3ee
&redirect_counter = 2
&cms_redirect = yes
&cmsv = e
&mh = 1J
&mip = 197.201.1.50
&mm = 34
&mn = sn-4g5edndl
&ms = ltu
&mt = 1654084603
&mv = m
&mvi = 5
&pl = 22
&lsparams = mh,mip,mm,mn,ms,mv,mvi,pl
&lsig = AG3C_xAwRQIgDWrakAvLyWUUDp5_Ubdpz5qWE0qk9jMqT1WDKjxqY78CIQDoaW79cklMU5ts5g2WanYyNxR-y-5DXezu8vbWHeXLJA%3D%3D

After align-regex RET = RET

&ei                     = wFSXYvnUEvaL6dsP9f2HsAE
&ip                     = 195.201.109.29
&id                     = o-AD7SgDnv171kT3qy-KSuSbDZ3zX4YR5X7cS6Mmq237oY
&itag                   = 22
&source                 = youtube
&requiressl             = yes
&vprv                   = 1
&mime                   = video%2Fmp4
&cnr                    = 14
&ratebypass             = yes
&dur                    = 193.863
&lmt                    = 1481782852831520
&fexp                   = 24001373,24007246
&c                      = ANDROID
&sparams                = expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Ccnr%2Cratebypass%2Cdur%2Clmt
&sig                    = AOq0QJ8wRQIhAOEaQvJ6d6Z3qVjvnAkqv_MOdyBwYGU3zYA2VGQMjvzlAiB8LLsH0WW-SFB2XuxZndVzMeLU4DEZYZUomM6TfEjfGA%3D%3D
&host                   = rr4---sn-4g5lznez.googlevideo.com
&title                  = y2meta.com%20-%20%D8%A7%D9%84%D8%AC%D8%B2%D8%A7%D8%A6%D8%B1%20:%20%D8%AC%D8%A7%D8%A6%D8%B2%D8%A9%20%D9%86%D9%88%D8%A8%D9%84%20%D9%81%D9%8A%20%D8%A7%D9%84%D9%85%D9%87%D8%B2%D9%84%D8%A9%20%D9%87%D9%87%D9%87%D9%87%D9%87%D9%87%D9%87
&cm2rm                  = sn-5abxgpxuxaxjvh-5abs7s,sn-hgnlz7l
&req_id                 = f665c13668b4a3ee
&redirect_counter       = 2
&cms_redirect           = yes
&cmsv                   = e
&mh                     = 1J
&mip                    = 197.201.1.50
&mm                     = 34
&mn                     = sn-4g5edndl
&ms                     = ltu
&mt                     = 1654084603
&mv                     = m
&mvi                    = 5
&pl                     = 22
&lsparams               = mh,mip,mm,mn,ms,mv,mvi,pl
&lsig                   = AG3C_xAwRQIgDWrakAvLyWUUDp5_Ubdpz5qWE0qk9jMqT1WDKjxqY78CIQDoaW79cklMU5ts5g2WanYyNxR-y-5DXezu8vbWHeXLJA%3D%3D

However, I'd like to have parameters on the left (strings before the = sign) be right aligned like in this example :

 1                     AC_BR_BONANZA  Too many newlines in a row... spammy template
 2                          ACCESSDB  Message would have been caught by accessdb
 3                ACCT_PHISHING_MANY  Phishing for account information
 4                    AC_DIV_BONANZA  Too many divs in a row... spammy template
 5                 AC_FROM_MANY_DOTS  Multiple periods in From user name
 6             AC_HTML_NONSENSE_TAGS  Many consecutive multi-letter HTML tags, likely nonsense/spam
 7                    AC_POST_EXTRAS  Suspicious URL
 8          AC_SPAMMY_URI_PATTERNS10  link combos match highly spammy template
 9          AC_SPAMMY_URI_PATTERNS11  link combos match highly spammy template
10          AC_SPAMMY_URI_PATTERNS12  link combos match highly spammy template
11           AC_SPAMMY_URI_PATTERNS1  link combos match highly spammy template
12           AC_SPAMMY_URI_PATTERNS2  link combos match highly spammy template
13           AC_SPAMMY_URI_PATTERNS3  link combos match highly spammy template
14           AC_SPAMMY_URI_PATTERNS4  link combos match highly spammy template
15           AC_SPAMMY_URI_PATTERNS8  link combos match highly spammy template
16           AC_SPAMMY_URI_PATTERNS9  link combos match highly spammy template
17                      ACT_NOW_CAPS  Talks about 'acting now' with capitals
18                            ADMAIL  "admail" and variants
19                       ADMITS_SPAM  Admits this is an ad

Any idea how to achieve this?

2
  • @Drew not really, fill-paragraph will add new lines, which I don't want.
    – ychaouche
    Commented Jun 2, 2022 at 9:15
  • @Drew This is not a duplicate of "How to right align region and/or line?". There the full line is right-aligned, but here only the part before the ?= is right-aligned.
    – Tobias
    Commented Jun 2, 2022 at 14:24

1 Answer 1

6

You use the "complex align"-form of align-regexp, i.e., call it as with universal prefix argument C-u M-x align-regexp RET.

Use \(\s-*&[[:alnum:]_]+\) as regexp and -1 as group number. The negative sign means "justify" instead of "align".
With "align" the full group is replaced by the right amount of spaces whereas with "justify" only the space in the group is used for alignment but not the nonspace characters. If the space is at the beginning of the group that causes the right-alignment of the nonspace-part of the group.

For the other prompted arguments, choose the appropriate amount of spacing and deny repetition.

7
  • regex : \([[:alpha:]_]+\s-*\), group -1, spacing 1, repeat : n, result : gist
    – ychaouche
    Commented Jun 2, 2022 at 9:23
  • @ychaouche Sorry, I used your last example for testing (first left-aligned everything and applied align-regexp afterwards). I have adapted the regexp for your first example now. Could you try again?
    – Tobias
    Commented Jun 2, 2022 at 10:00
  • This incredible working answer should absolutely be accepted and upvoted! Commented Jun 2, 2022 at 13:19
  • 1
    @ychaouche Please use Emacs to check the regexp. E.g., paste the text into the scratch buffer and call re-builder. Set reb-re-syntax to string via C-c TAB (you can use TAB-completion there) and paste the regexp from the question within the quotes "".
    – Tobias
    Commented Jun 7, 2022 at 7:58
  • 1
    @ychaouche Note also, that \s- depends on the syntax table of the major mode of the current buffer.
    – Tobias
    Commented Jun 7, 2022 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.