1

How can I use M-x align-regexp to align by

  1. //
  2. All ; after //
  3. All , within [] after //

For example:

With text:

Line 1 ; B // Comment 1 [11, 22] ; Comment 2 [3333, 4]
Line 2 C // Comment 3 [3, 55]   ; Comment 4 [33,222]

How can I achieve alignment of something like

Line 1 ; B // Comment 1 [11, 22]; Comment 2 [3333, 4]
Line 2 C   // Comment 3 [3 , 55]; Comment 4 [33  ,222]

I have confirmed already that M-x align-regexp // aligns the // properly, but everything else after that is over my head :-)

  • I believe this wouldn't be possible with a regular expression without lookbehind. Seems like this is asking for more code than just calling to align-regexp. – wvxvw Jul 10 '17 at 6:21
  • Using align.el in general, it's possible to specify multiple groups of whitespace to align in one line. But the problem is that they all have to match, otherwise an error occurs. So, the only way I see this happening is using a custom search function as regexp attribute to the align-region function. – politza Jul 10 '17 at 13:04
  • @politza: Can you elaborate a bit more on what you mean by the align-region idea? – George Jul 14 '17 at 6:21
  • align-region is the function doing the actual work, the other command is just a wrapper around it. It allows you to specify a function as a "regexp" which then would search the appropriate strings to align and setup the match-data on which align operates. – politza Jul 14 '17 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.