From 0f3ce6d6fd0e081db6ed1ab20ad126ed931950e3 Mon Sep 17 00:00:00 2001 From: Lars Tveito Date: Tue, 31 Mar 2015 22:01:41 +0200 Subject: [PATCH] Updated duplicate-thing to optionally comment out original thing. --- init.el | 10 ++++++---- init.org | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/init.el b/init.el index 8aff2b7..56c9bef 100644 --- a/init.el +++ b/init.el @@ -635,16 +635,18 @@ the buffer is buried." ;; To duplicate either selected text or a line we define this interactive ;; function. -(defun duplicate-thing () - "Duplicates the current line, or the region if active." - (interactive) +(defun duplicate-thing (comment) + "Duplicates the current line, or the region if active. If an argument is +given, the duplicated region will be commented out." + (interactive "P") (save-excursion (let ((start (if (region-active-p) (region-beginning) (point-at-bol))) (end (if (region-active-p) (region-end) (point-at-eol)))) (goto-char end) (unless (region-active-p) (newline)) - (insert (buffer-substring start end))))) + (insert (buffer-substring start end)) + (when comment (comment-region start end))))) ;; To tidy up a buffer we define this function borrowed from [[https://github.com/simenheg][simenheg]]. diff --git a/init.org b/init.org index 1f886ff..9aedead 100644 --- a/init.org +++ b/init.org @@ -812,16 +812,18 @@ function. #+BEGIN_SRC emacs-lisp - (defun duplicate-thing () - "Duplicates the current line, or the region if active." - (interactive) + (defun duplicate-thing (comment) + "Duplicates the current line, or the region if active. If an argument is + given, the duplicated region will be commented out." + (interactive "P") (save-excursion (let ((start (if (region-active-p) (region-beginning) (point-at-bol))) (end (if (region-active-p) (region-end) (point-at-eol)))) (goto-char end) (unless (region-active-p) (newline)) - (insert (buffer-substring start end))))) + (insert (buffer-substring start end)) + (when comment (comment-region start end))))) #+END_SRC To tidy up a buffer we define this function borrowed from [[https://github.com/simenheg][simenheg]].