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.

Cygwin, Parrot

Parrot: build parrot on cygwin

Building parrot on cygwin is not as straightforward as on other platforms. You have to add path of libparrot.dll into PATH environment variable. For example,


It’s better to add this line into your .bashrc file so that you do not need to run it every time you start a console.

After that, you can follow basic building steps to build parrot.

$ perl Configure.PL
$ make

To test parrot, write a hello.pir

.sub main
    print "Hello world!\n"

And then run it

$ parrot hello.pir

If everything is ok, you should get a string as output.


Makefile: whitespace in path

I hates whitespace in path. I wrote a Perl script which uses a resource file and several template files. So I created a makefile to copy them to user’s HOME directory. It looks like:

$(HOME)/a: a
      cp -f $< $@

Unfortunately, it doesn’t work when there are whitespaces in $(HOME) string, such as /abc/d e/. That happens on Cygwin default installation.

You can double-qoute path, but there are whitespaces in target and target can not be double-qouted. Finally, I find a workaround after diving into `make' info page for a long time. Here is the trick.

nullstring :=
space := $(nullstring) # a space at the end
QUOTED_HOME=$(subst $(space),\ ,$(HOME))
      cp -f $< $(subst $(space),\ ,$@)


Emacs: Do what I mean when commenting

I should know this command earlier. It’s so convenient.

M-x comment-dwim

I always run M-x comment-region and M-x uncomment-region manually except when using C Mode since I can use C-c C-c when commenting.

Don’t do it that way any more. And even fortunately, M-x comment-dwim is bound to M-; by default.

According to help, this command runs different commenting command on different situation. For example, if you mark a region, this command comments code in the region. If you mark comments, this command uncomments them. Read more on help, and read now.

Cygwin, Perl

Upgrade cygwin perl to 5.8.8-4

Cygwin perl is broken after I upgrate to version 5.8.8-4. Let’s fix it!

You have to remove Compress::Zlib first. Otherwise, cpan wouldn’t work.

$ rm -fr `find /usr/lib/perl5/ | grep Compress | grep Zlib`

Then, you have to recompile Scalar::Util yourself because weaken is not supported by default.

cpan[1]> force install Scalar::Util

Now, it’s time to upgrade CPAN.

cpan[2]> install CPAN

If you want Compress::Zlib back, remove IO::Uncompress::Inflate first. There is a circular dependence between IO::Compress::Bzip2 and IO::Uncompress::Inflate. Unless you remove this inconsistency, Compress::Zlib can’t be installed.

$ rm -fr `find /usr/lib/perl5/ | grep Uncompress | grep '\bInflate'`

Finally, I recommend you reinstall Bundle::CPAN and Bundle::Test.


Emacs is not an island

Emacs is not an island. It can communicate with other programs smoothly, with a little tweak.

Tip 1: to enable copy-and paste between emacs and other X Window programs, put the following line into your .emacs file.

(setq x-select-enable-clipboard t)

Tip 2: install firefox extension, It’s All Text!, to edit textareas using external editor, including emacs.