Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs hotkey to align equal signs

Tags:

emacs

I'd like to put something like this in my .emacs:

(local-set-key (kbd "C-c a =") 
  (lambda () (interactive) 
    (align-regexp (region-beginning) (region-end) "=")))

But whenever I run it, I get an error "Wrong type argument: numberp, nil".

What does this error mean and how do I get the effect I'm looking for?

like image 455
qrest Avatar asked Sep 03 '10 04:09

qrest


1 Answers

Here you are my dear fellow.

(defun align-to-equals (begin end)
  "Align region to equal signs"
   (interactive "r")
   (align-regexp begin end "\\(\\s-*\\)=" 1 1 ))

The (\s-*) prefix is used internally by align-regexp

From the align.el

(list (concat "\\(\\s-*\\)"

John Wiegley just neglected to document it, and I guess most people just use align-regexp interactively, or just record and save a macro!

like image 167
ocodo Avatar answered Oct 02 '22 06:10

ocodo