Align regex from emacs lisp

I am trying to use the following elisp function to align text with = :

 (defun align-= () "Align lines by `=`" (interactive) (align-regexp (region-beginning) (region-end) "=")) 

And I'm trying to align the following text:

 offer = stub('offer') user = stub('user') 

But emacs returns the following error:

 align-region: Marker does not point anywhere 

What am I doing wrong?

thanks

+7
source share
1 answer

I worked by doing this:

 (defun align-= (p1 p2) "Align lines by =" (interactive "r") (align-regexp p1 p2 "\\(\\s-*\\)=" 1 1 nil) ) 

As far as I understand, align-regexp does not get what you think it gets.

You can test it manually by calling Mx align-regexp <RET> = <RET> and then pressing Cx ESC ESC (by default, repeat-complex-command bound to Cx ESC ESC , you can also use Mn / Mp to move through the history ), and you will see exactly what align-regexp is being transmitted. Then I copied the string to a function. (I also used the interactive "r" because it is convenient)

It works for me on Emacs 24.

Associated, but not 100% identical:

Inconsistent Mx align-regexp versus Cu behavior Mx align-regexp

And:

Marker doesn't point anywhere from align-regexp (Emacs)

+8
source

All Articles