Skip to content

Instantly share code, notes, and snippets.

@JEG2
Created March 25, 2012 22:32
Show Gist options
  • Select an option

  • Save JEG2/2200432 to your computer and use it in GitHub Desktop.

Select an option

Save JEG2/2200432 to your computer and use it in GitHub Desktop.
An attempt to duplicate one of my favorite TextMate commands in Emacs.
(defun jeg2s-duplicate-line-or-region ()
"Duplicate the current region, or line, and leave it selected."
(interactive)
(unless (region-active-p)
(unless (bolp)
(beginning-of-line))
(set-mark-command nil)
(next-line))
(kill-region (region-beginning) (region-end))
(yank)
(yank)
(exchange-point-and-mark))
(global-set-key (kbd "C-c d") 'jeg2s-duplicate-line-or-region)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment