views:

47

answers:

2

I have the following line in my Emacs init file.

(global-set-key (kbd "C-x a r") 'align-regexp)

Is there any way to hard-code in a particular regex so that I don't have to specify it every time?

A: 

You could just bind that key-sequence to a keyboard-macro:

(fset 'my-align-regexp
   [?\M-x ?a ?l ?i ?g ?n ?- ?r ?e ?g ?e ?x ?p return ?f ?o ?o return])

(global-set-key (kbd "C-x a r") 'my-align-regexp)

Create a keyboard macro with M-xalign-regexp then enter your regex.

Then insert the macro into your .emacs file with M-xinsert-kbd-macro return return

Adrian Pronk
If you go this route, you might want to look at this answer so as to have a more readable version of the macro: http://stackoverflow.com/questions/3121274/emacs-keystroke-representation-confusion/3121383#3121383
Trey Jackson
+2  A: 

You could create your own command with the hard-coded regexp like so:

(defun align-specific-regexp (beg end)
  "Call 'align-regexp with the regexp ..."
  (interactive "r")
  (align-regexp beg end "^some.*regexp\\(here\\)?"))
Trey Jackson