Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right-justification of a column using align-regexp

I try to align something using align-regexp but can't get the desired behavior.

Here's what I have at first:

  [21:26] <Luke-Jr> btcNeverSleeps: no
  [21:26] <dmanderson> Not if it has to wait to make it into the block
  [21:26] <btcNeverSleeps> Luke-Jr: can you develop a bit?
  [21:26] <Luke-Jr> btcNeverSleeps: Bitcoin is a currency, not an authentication system
  [21:26] <dmanderson> your user could be waiting a LONG time for 1 Satoshi to who up
  [21:26] <Luke-Jr> btcNeverSleeps: you can use signed messages though

Here's what I want:

  [21:26]        <Luke-Jr> btcNeverSleeps: no
  [21:26]     <dmanderson> Not if it has to wait to make it into the block
  [21:26] <btcNeverSleeps> Luke-Jr: can you develop a bit?
  [21:26]        <Luke-Jr> btcNeverSleeps: Bitcoin is a currency, not an authentication system
  [21:26]     <dmanderson> your user could be waiting a LONG time for 1 Satoshi to who up
  [21:26]        <Luke-Jr> btcNeverSleeps: you can use signed messages though

Here's what I get using "align-rexegp RET > RET": (and which is NOT what I want)

  [21:26] <Luke-Jr        > btcNeverSleeps: no
  [21:26] <dmanderson     > Not if it has to wait to make it into the block
  [21:26] <btcNeverSleeps > Luke-Jr: can you develop a bit?
  [21:26] <Luke-Jr        > btcNeverSleeps: Bitcoin is a currency, not an authentication system
  [21:26] <dmanderson     > your user could be waiting a LONG time for 1 Satoshi to who up
  [21:26] <Luke-Jr        > btcNeverSleeps: you can use signed messages though

can what I want be done with a simple align-regexp or should I look into something more advanced? (for example I know I can definitely do it using a macro but I'd first like to know if it can be done using a simple regexp).

like image 911
bitcoinNeverSleeps Avatar asked Jan 14 '14 19:01

bitcoinNeverSleeps


2 Answers

The align-regexp function is not well documented. What you actually want to do in this case is to use C-u M-x align-regexp

Then, follow the prompts being sure to enter -1 to justify the capture group.

Complex align using regexp: (<[^>]*>)

Parenthesis group to modify (justify if negative): -1

Amount of spacing (or column if negative): 1

Repeat throughout line? (yes or no): yes

like image 154
bnbeckwith Avatar answered Nov 02 '22 23:11

bnbeckwith


You need to include the bracketed text in the capturing group, then turn on justification by supplying a negative group argument:

C-u M-xalign-regexpRET\( <[^>]+>\)RETDEL-1RETRETn

align-regexp is definitely one of the more cryptic Emacs commands. Powerful, though.

like image 36
Sean Avatar answered Nov 03 '22 01:11

Sean