Skip to content

Commit 1a22226

Browse files
committed
rc/duplicate-line ♂️ (Right version)
1 parent 006d63a commit 1a22226

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

.emacs.rc/misc-rc.el

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,24 @@ This command does the inverse of `fill-paragraph'."
117117
,rc/frame-transparency))
118118
(set-frame-parameter nil 'alpha '(100 100)))))
119119

120-
(defun rc/duplicate-line ()
120+
(defun rc/duplicate-line (&optional count)
121121
"Duplicate current line"
122-
(interactive)
123-
(move-beginning-of-line 1)
124-
(kill-line)
125-
(yank)
126-
(newline)
127-
(yank))
122+
(interactive (list (or current-prefix-arg 1)))
123+
(let ((cur-line (buffer-substring (point-at-bol) (1+ (point-at-eol))))
124+
(count (or count 1)))
125+
(if (or (not (integerp count))
126+
(< count 0))
127+
(user-error "%S is not positive integer" count)
128+
(save-excursion
129+
(forward-line)
130+
(insert (cond
131+
((= count 1)
132+
cur-line)
133+
((= count 0)
134+
"")
135+
(t (thread-last cur-line
136+
(make-list count)
137+
(apply 'concat)))))))))
128138

129139
(global-set-key (kbd "C-,") 'rc/duplicate-line)
130140

0 commit comments

Comments
 (0)