From ab4ebe9d21bcc20da153b4ee4d7ddb7b938ae53a Mon Sep 17 00:00:00 2001 From: JAremko Date: Thu, 19 Dec 2019 21:59:39 +0200 Subject: [PATCH] =?UTF-8?q?rc/duplicate-line=20=E2=99=82=EF=B8=8F=20(Right?= =?UTF-8?q?=20version)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .emacs.rc/misc-rc.el | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/.emacs.rc/misc-rc.el b/.emacs.rc/misc-rc.el index 1366e2c..282120f 100644 --- a/.emacs.rc/misc-rc.el +++ b/.emacs.rc/misc-rc.el @@ -117,14 +117,24 @@ This command does the inverse of `fill-paragraph'." ,rc/frame-transparency)) (set-frame-parameter nil 'alpha '(100 100))))) -(defun rc/duplicate-line () +(defun rc/duplicate-line (&optional count) "Duplicate current line" - (interactive) - (move-beginning-of-line 1) - (kill-line) - (yank) - (newline) - (yank)) + (interactive (list current-prefix-arg)) + (let ((cur-line (buffer-substring (point-at-bol) (1+ (point-at-eol)))) + (count (or count 1))) + (if (or (not (integerp count)) + (< count 0)) + (user-error "%S is not positive integer" count) + (save-excursion + (forward-line) + (insert (cond + ((= count 1) + cur-line) + ((= count 0) + "") + (t (thread-last cur-line + (make-list count) + (apply 'concat))))))))) (global-set-key (kbd "C-,") 'rc/duplicate-line)