Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align regexp from emacs lisp

Tags:

emacs

elisp

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

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

And I am 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

like image 547
simao Avatar asked Jan 29 '13 13:01

simao


Video Answer


1 Answers

I got it working 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 it align-regexp is not receiving what you think it is receiving.

You can test it manually by invoking M-x align-regexp <RET> = <RET> and then hitting C-x ESC ESC (by default repeat-complex-command is bound to C-x ESC ESC, you can also use M-n / M-p to move in the history) and you'll see exactly what is passed to align-regexp. I then copied the line into the function. (I also used interactive "r" because it's convenient)

It's working for me on Emacs 24.

Related but not 100% identical to:

Inconsistent M-x align-regexp vs. C-u M-x align-regexp behaviour

And also:

Marker does not point anywhere from align-regexp (Emacs)

like image 51
TacticalCoder Avatar answered Sep 30 '22 19:09

TacticalCoder