From 78545d188db777279206b70bc68e69387177f5a8 Mon Sep 17 00:00:00 2001 From: Ravi R Kiran Date: Sat, 28 Dec 2013 21:56:09 -0800 Subject: Duplicate lines easily diff --git a/ravi-init-navigation.el b/ravi-init-navigation.el index e52a85b..bef87ca 100644 --- a/ravi-init-navigation.el +++ b/ravi-init-navigation.el @@ -109,6 +109,33 @@ ) ) +;; From Kyle Sherman's comment at +;; http://emacs-fu.blogspot.com/2010/01/duplicating-lines-and-commenting-them.html +;; \todo Make this work someday with regions too. +(defun ravi/kyle-sherman-duplicate-line (&optional comment line) + "Duplicate the line containing the point. +\nIf COMMENT is non-nil, also comment out the original line. + If LINE is non-nil, duplicate that line instead." + (interactive "P") + (let ((col (current-column))) + (save-excursion + (when line + (goto-line line)) + (let ((line (buffer-substring (point-at-bol) (point-at-eol)))) + (when comment + (comment-region (point-at-bol) (point-at-eol))) + (goto-char (point-at-eol)) + (if (eobp) + (newline) + (forward-line 1)) + (open-line 1) + (insert line))) + (forward-line 1) + (move-to-column col))) + +;; C-: duplicates line, C-u C-: comments first line +(bind-key "C-:" 'ravi/kyle-sherman-duplicate-line) + ;; grep and friends (use-package wgrep -- cgit v0.10.1