Friday, March 12, 2010

How to duplicate lines/regions in Emacs

So, I read a blog post just now on line/region duplication over here and thought I'd give it a try as well.

Here's what I came up with:


(defun duplicate-line-or-region (arg)
"Duplicates the current region (transient) ARG times, but at
least twice. If none is active, duplicate the current line
instead."
(interactive "p")
(let ((times (if (> arg 1) arg 2)))
(save-excursion
(if (use-region-p)
(kill-region (mark) (point))
(kill-region (point-at-bol) (point-at-bol 2)))
(dotimes (i times)
(yank)))))

Arrrrrr! Mono docs! *shakes fist*

I just ran into a Makefile that had a rule like this:


blah.tree blah.zip: Makefile
mdassembler --ecma ./blah -o blah

Why does this suck? Because it will choke on make -jN and die horribly.

How it should have been written?

blah.zip: blah.tree
blah.tree: Makefile
mdassembler --ecma ./blah -o blah