Emacs, Perl

Emacs: align perl hash with align-current

I often write Perl script and use hash heavily. But I feel boring (and a little bit stupid) to align “=>” manually. For example, press SPACE to align

my %h =
        key1 => value1,
        key11 => value11,
        key111 => value111,


my %h =
        key1   => value1,
        key11  => value11,
        key111 => value111,

After reading Ruslan’s align-regexp, I find align-current and bind it to C-c C-c in cperl-mode.

(define-key cperl-mode-map "\C-c\C-c" 'align-current)

So, I can align those lines of Perl code simply by moving cursor to one of three lines and pressing C-c C-c.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s