emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 6362f65474: Add new command `duplicate-line'


From: Lars Ingebrigtsen
Subject: master 6362f65474: Add new command `duplicate-line'
Date: Fri, 17 Jun 2022 13:34:31 -0400 (EDT)

branch: master
commit 6362f65474bad81c1d57b9b603c65686a0dd853e
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add new command `duplicate-line'
    
    * lisp/misc.el (copy-from-above-command): Mention it.
    (duplicate-line): New command (bug#46621).
---
 etc/NEWS     |  4 ++++
 lisp/misc.el | 17 ++++++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index 3b9515c2d4..d27c18f4ec 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -298,6 +298,10 @@ startup.  Previously, these functions ignored
 
 * Changes in Emacs 29.1
 
+---
+** New command 'duplicate-line'.
+This command duplicates the current line the specified number of times.
+
 ---
 ** Files with the '.eld' extension are now visited in 'lisp-data-mode'.
 
diff --git a/lisp/misc.el b/lisp/misc.el
index 0bb8ee6c7b..88932681c1 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]