emacs-devel
[Top][All Lists]
Advanced

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

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


From: Ergus
Subject: Re: master 6362f65474: Add new command `duplicate-line'
Date: Sat, 18 Jun 2022 18:30:43 +0200

Hi:

I saw this command and I would like to make some suggestions very simple
to implement, but that provides some consistency and improve user
interaction.

1) Could we consider to move the cursor when duplicate-line based on
prefix value?  This may be useful to bind the command giving a more
intuitive behavior. For example: USERPREFIX-<up> and USERPREFIX-<down>.

Actually the current command `duplicate-line' is what I expect for
USERPREFIX-<up>, which "emulates" like "we have duplicated before or
up".

Many packages around try to implement such commands because they are
available y sublime ad VS-Code... for example:
https://github.com/wyuenho/move-dup/blob/master/move-dup.el

2) From the same package may we consider a command "move-line", which in
the same fashion the user could bind to move the current line up/down?

3) Could we provide a consistent alternative to all mark-? commands?
Because mark-work selects from the current position to the end of the
work, but mark-sexp or mark-paragraph marks the whole current
sexp/paragraph... moving the cursor to the beginning maybe as mark-word
is a current a long standing command we may provide an alternative like
mark-current-word or similes...

The idea behind this is to provide a more consistent API that avoids to
wrap all per-case commands like transpose-word could have bother like
duplicate-work with just a few lines.

4) Could we provide a mark-line command to complete the family of
mark-something commands? Actually all this could rely on thing-at-point
api right?

Best,
Ergus

On Fri, Jun 17, 2022 at 11:14:14PM +0530, Visuwesh wrote:
[வெள்ளி ஜூன் 17, 2022 13:34] Lars Ingebrigtsen wrote:

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."

Shouldn't this be `duplicate-line'?

   (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]