Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

shortcut for align-regexp

3 views
Skip to first unread message

Jannis

unread,
Apr 17, 2013, 8:35:28 AM4/17/13
to help-gn...@gnu.org
Hi emacs users,


this most probably is a beginners question ... googeling however yielded
now exlanation suitable for my emacs experience.

I would love to bind single key combination (like C-a) to the
align-regexp command and use = and <- as alignment regexpressions. How
would I do this?

Without this I always have to type:

M-align-regexp RET <- RET


Thanks a lot
Jannis

Doug Lewan

unread,
Apr 17, 2013, 9:20:02 AM4/17/13
to Jannis, help-gn...@gnu.org
The command align-regexp is written to prompt you for a regular expression if you use it interactively.

The following code does what you describe you want.

(defun my-common-align (begin end)
"Align text in the region on '=' and '<-'."
(interactive "r")
(let ((common-align-regexp "\\(?:=\\|<-\\)"))
(align-regexp begin end common-align-regexp)))
(global-set-key "\C-a" 'my-common-align)

The choice of key is yours, but `C-a' is move-beginning-of-line almost everywhere. I might recommend `C-c a' instead.

,Douglas
Douglas Lewan
Shubert Ticketing
(201) 489-8600 ext 224

If the majority of cooking accidents happen in the kitchen, then why don't we just cook in other rooms?
0 new messages