summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ravi-init-navigation.el27
1 files changed, 27 insertions, 0 deletions
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