summaryrefslogtreecommitdiff
path: root/lisp/misc.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-06-17 19:33:48 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-06-17 19:34:26 +0200
commit6362f65474bad81c1d57b9b603c65686a0dd853e (patch)
treee888ab8e90b38cbbe2f8a07d9b42cdabd1c7ebc4 /lisp/misc.el
parent4311bd0bd73c17b883d3f88eab4928a44d056a3a (diff)
downloademacs-6362f65474bad81c1d57b9b603c65686a0dd853e.tar.gz
emacs-6362f65474bad81c1d57b9b603c65686a0dd853e.tar.bz2
emacs-6362f65474bad81c1d57b9b603c65686a0dd853e.zip
Add new command `duplicate-line'
* lisp/misc.el (copy-from-above-command): Mention it. (duplicate-line): New command (bug#46621).
Diffstat (limited to 'lisp/misc.el')
-rw-r--r--lisp/misc.el17
1 files changed, 16 insertions, 1 deletions
diff --git a/lisp/misc.el b/lisp/misc.el
index 0bb8ee6c7bc..88932681c1f 100644
--- a/lisp/misc.el
+++ b/lisp/misc.el
@@ -33,7 +33,9 @@
"Copy characters from previous nonblank line, starting just above point.
Copy ARG characters, but not past the end of that line.
If no argument given, copy the entire rest of the line.
-The characters copied are inserted in the buffer before point."
+The characters copied are inserted in the buffer before point.
+
+Also see the `copy-line' command."
(interactive "P")
(let ((cc (current-column))
n
@@ -61,6 +63,19 @@ The characters copied are inserted in the buffer before point."
(+ n (point)))))))
(insert string)))
+;;;###autoload
+(defun duplicate-line (&optional n)
+ "Duplicate the current line N times.
+Also see the `copy-from-above-command' command."
+ (interactive "p")
+ (let ((line (buffer-substring (line-beginning-position) (line-end-position))))
+ (save-excursion
+ (forward-line 1)
+ (unless (bolp)
+ (insert "\n"))
+ (dotimes (_ n)
+ (insert line "\n")))))
+
;; Variation of `zap-to-char'.
;;;###autoload