unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / Atom feed
* bug#46621: Copy line
@ 2021-02-18 19:07 Juri Linkov
  2021-02-18 19:30 ` bug#46621: [External] : " Drew Adams
  2021-02-19 13:09 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 46+ messages in thread
From: Juri Linkov @ 2021-02-18 19:07 UTC (permalink / raw)
  To: 46621

[-- Attachment #1: Type: text/plain, Size: 149 bytes --]

Why there is still no such fundamental command as duplicating the current
line?  This command slightly extends the existing copy-from-above-command:

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: copy-line.patch --]
[-- Type: text/x-diff, Size: 491 bytes --]

diff --git a/lisp/misc.el b/lisp/misc.el
index 09f6011f98..b3b7d8355f 100644
--- a/lisp/misc.el
+++ b/lisp/misc.el
@@ -61,6 +61,16 @@ copy-from-above-command
 				 (+ n (point)))))))
     (insert string)))
 
+;;;###autoload
+(defun copy-line (&optional arg)
+  "Duplicate the current line ARG times."
+  (interactive "p")
+  (dotimes (_ arg)
+    (forward-line 1)
+    (insert "\n")
+    (forward-line -1)
+    (copy-from-above-command)))
+
 ;; Variation of `zap-to-char'.
 
 ;;;###autoload

^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: [External] : bug#46621: Copy line
  2021-02-18 19:07 bug#46621: Copy line Juri Linkov
@ 2021-02-18 19:30 ` Drew Adams
  2021-02-20  6:58   ` Richard Stallman
  2021-02-19 13:09 ` Lars Ingebrigtsen
  1 sibling, 1 reply; 46+ messages in thread
From: Drew Adams @ 2021-02-18 19:30 UTC (permalink / raw)
  To: Juri Linkov, 46621

> Why there is still no such fundamental command as duplicating the
> current line?  This command slightly extends the existing
> copy-from-above-command:

 "still"?
 "fundamental command"?

In the 35+ years of Emacs, has anyone actually
requested/missed this?

We seem to be adding this & that simple command
more & more - perhaps just because it's available
in other editors?

(Next, we'll dedicate a default key for this...)

The right approach for this kind of thing, IMO, is
for users to create and use such a command.  Then
after a while they start asking for it by default,
and we maybe add it, if it's a real lack.

I've nothing against such a command.  But I've
also never felt the need for it.





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-18 19:07 bug#46621: Copy line Juri Linkov
  2021-02-18 19:30 ` bug#46621: [External] : " Drew Adams
@ 2021-02-19 13:09 ` Lars Ingebrigtsen
  2021-02-19 20:27   ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 1 reply; 46+ messages in thread
From: Lars Ingebrigtsen @ 2021-02-19 13:09 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 46621

Juri Linkov <juri@linkov.net> writes:

> Why there is still no such fundamental command as duplicating the current
> line?  This command slightly extends the existing copy-from-above-command:

Hm...  So this would basically just allow you to get X number of the
line?

Well, I don't object to adding it, but I'm not sure what the use case is
here?  The only time I can remember wanting something like that is when
I'm filling a buffer with text for test purposes, which is perhaps not a
compelling use case.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-19 13:09 ` Lars Ingebrigtsen
@ 2021-02-19 20:27   ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-02-20  6:54     ` Eli Zaretskii
  2021-02-20 13:03     ` Lars Ingebrigtsen
  0 siblings, 2 replies; 46+ messages in thread
From: Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-02-19 20:27 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 46621, Juri Linkov

Lars Ingebrigtsen <larsi@gnus.org> writes:

>
> Well, I don't object to adding it, but I'm not sure what the use case is
> here?  The only time I can remember wanting something like that is when
> I'm filling a buffer with text for test purposes, which is perhaps not a
> compelling use case.

In programming modes, if you need to declare a bunch of variables, you
may duplicate the current line several times and then proceed to rename
them.  I see the proposed new command may be useful in that scenario.

Also, why not name the command `duplicate-line'? I think it's a more
descriptive name and more discoverable via apropos (along with
`delete-duplicate-lines', for example).

This has been a hot topic in Q&A sites:
https://stackoverflow.com/questions/88399/how-do-i-duplicate-a-whole-line-in-emacs





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-19 20:27   ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2021-02-20  6:54     ` Eli Zaretskii
  2021-02-20 13:05       ` Lars Ingebrigtsen
  2021-02-20 13:03     ` Lars Ingebrigtsen
  1 sibling, 1 reply; 46+ messages in thread
From: Eli Zaretskii @ 2021-02-20  6:54 UTC (permalink / raw)
  To: Daniel Martín; +Cc: 46621, larsi, juri

> Cc: 46621@debbugs.gnu.org, Juri Linkov <juri@linkov.net>
> Date: Fri, 19 Feb 2021 21:27:09 +0100
> From:  Daniel Martín via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> 
> > Well, I don't object to adding it, but I'm not sure what the use case is
> > here?  The only time I can remember wanting something like that is when
> > I'm filling a buffer with text for test purposes, which is perhaps not a
> > compelling use case.
> 
> In programming modes, if you need to declare a bunch of variables, you
> may duplicate the current line several times and then proceed to rename
> them.

I usually use M-/ for that.  It makes typing something that you just
typed very easy: just a single character followed by M-/ usually does
the job.  This allows me to type just what is needed, without
redundant "renaming".





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: [External] : bug#46621: Copy line
  2021-02-18 19:30 ` bug#46621: [External] : " Drew Adams
@ 2021-02-20  6:58   ` Richard Stallman
  0 siblings, 0 replies; 46+ messages in thread
From: Richard Stallman @ 2021-02-20  6:58 UTC (permalink / raw)
  To: Drew Adams; +Cc: 46621, juri

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > We seem to be adding this & that simple command
  > more & more - perhaps just because it's available
  > in other editors?

I agree.  Just because we don't need any longer to struggle
to keep Emacs down to 8 megabytes is no reason to add commands
without real demand.


-- 
Dr Richard Stallman
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)







^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-19 20:27   ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-02-20  6:54     ` Eli Zaretskii
@ 2021-02-20 13:03     ` Lars Ingebrigtsen
  2021-02-20 18:28       ` Juri Linkov
  1 sibling, 1 reply; 46+ messages in thread
From: Lars Ingebrigtsen @ 2021-02-20 13:03 UTC (permalink / raw)
  To: Daniel Martín; +Cc: 46621, Juri Linkov

Daniel Martín <mardani29@yahoo.es> writes:

> In programming modes, if you need to declare a bunch of variables, you
> may duplicate the current line several times and then proceed to rename
> them.  I see the proposed new command may be useful in that scenario.

Right; makes sense.

> This has been a hot topic in Q&A sites:
> https://stackoverflow.com/questions/88399/how-do-i-duplicate-a-whole-line-in-emacs

OK, so there seems to be some general demand for this command, so I
think we should go ahead and add it, unless somebody strongly objects.

> Also, why not name the command `duplicate-line'? I think it's a more
> descriptive name and more discoverable via apropos (along with
> `delete-duplicate-lines', for example).

That does seem like an even better name for the command.  What do you
think, Juri?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-20  6:54     ` Eli Zaretskii
@ 2021-02-20 13:05       ` Lars Ingebrigtsen
  2021-02-20 13:12         ` Eli Zaretskii
  0 siblings, 1 reply; 46+ messages in thread
From: Lars Ingebrigtsen @ 2021-02-20 13:05 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 46621, Daniel Martín, juri

Eli Zaretskii <eliz@gnu.org> writes:

> I usually use M-/ for that.  It makes typing something that you just
> typed very easy: just a single character followed by M-/ usually does
> the job.  This allows me to type just what is needed, without
> redundant "renaming".

`dabbrev-expand'?  I just tried "emacs -Q" and then `M-/' and Emacs just
beeped at me:

---
user-error: No dynamic expansion for ‘buffer.

’ found
---

(Because "buffer." was the previous word in the *scratch* buffer.)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-20 13:05       ` Lars Ingebrigtsen
@ 2021-02-20 13:12         ` Eli Zaretskii
  2021-02-20 13:18           ` Lars Ingebrigtsen
  0 siblings, 1 reply; 46+ messages in thread
From: Eli Zaretskii @ 2021-02-20 13:12 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 46621, mardani29, juri

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: Daniel Martín <mardani29@yahoo.es>,
>   46621@debbugs.gnu.org,
>   juri@linkov.net
> Date: Sat, 20 Feb 2021 14:05:44 +0100
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > I usually use M-/ for that.  It makes typing something that you just
> > typed very easy: just a single character followed by M-/ usually does
> > the job.  This allows me to type just what is needed, without
> > redundant "renaming".
> 
> `dabbrev-expand'?  I just tried "emacs -Q" and then `M-/' and Emacs just
> beeped at me:

You need to type the beginning of what you want it to complete before
M-/.  Try

  b M-/
  f M-/
  f M-/ M-/ M-/

etc.





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-20 13:12         ` Eli Zaretskii
@ 2021-02-20 13:18           ` Lars Ingebrigtsen
  2021-02-20 14:15             ` Eli Zaretskii
  0 siblings, 1 reply; 46+ messages in thread
From: Lars Ingebrigtsen @ 2021-02-20 13:18 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 46621, mardani29, juri

Eli Zaretskii <eliz@gnu.org> writes:

> You need to type the beginning of what you want it to complete before
> M-/.  Try
>
>   b M-/
>   f M-/
>   f M-/ M-/ M-/
>
> etc.

Ah, I see.  I've never used that command before.  However, this just
copies a single word, and not a line?  So a line-copying command still
sounds somewhat useful.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-20 13:18           ` Lars Ingebrigtsen
@ 2021-02-20 14:15             ` Eli Zaretskii
  2021-02-20 14:35               ` Dmitry Gutov
  0 siblings, 1 reply; 46+ messages in thread
From: Eli Zaretskii @ 2021-02-20 14:15 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 46621, mardani29, juri

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: mardani29@yahoo.es,  46621@debbugs.gnu.org,  juri@linkov.net
> Date: Sat, 20 Feb 2021 14:18:06 +0100
> 
> >   b M-/
> >   f M-/
> >   f M-/ M-/ M-/
> >
> > etc.
> 
> Ah, I see.  I've never used that command before.

It's a great means to type much less, and not just in programming
modes.  When writing email as well, for example.

> However, this just copies a single word, and not a line?

I mentioned M-/ because of this rationale:

> > In programming modes, if you need to declare a bunch of variables, you
> > may duplicate the current line several times and then proceed to rename
> > them.

> In programming modes, if you need to declare a bunch of variables, you
> may duplicate the current line several times and then proceed to rename
> them.

So assume you have this:

  ptrdiff_t foobar;

and you want to add this:

  ptrdiff_t bazquux;

Instead of copying the "foobar" line and then editing "foobar" into
"bazquux", you can do

  p M-/ bazquux;

IOW, instead of copying lines, it usually makes more sense in PL modes
to be able to easily repeat what has been typed recently, because
source lines are rarely exact copies of some other line.

So that use case I think is not the best one to justify this new
command.  Which is not to say I object to adding it, just that at
least some people may think they need it because they aren't aware of
some Emacs feature.  Because I _never_ in all the years of writing
code felt the need to have such a command.





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-20 14:15             ` Eli Zaretskii
@ 2021-02-20 14:35               ` Dmitry Gutov
  0 siblings, 0 replies; 46+ messages in thread
From: Dmitry Gutov @ 2021-02-20 14:35 UTC (permalink / raw)
  To: Eli Zaretskii, Lars Ingebrigtsen; +Cc: 46621, mardani29, juri

On 20.02.2021 16:15, Eli Zaretskii wrote:
> Which is not to say I object to adding it, just that at
> least some people may think they need it because they aren't aware of
> some Emacs feature.  Because I_never_  in all the years of writing
> code felt the need to have such a command.

FWIW, I routinely use copy-from-above-command, most often when writing 
tests, when a lot of lines look similar to each other, with minor 
variations.

Never felt a need for another variation of it, though.





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-20 13:03     ` Lars Ingebrigtsen
@ 2021-02-20 18:28       ` Juri Linkov
  2021-02-21  6:16         ` Richard Stallman
                           ` (2 more replies)
  0 siblings, 3 replies; 46+ messages in thread
From: Juri Linkov @ 2021-02-20 18:28 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 46621, Daniel Martín

>> In programming modes, if you need to declare a bunch of variables, you
>> may duplicate the current line several times and then proceed to rename
>> them.  I see the proposed new command may be useful in that scenario.
>
> Right; makes sense.
>
>> This has been a hot topic in Q&A sites:
>> https://stackoverflow.com/questions/88399/how-do-i-duplicate-a-whole-line-in-emacs
>
> OK, so there seems to be some general demand for this command, so I
> think we should go ahead and add it, unless somebody strongly objects.

Also tired of reading endless discussions on Q&A sites about reinventing
such fundamental feature as duplicating a line.

>> Also, why not name the command `duplicate-line'? I think it's a more
>> descriptive name and more discoverable via apropos (along with
>> `delete-duplicate-lines', for example).
>
> That does seem like an even better name for the command.  What do you
> think, Juri?

`duplicate-line' is a better name, but the problem is that is based on the
existing command `copy-from-above-command'.  Should they share
the same name prefix?  Please decide, I have no opinion on this. :-)





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-20 18:28       ` Juri Linkov
@ 2021-02-21  6:16         ` Richard Stallman
  2021-02-21  6:21         ` Richard Stallman
  2021-02-21 13:13         ` Lars Ingebrigtsen
  2 siblings, 0 replies; 46+ messages in thread
From: Richard Stallman @ 2021-02-21  6:16 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 46621, larsi, mardani29

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > >> In programming modes, if you need to declare a bunch of variables, you
  > >> may duplicate the current line several times and then proceed to rename
  > >> them.  I see the proposed new command may be useful in that scenario.

Once in a while I want to do that.  It is easy: C-a C-k C-k,
they C-y as many times as needed.

Instead of a command to duplicate the current line repeatedly,
how about a command to yank the current kill repeatedly?
That would be useful in a much broader range of situations.

I wonder if the current meaning of the numeric argument to C-y (reach
back in the kill ring) is actually useful.  Would it be better for
it to repeat the yank in this way?


-- 
Dr Richard Stallman
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)







^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-20 18:28       ` Juri Linkov
  2021-02-21  6:16         ` Richard Stallman
@ 2021-02-21  6:21         ` Richard Stallman
  2021-02-21  8:54           ` Juri Linkov
  2021-02-21 13:13         ` Lars Ingebrigtsen
  2 siblings, 1 reply; 46+ messages in thread
From: Richard Stallman @ 2021-02-21  6:21 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 46621, larsi, mardani29

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > >> In programming modes, if you need to declare a bunch of variables, you
  > >> may duplicate the current line several times and then proceed to rename
  > >> them.  I see the proposed new command may be useful in that scenario.

Once in a while I want to do that.  It is easy: C-a C-k C-k,
they C-y as many times as needed.

Instead of a command to duplicate the current line repeatedly,
how about a command to yank the current kill repeatedly?
That would be useful in a much broader range of situations.

I wonder if the current meaning of the numeric argument to C-y (reach
back in the kill ring) is actually useful.  Would it be better for
it to repeat the yank in this way?


-- 
Dr Richard Stallman
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)







^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-21  6:21         ` Richard Stallman
@ 2021-02-21  8:54           ` Juri Linkov
  2021-02-21 10:41             ` Eli Zaretskii
                               ` (2 more replies)
  0 siblings, 3 replies; 46+ messages in thread
From: Juri Linkov @ 2021-02-21  8:54 UTC (permalink / raw)
  To: Richard Stallman; +Cc: 46621, larsi, mardani29

>   > >> In programming modes, if you need to declare a bunch of variables, you
>   > >> may duplicate the current line several times and then proceed to rename
>   > >> them.  I see the proposed new command may be useful in that scenario.
>
> Once in a while I want to do that.  It is easy: C-a C-k C-k,
> they C-y as many times as needed.

Let's compare these two solutions.  Trying to copy 10 lines:

  C-a C-k C-k C-y C-y C-y C-y C-y C-y C-y C-y C-y C-y

and adds an unrequested entry to the kill ring
that the user needs to remove from the kill ring later.

When bound to a short key, it's just

  C-12 C-c c

and doesn't change the contents of the kill ring.

> Instead of a command to duplicate the current line repeatedly,
> how about a command to yank the current kill repeatedly?
> That would be useful in a much broader range of situations.
>
> I wonder if the current meaning of the numeric argument to C-y (reach
> back in the kill ring) is actually useful.  Would it be better for
> it to repeat the yank in this way?

It's not realistic to change the meaning of the numeric arg to C-y.
People already use the current meaning for decades.





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-21  8:54           ` Juri Linkov
@ 2021-02-21 10:41             ` Eli Zaretskii
  2021-02-21 13:12               ` Lars Ingebrigtsen
                                 ` (2 more replies)
  2021-02-21 23:04             ` Howard Melman
  2021-02-22  6:23             ` Richard Stallman
  2 siblings, 3 replies; 46+ messages in thread
From: Eli Zaretskii @ 2021-02-21 10:41 UTC (permalink / raw)
  To: 46621, juri, rms; +Cc: larsi, mardani29

On February 21, 2021 10:54:24 AM GMT+02:00, Juri Linkov <juri@linkov.net> wrote:
> >   > >> In programming modes, if you need to declare a bunch of
> variables, you
> >   > >> may duplicate the current line several times and then proceed
> to rename
> >   > >> them.  I see the proposed new command may be useful in that
> scenario.
> >
> > Once in a while I want to do that.  It is easy: C-a C-k C-k,
> > they C-y as many times as needed.
> 
> Let's compare these two solutions.  Trying to copy 10 lines:
> 
>   C-a C-k C-k C-y C-y C-y C-y C-y C-y C-y C-y C-y C-y
> 
> and adds an unrequested entry to the kill ring
> that the user needs to remove from the kill ring later.
> 
> When bound to a short key, it's just
> 
>   C-12 C-c c
> 
> and doesn't change the contents of the kill ring.

What is the use case for an Emacs user to need to copy a line 12 times, and is it frequent enough to justify binding the command to a key, and to C-c key on top of that?

Also, let's not forget that Emacs has keyboard macros, and those can be run with a repeat count.





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-21 10:41             ` Eli Zaretskii
@ 2021-02-21 13:12               ` Lars Ingebrigtsen
  2021-02-21 13:19                 ` Eli Zaretskii
                                   ` (2 more replies)
  2021-02-21 17:41               ` bug#46621: [External] : " Drew Adams
  2021-02-21 20:37               ` Juri Linkov
  2 siblings, 3 replies; 46+ messages in thread
From: Lars Ingebrigtsen @ 2021-02-21 13:12 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 46621, Juri Linkov, Richard Stallman, mardani29

Eli Zaretskii <eliz@gnu.org> writes:

> What is the use case for an Emacs user to need to copy a line 12
> times, and is it frequent enough to justify binding the command to a
> key, and to C-c key on top of that?

That users are asking about a command like this on stackexchange seems to
indicate that some users would find this useful.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-20 18:28       ` Juri Linkov
  2021-02-21  6:16         ` Richard Stallman
  2021-02-21  6:21         ` Richard Stallman
@ 2021-02-21 13:13         ` Lars Ingebrigtsen
  2 siblings, 0 replies; 46+ messages in thread
From: Lars Ingebrigtsen @ 2021-02-21 13:13 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 46621, Daniel Martín

Juri Linkov <juri@linkov.net> writes:

> `duplicate-line' is a better name, but the problem is that is based on the
> existing command `copy-from-above-command'.  Should they share
> the same name prefix?  Please decide, I have no opinion on this. :-)

I think it's fine to go with `duplicate-line', even if it's conceptually
similar to `copy-from-above-command'.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-21 13:12               ` Lars Ingebrigtsen
@ 2021-02-21 13:19                 ` Eli Zaretskii
  2021-02-21 15:51                   ` Lars Ingebrigtsen
  2021-02-21 17:45                 ` Drew Adams
  2021-02-22  6:22                 ` Richard Stallman
  2 siblings, 1 reply; 46+ messages in thread
From: Eli Zaretskii @ 2021-02-21 13:19 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 46621, Juri Linkov, Richard Stallman, mardani29

On February 21, 2021 3:12:19 PM GMT+02:00, Lars Ingebrigtsen <larsi@gnus.org> wrote:
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > What is the use case for an Emacs user to need to copy a line 12
> > times, and is it frequent enough to justify binding the command to a
> > key, and to C-c key on top of that?
> 
> That users are asking about a command like this on stackexchange seems
> to
> indicate that some users would find this useful.

They asked about making a dozen copies of a line?





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-21 13:19                 ` Eli Zaretskii
@ 2021-02-21 15:51                   ` Lars Ingebrigtsen
  2021-02-21 17:06                     ` Eli Zaretskii
  2021-02-21 18:00                     ` bug#46621: [External] : " Drew Adams
  0 siblings, 2 replies; 46+ messages in thread
From: Lars Ingebrigtsen @ 2021-02-21 15:51 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 46621, Juri Linkov, Richard Stallman, mardani29

Eli Zaretskii <eliz@gnu.org> writes:

> They asked about making a dozen copies of a line?

I don't think anybody asked for a dozen copies in particular.

I think we should add the command, but I'm not convinced it deserves a
default key binding -- we can add that later if it turns out that this
is the break-out most-popular new command in Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-21 15:51                   ` Lars Ingebrigtsen
@ 2021-02-21 17:06                     ` Eli Zaretskii
  2021-02-21 17:39                       ` Lars Ingebrigtsen
  2021-02-21 18:00                     ` bug#46621: [External] : " Drew Adams
  1 sibling, 1 reply; 46+ messages in thread
From: Eli Zaretskii @ 2021-02-21 17:06 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 46621, juri, rms, mardani29

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: Juri Linkov <juri@linkov.net>, Richard Stallman <rms@gnu.org>,
>  46621@debbugs.gnu.org, mardani29@yahoo.es
> Date: Sun, 21 Feb 2021 16:51:34 +0100
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > They asked about making a dozen copies of a line?
> 
> I don't think anybody asked for a dozen copies in particular.

Then why did Juri decide to countermand Richard's arguments by a
strawman?

> I think we should add the command, but I'm not convinced it deserves a
> default key binding -- we can add that later if it turns out that this
> is the break-out most-popular new command in Emacs 28.

Richard's arguments still stand, and I'd prefer to seriously consider
rather than dismiss them.





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-21 17:06                     ` Eli Zaretskii
@ 2021-02-21 17:39                       ` Lars Ingebrigtsen
  0 siblings, 0 replies; 46+ messages in thread
From: Lars Ingebrigtsen @ 2021-02-21 17:39 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 46621, mardani29, rms, juri

Eli Zaretskii <eliz@gnu.org> writes:

> Richard's arguments still stand, and I'd prefer to seriously consider
> rather than dismiss them.

Richard said that he didn't see the point of this command since we have
`C-a C-k C-k'.  Nevertheless, it has been demonstrated that this is a
command that users do ask about, so I didn't see any point in repeating
that.

But in the interest of non-dismissal, I've now done so.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: [External] : bug#46621: Copy line
  2021-02-21 10:41             ` Eli Zaretskii
  2021-02-21 13:12               ` Lars Ingebrigtsen
@ 2021-02-21 17:41               ` Drew Adams
  2021-02-21 20:37               ` Juri Linkov
  2 siblings, 0 replies; 46+ messages in thread
From: Drew Adams @ 2021-02-21 17:41 UTC (permalink / raw)
  To: Eli Zaretskii, 46621, juri, rms; +Cc: larsi, mardani29

> Also, let's not forget that Emacs has keyboard
> macros, and those can be run with a repeat count.

+1 for emphasizing this.

We should maybe emphasize it more, particularly
when someone used to another editor asks why
Emacs doesn't have this or that key/action.

Instead, we too often, I think, start thinking
about whether Emacs should indeed add such a
command (and key).

Newbies, in particular, could do well to learn
about using keyboard macros early.

(I haven't used the tutorial in ages.  Do we
introduce recording and playing back macros?)

Speaking of which, it might be good to speak
more of "recording" and "playing back" a
sequence of actions, and less of "macros" in
this context.

I think that many people are used to turning
on "recording" in various contexts - it's not
a big deal as a notion, whereas "macro" sounds
exotic and can sound complicated/intimidating.

^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: [External] : bug#46621: Copy line
  2021-02-21 13:12               ` Lars Ingebrigtsen
  2021-02-21 13:19                 ` Eli Zaretskii
@ 2021-02-21 17:45                 ` Drew Adams
  2021-02-22  6:22                 ` Richard Stallman
  2 siblings, 0 replies; 46+ messages in thread
From: Drew Adams @ 2021-02-21 17:45 UTC (permalink / raw)
  To: Lars Ingebrigtsen, Eli Zaretskii
  Cc: 46621, Juri Linkov, Richard Stallman, mardani29

> That users are asking about a command like this
> on stackexchange seems to indicate that some
> users would find this useful.

Not necessarily.  Which users?  Sometimes newbies
to Emacs are looking for what they're used to in
some other editor, and not seeing that in Emacs
they think "missing feature".

And answers on emacs.SE often set newbies straight
in this regard, saying "this is how you use Emacs
to do what you want".

The first response by us shouldn't be a knee-jerk
reaction to add what someone says is missing.  We
should first check what people who use Emacs do,
i.e., see if what seems to be missing really
represents a problem to be fixed.





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: [External] : bug#46621: Copy line
  2021-02-21 15:51                   ` Lars Ingebrigtsen
  2021-02-21 17:06                     ` Eli Zaretskii
@ 2021-02-21 18:00                     ` Drew Adams
  1 sibling, 0 replies; 46+ messages in thread
From: Drew Adams @ 2021-02-21 18:00 UTC (permalink / raw)
  To: Lars Ingebrigtsen, Eli Zaretskii
  Cc: 46621, Juri Linkov, Richard Stallman, mardani29

> I think we should add the command, but I'm not convinced it deserves a
> default key binding

I'd support that.  Doesn't hurt; anyone can
make use of it.  Not a big deal.

> we can add that later if it turns out that this
> is the break-out most-popular new command in Emacs 28.

I'd hope that we'd hold off for quite a while,
and real, popular acclaim.

It's trivial for users to bind a command.  And
users will let Emacs know if they really, really
want a default binding for some command.  Be
conservative handing out keys by default.






^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-21 10:41             ` Eli Zaretskii
  2021-02-21 13:12               ` Lars Ingebrigtsen
  2021-02-21 17:41               ` bug#46621: [External] : " Drew Adams
@ 2021-02-21 20:37               ` Juri Linkov
  2021-02-21 22:06                 ` bug#46621: [External] : " Drew Adams
  2021-02-22 15:45                 ` Eli Zaretskii
  2 siblings, 2 replies; 46+ messages in thread
From: Juri Linkov @ 2021-02-21 20:37 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 46621, larsi, rms, mardani29

>> > Once in a while I want to do that.  It is easy: C-a C-k C-k,
>> > they C-y as many times as needed.
>>
>> Let's compare these two solutions.  Trying to copy 10 lines:
>>
>>   C-a C-k C-k C-y C-y C-y C-y C-y C-y C-y C-y C-y C-y
>>
>> and adds an unrequested entry to the kill ring
>> that the user needs to remove from the kill ring later.
>>
>> When bound to a short key, it's just
>>
>>   C-12 C-c c
>>
>> and doesn't change the contents of the kill ring.
>
> What is the use case for an Emacs user to need to copy a line 12
> times, and is it frequent enough

Yes, it is frequently used, as these Q&A sites indicate.

> to justify binding the command to a key, and to C-c key on top
> of that?

ISTR, 'C-c letter' keys are reserved for users, so users can bind the
command to 'C-c c' or any other short key.  But I can't prove if such
convention of 'C-c letter' for user keys really exists, I can't find it
in the manual.

Or it could be bound to some short key sequence by default.
Even without a keybinding the key sequence is very short:

  M-10 M-x dup RET

> Also, let's not forget that Emacs has keyboard macros, and those can
> be run with a repeat count.

This is how long it takes with keyboard macros:

  C-a C-k C-k C-x ( C-y C-x ) C-10 C-x e





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: [External] : bug#46621: Copy line
  2021-02-21 20:37               ` Juri Linkov
@ 2021-02-21 22:06                 ` Drew Adams
  2021-02-22 15:45                 ` Eli Zaretskii
  1 sibling, 0 replies; 46+ messages in thread
From: Drew Adams @ 2021-02-21 22:06 UTC (permalink / raw)
  To: Juri Linkov, Eli Zaretskii; +Cc: 46621, larsi, rms, mardani29

> I can't prove if such convention of 'C-c letter' for
> user keys really exists, I can't find it in the manual.

In the Elisp manual, `i key bind TAB':

 key binding
 key binding, conventions for

Or `i conven TAB': (with substring matching):

 buffer display conventions
 coding conventions in Emacs Lisp 
 comments, Lisp convention for
 conventions for writing major modes 
 conventions for writing minor modes
 documentation conventions 
 documentation strings, conventions and tips
 key binding, conventions for 
 major mode conventions
 minor mode conventions 
 programming conventions
 set-advertised-calling-convention 
 typographic conventions

(Yet another advertisement for completion candidates
as an aid to discovery.)

Candidate `key binding, conventions for' takes you
to node `Key Binding Conventions', where you find
this, among other conventions:

  Don't define 'C-c LETTER' as a key in Lisp programs.
  Sequences consisting of 'C-c' and a letter (either
  upper or lower case) are reserved for users; they
  are the *only* sequences reserved for users, so do
  not block them.





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-21  8:54           ` Juri Linkov
  2021-02-21 10:41             ` Eli Zaretskii
@ 2021-02-21 23:04             ` Howard Melman
  2021-02-22  6:23             ` Richard Stallman
  2 siblings, 0 replies; 46+ messages in thread
From: Howard Melman @ 2021-02-21 23:04 UTC (permalink / raw)
  To: 46621

Juri Linkov <juri@linkov.net> writes:

>> Once in a while I want to do that.  It is easy: C-a C-k C-k,
>> they C-y as many times as needed.

I do this occasionally.  Usually it's in something like
markdown-mode.  Typically I'm creating lists and want to
write out a bunch of formatting characters before going back
and filling in text.  So I might want 10-12 lines like:

    - [ ]

which is a markdown list item with a checkbox, before going
back and filing in text without having to type odd
punctuation characters.  Sometimes I might put a date string
in there too or some other prefix string.

It's emacs I can do this many different ways.  I might do
the C-a C-k C-k C-y C-y ... dance.  Typically I'll make 4
lines then kill those 4 lines and yank them 3 times.  I
might just type my text and then go back and use
string-rectangle to insert the markup.  If it were more
involved I might use a macro.

If there were a duplicate-line command that took an arg to
duplicate it arg times I'd probably start using that.  I
probably wouldn't bother to write it myself (I haven't in
30+ years).

>> Instead of a command to duplicate the current line repeatedly,
>> how about a command to yank the current kill repeatedly?
>> That would be useful in a much broader range of situations.
>>
>> I wonder if the current meaning of the numeric argument to C-y (reach
>> back in the kill ring) is actually useful.  Would it be better for
>> it to repeat the yank in this way?
>
> It's not realistic to change the meaning of the numeric arg to C-y.
> People already use the current meaning for decades.

Actually, I'd like that and this is a place where I think
completion systems influence that decision.

I don't use an arg to C-y.  If I want something from the
kill-ring that isn't the last thing, I'll C-y and then M-y
until I get it.  I'm not remembering I want the 3rd to last
thing I killed and if I'm off by one I think it's a pain to
fix.  I might do that if I were writing a complex keyboard
macro and concentrating for it but I'd probably use
registers instead.

But in particular with modern completion systems I'd
definitely like this change to yank's arg.  While I do C-y
M-y for simple stuff, if I want something I've yanked from
longer ago, instead I'll use something like consult-yank or
counsel-yank.  These use the kill-region as completion
candidates and show the candidates, one per line, in the
minibuffer with all the completion tools available (most
have options to cope with multi-line text).  I bind it to
M-y globally so if I want to yank something old I skip C-y
entirely and just type M-y and then might use completion and
narrowing if I don't see it near the top of the list.  As a
result, the current arg to C-y is useless to me because
completion offers a much better experience.

-- 

Howard






^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-21 13:12               ` Lars Ingebrigtsen
  2021-02-21 13:19                 ` Eli Zaretskii
  2021-02-21 17:45                 ` Drew Adams
@ 2021-02-22  6:22                 ` Richard Stallman
  2 siblings, 0 replies; 46+ messages in thread
From: Richard Stallman @ 2021-02-22  6:22 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 46621, juri, mardani29

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > > What is the use case for an Emacs user to need to copy a line 12
  > > times, and is it frequent enough to justify binding the command to a
  > > key, and to C-c key on top of that?

  > That users are asking about a command like this on stackexchange seems to
  > indicate that some users would find this useful.

Sure, but how much?  Is it enough interest that we should cater to it?

Adding to Emacs every function or command that some users would like
would make it even more bloated.  Of course, we add commands, but we
should make sure each one is substantially useful.



-- 
Dr Richard Stallman
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)







^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-21  8:54           ` Juri Linkov
  2021-02-21 10:41             ` Eli Zaretskii
  2021-02-21 23:04             ` Howard Melman
@ 2021-02-22  6:23             ` Richard Stallman
  2021-02-22  9:07               ` Juri Linkov
  2 siblings, 1 reply; 46+ messages in thread
From: Richard Stallman @ 2021-02-22  6:23 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 46621, larsi, mardani29

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > > Once in a while I want to do that.  It is easy: C-a C-k C-k,
  > > they C-y as many times as needed.

  > Let's compare these two solutions.  Trying to copy 10 lines:

  >   C-a C-k C-k C-y C-y C-y C-y C-y C-y C-y C-y C-y C-y

  > and adds an unrequested entry to the kill ring
  > that the user needs to remove from the kill ring later.

With my proposd change to C-y, it would be

   C-a C-k C-k C-u 12 C-y

and it would not require the user to make a new key binding.

Changing the contents of the kill ring is not a drawback.
It is the normal way you move text around in Emacs.

  > It's not realistic to change the meaning of the numeric arg to C-y.
  > People already use the current meaning for decades.

We could inquire of the users to see what they think about the issue.

-- 
Dr Richard Stallman
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)







^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-22  6:23             ` Richard Stallman
@ 2021-02-22  9:07               ` Juri Linkov
  2021-02-22 15:43                 ` Eli Zaretskii
  0 siblings, 1 reply; 46+ messages in thread
From: Juri Linkov @ 2021-02-22  9:07 UTC (permalink / raw)
  To: Richard Stallman; +Cc: 46621, larsi, mardani29

>   > It's not realistic to change the meaning of the numeric arg to C-y.
>   > People already use the current meaning for decades.
>
> We could inquire of the users to see what they think about the issue.

Every once in a while the lack of such fundamental command sparks very
long discussions how to reinvent the wheel.  Some recent examples:

https://stackoverflow.com/questions/88399/how-do-i-duplicate-a-whole-line-in-emacs
https://stackoverflow.com/questions/88399/how-do-i-duplicate-a-whole-line-in-emacs?page=2
https://stackoverflow.com/questions/27129147/efficent-way-to-copy-and-paste-a-line
https://stackoverflow.com/questions/12132601/duplicating-the-current-line
https://emacs.stackexchange.com/questions/22705/quickly-duplicate-line-and-increase-number-for-lots-of-lines
https://old.reddit.com/r/emacs/comments/lkyadp/weekly_tipstricketc_thread/gnnniq3/
https://old.reddit.com/r/emacs/comments/jvpccf/weekly_tipstricketc_thread/gcr8h68/
https://old.reddit.com/r/emacs/comments/jwhr6g/batteries_included_with_emacs/gcqdmp9/
with questions like from the last:

  Why does emacs doesn't have a built-in ergonomic way to duplicate a line?
  Genuinely curious, seems like something fundamental.  Guess it is one of
  the reasons evil-mode has rise so much.  Any new comer will feel disgusted
  by having to do C-a C-space C-e M-w and more keystrokes to place it

The proposed tiny 8-line patch was intended to help people avoid
wasting their time on such trivial things.





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-22  9:07               ` Juri Linkov
@ 2021-02-22 15:43                 ` Eli Zaretskii
  2021-02-22 16:28                   ` Helmut Eller
                                     ` (2 more replies)
  0 siblings, 3 replies; 46+ messages in thread
From: Eli Zaretskii @ 2021-02-22 15:43 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 46621, larsi, rms, mardani29

> From: Juri Linkov <juri@linkov.net>
> Date: Mon, 22 Feb 2021 11:07:58 +0200
> Cc: 46621@debbugs.gnu.org, larsi@gnus.org, mardani29@yahoo.es
> 
> >   > It's not realistic to change the meaning of the numeric arg to C-y.
> >   > People already use the current meaning for decades.
> >
> > We could inquire of the users to see what they think about the issue.
> 
> Every once in a while the lack of such fundamental command sparks very
> long discussions how to reinvent the wheel.  Some recent examples:

Thanks for the links.

However, I don't think they add anything substantial to this
discussion.  For starters, many posters there just wanted to know how
many keystrokes it takes in Emacs to copy a line, and some even said
they wanted to compare the result with Vim.  They don't necessarily
ask for a command or a single short key sequence to do that, at least
not in every post.

More importantly, I see no description of the situations where such a
copy is needed, so it is hard to analyze reason about the necessity.
For example, perhaps some of the posters wanted this because they are
unaware of some existing Emacs features which can do the job
efficiently enough.

This is why I asked here to describe the use cases, i.e. the
situations where such a command would be needed.  I didn't get any
answers to that, AFAIR.  Just one person posted his experiences.

Without knowing what situations necessitate such a command, I don't
see how we will be able to reason whether the needs justify adding the
command.  And reason we must, because we cannot possibly implement
feature after feature just because someone asks about it on
stackexchange.

> The proposed tiny 8-line patch was intended to help people avoid
> wasting their time on such trivial things.

Yes, this command is relatively small.  But we must have some criteria
for adding new commands and features, because otherwise we will add 8
lines, then another 10 lines, then 5 more, etc. etc.  These things add
up, and that's even before you consider the supporting docs and other
consequences.

Bottom line, if we want to consider this command, we should somehow
come up with the relevant use cases, and then weigh them against the
added complexity and maintenance costs.  I therefore urge people who
think they know these details to please speak up and contribute to
this discussion.





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-21 20:37               ` Juri Linkov
  2021-02-21 22:06                 ` bug#46621: [External] : " Drew Adams
@ 2021-02-22 15:45                 ` Eli Zaretskii
  1 sibling, 0 replies; 46+ messages in thread
From: Eli Zaretskii @ 2021-02-22 15:45 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 46621, larsi, rms, mardani29

> From: Juri Linkov <juri@linkov.net>
> Cc: bug-gnu-emacs@gnu.org, Richard Stallman <rms@gnu.org>,
>   46621@debbugs.gnu.org, larsi@gnus.org, mardani29@yahoo.es
> Date: Sun, 21 Feb 2021 22:37:28 +0200
> 
> > Also, let's not forget that Emacs has keyboard macros, and those can
> > be run with a repeat count.
> 
> This is how long it takes with keyboard macros:
> 
>   C-a C-k C-k C-x ( C-y C-x ) C-10 C-x e

But that's a one-time investment.  Thereafter one can bind this to a
key and save it to the init file.

So counting the keystrokes required for defining the macro is not
unlike counting keystrokes required for coding the function you
propose.





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-22 15:43                 ` Eli Zaretskii
@ 2021-02-22 16:28                   ` Helmut Eller
  2021-02-22 16:58                     ` Andreas Schwab
  2021-02-22 17:08                     ` Eli Zaretskii
  2021-02-22 17:04                   ` Gregory Heytings
  2021-02-22 20:51                   ` Stephen Berman
  2 siblings, 2 replies; 46+ messages in thread
From: Helmut Eller @ 2021-02-22 16:28 UTC (permalink / raw)
  To: 46621

On Mon, Feb 22 2021, Eli Zaretskii wrote:

> More importantly, I see no description of the situations where such a
> copy is needed, so it is hard to analyze reason about the necessity.

One example where copy-line would be useful is editing configuration
files.  E.g. /etc/ssh/sshd_config list many options with the default
value but as comments, like so:

  #SyslogFacility AUTH
  #LogLevel INFO
  ... other options ...
  
Now, if I want to change LogLevel to say DEBUG, I would copy the line,
keep the original, and edit the copied line.

Not hard to do in Emacs, but somehow the vi way of doing this feels more
efficient.

Helmut






^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-22 16:28                   ` Helmut Eller
@ 2021-02-22 16:58                     ` Andreas Schwab
  2021-02-22 18:32                       ` Helmut Eller
  2021-02-22 17:08                     ` Eli Zaretskii
  1 sibling, 1 reply; 46+ messages in thread
From: Andreas Schwab @ 2021-02-22 16:58 UTC (permalink / raw)
  To: Helmut Eller; +Cc: 46621

On Feb 22 2021, Helmut Eller wrote:

> On Mon, Feb 22 2021, Eli Zaretskii wrote:
>
>> More importantly, I see no description of the situations where such a
>> copy is needed, so it is hard to analyze reason about the necessity.
>
> One example where copy-line would be useful is editing configuration
> files.  E.g. /etc/ssh/sshd_config list many options with the default
> value but as comments, like so:
>
>   #SyslogFacility AUTH
>   #LogLevel INFO
>   ... other options ...
>   
> Now, if I want to change LogLevel to say DEBUG, I would copy the line,
> keep the original, and edit the copied line.

But you don't need the repeat count for that.  copy-from-above-command
will work well for this task.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-22 15:43                 ` Eli Zaretskii
  2021-02-22 16:28                   ` Helmut Eller
@ 2021-02-22 17:04                   ` Gregory Heytings
  2021-02-22 17:16                     ` Eli Zaretskii
  2021-02-22 20:51                   ` Stephen Berman
  2 siblings, 1 reply; 46+ messages in thread
From: Gregory Heytings @ 2021-02-22 17:04 UTC (permalink / raw)
  To: 46621

[-- Attachment #1: Type: text/plain, Size: 1681 bytes --]


>
> Bottom line, if we want to consider this command, we should somehow come 
> up with the relevant use cases, and then weigh them against the added 
> complexity and maintenance costs.  I therefore urge people who think 
> they know these details to please speak up and contribute to this 
> discussion.
>

My 2 cents: a typical case where this could be useful is:

switch (foobar) {
case long_enum_value_name_a: printf ("a"); break;
case long_enum_value_name_b: printf ("b"); break;
case long_enum_value_name_c: printf ("c"); break;
case long_enum_value_name_d: printf ("d"); break;
case long_enum_value_name_e: printf ("e"); break;
case long_enum_value_name_f: printf ("f"); break;
case long_enum_value_name_g: printf ("g"); break;
case long_enum_value_name_h: printf ("h"); break;
case long_enum_value_name_i: printf ("i"); break;
default: printf ("?"); break;
}

Another typical case:

import java.util.Set;
import java.util.TreeSet;
import java.util.HashSet;
import java.util.LinkedHashSet;

I agree with Richard that this can be done with C-a C-k C-k C-y..., which 
is what I've been using in such cases, but that doesn't mean that the 
proposed command wouldn't be welcome.  I agree with Juri that Richard's 
solution "pollutes" the kill-ring with something that the user actually 
did not want to kill.  I would suggest the following (based on Juri's 
code):

(defun duplicate-line (&optional arg)
   (interactive "p")
   (save-mark-and-excursion
     (dotimes (_ arg)
       (forward-line 1)
       (insert "\n")
       (forward-line -1)
       (copy-from-above-command))))
(global-set-key (kbd "C-x r z") 'duplicate-line)

^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-22 16:28                   ` Helmut Eller
  2021-02-22 16:58                     ` Andreas Schwab
@ 2021-02-22 17:08                     ` Eli Zaretskii
  2021-02-22 18:42                       ` Helmut Eller
  1 sibling, 1 reply; 46+ messages in thread
From: Eli Zaretskii @ 2021-02-22 17:08 UTC (permalink / raw)
  To: Helmut Eller; +Cc: 46621

> From: Helmut Eller <eller.helmut@gmail.com>
> Date: Mon, 22 Feb 2021 17:28:39 +0100
> 
> One example where copy-line would be useful is editing configuration
> files.  E.g. /etc/ssh/sshd_config list many options with the default
> value but as comments, like so:
> 
>   #SyslogFacility AUTH
>   #LogLevel INFO
>   ... other options ...
>   
> Now, if I want to change LogLevel to say DEBUG, I would copy the line,
> keep the original, and edit the copied line.

I already mentioned M-/ as the alternative.  In the above case, type
"#L M-/", and Emacs will complete to "#LogLevel".  IOW, if these cases
are considered as "repeat a previous word" rather than "copy a
previous line, then edit it", the solution already exists.  I suspect
that people who are looking for this command simply don't know about
M-/ in Emacs, because IME it's still quite a unique feature.





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-22 17:04                   ` Gregory Heytings
@ 2021-02-22 17:16                     ` Eli Zaretskii
  2021-02-22 17:54                       ` Gregory Heytings
  0 siblings, 1 reply; 46+ messages in thread
From: Eli Zaretskii @ 2021-02-22 17:16 UTC (permalink / raw)
  To: Gregory Heytings; +Cc: 46621

> Date: Mon, 22 Feb 2021 17:04:02 +0000
> From: Gregory Heytings <gregory@heytings.org>
> 
> My 2 cents: a typical case where this could be useful is:
> 
> switch (foobar) {
> case long_enum_value_name_a: printf ("a"); break;
> case long_enum_value_name_b: printf ("b"); break;
> case long_enum_value_name_c: printf ("c"); break;
> case long_enum_value_name_d: printf ("d"); break;
> case long_enum_value_name_e: printf ("e"); break;
> case long_enum_value_name_f: printf ("f"); break;
> case long_enum_value_name_g: printf ("g"); break;
> case long_enum_value_name_h: printf ("h"); break;
> case long_enum_value_name_i: printf ("i"); break;
> default: printf ("?"); break;
> }

Here's how I'd type this:

  case long_enum_value_name_a: printf ("a"); break;
  c M-/ DEL b : p M-/ ("b"); b M-/
  c M-/ DEL c : p M-/ ("c"); b M-/
  c M-/ M-/ DEL d : p M-/ ("d"); b M-/

etc.  (And if the series are indeed longer than a couple of lines, a
rare case indeed, then a keyboard macro is in order.)





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-22 17:16                     ` Eli Zaretskii
@ 2021-02-22 17:54                       ` Gregory Heytings
  0 siblings, 0 replies; 46+ messages in thread
From: Gregory Heytings @ 2021-02-22 17:54 UTC (permalink / raw)
  To: 46621

[-- Attachment #1: Type: text/plain, Size: 1547 bytes --]


>> My 2 cents: a typical case where this could be useful is:
>>
>> switch (foobar) {
>> case long_enum_value_name_a: printf ("a"); break;
>> case long_enum_value_name_b: printf ("b"); break;
>> case long_enum_value_name_c: printf ("c"); break;
>> case long_enum_value_name_d: printf ("d"); break;
>> case long_enum_value_name_e: printf ("e"); break;
>> case long_enum_value_name_f: printf ("f"); break;
>> case long_enum_value_name_g: printf ("g"); break;
>> case long_enum_value_name_h: printf ("h"); break;
>> case long_enum_value_name_i: printf ("i"); break;
>> default: printf ("?"); break;
>> }
>
> Here's how I'd type this:
>
>  case long_enum_value_name_a: printf ("a"); break;
>  c M-/ DEL b : p M-/ ("b"); b M-/
>  c M-/ DEL c : p M-/ ("c"); b M-/
>  c M-/ M-/ DEL d : p M-/ ("d"); b M-/
>
> etc.  (And if the series are indeed longer than a couple of lines, a 
> rare case indeed, then a keyboard macro is in order.)
>

Yes, that's one way to do it, perhaps the most "emacsish" way to do it. 
But it takes more keystrokes than what you write:

case long_enum_value_name_a: printf ("a"); break; RET
c M-/ SPC l M-/ DEL DEL b : SPC p M-/ SPC ("b"); b M-/ ; RET
c M-/ SPC l M-/ DEL DEL c : SPC p M-/ SPC ("c"); b M-/ ; RET
...

And yes, keyboard macros can also be used.

That doesn't mean that the proposed feature wouldn't be useful; I'd say 
it's more intuitive:

case long_enum_value_name_a: printf ("a"); break; RET
C-u 8 C-x r z
C-s a : RET
C-b C-b C-d b
C-n C-b C-d c
C-n C-b C-d d
...

^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-22 16:58                     ` Andreas Schwab
@ 2021-02-22 18:32                       ` Helmut Eller
  2021-02-22 19:41                         ` Howard Melman
  0 siblings, 1 reply; 46+ messages in thread
From: Helmut Eller @ 2021-02-22 18:32 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: 46621

On Mon, Feb 22 2021, Andreas Schwab wrote:

>> One example where copy-line would be useful is editing configuration
>> files.  E.g. /etc/ssh/sshd_config list many options with the default
>> value but as comments, like so:
>>
>>   #SyslogFacility AUTH
>>   #LogLevel INFO
>>   ... other options ...
>>   
>> Now, if I want to change LogLevel to say DEBUG, I would copy the line,
>> keep the original, and edit the copied line.
>
> But you don't need the repeat count for that.  copy-from-above-command
> will work well for this task.

I didn't know about this.  But if I place point between LogLevel and
INFO and then execute M-x copy-from-above-command then the result is

 #LogLevelcility AUTH INFO

which is not what is needed in this situation.

Helmut





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-22 17:08                     ` Eli Zaretskii
@ 2021-02-22 18:42                       ` Helmut Eller
  0 siblings, 0 replies; 46+ messages in thread
From: Helmut Eller @ 2021-02-22 18:42 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 46621

On Mon, Feb 22 2021, Eli Zaretskii wrote:

>> One example where copy-line would be useful is editing configuration
>> files.  E.g. /etc/ssh/sshd_config list many options with the default
>> value but as comments, like so:
>> 
>>   #SyslogFacility AUTH
>>   #LogLevel INFO
>>   ... other options ...
>>   
>> Now, if I want to change LogLevel to say DEBUG, I would copy the line,
>> keep the original, and edit the copied line.
>
> I already mentioned M-/ as the alternative.  In the above case, type
> "#L M-/", and Emacs will complete to "#LogLevel".  IOW, if these cases
> are considered as "repeat a previous word" rather than "copy a
> previous line, then edit it", the solution already exists.  I suspect
> that people who are looking for this command simply don't know about
> M-/ in Emacs, because IME it's still quite a unique feature.

I certainly know about M-/, but in this situation it's pretty far down
the list of alternatives I would consider.  Killing the whole line and
inserting it two times is what I usually end up doing.

Admittedly, I do have my own copy-line command and it's bound to C-x-,.
But I often forget the key binding.

Helmut





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-22 18:32                       ` Helmut Eller
@ 2021-02-22 19:41                         ` Howard Melman
  2021-02-22 19:46                           ` bug#46621: [External] : " Drew Adams
  0 siblings, 1 reply; 46+ messages in thread
From: Howard Melman @ 2021-02-22 19:41 UTC (permalink / raw)
  To: 46621


>> But you don't need the repeat count for that.  copy-from-above-command
>> will work well for this task.
>
> I didn't know about this.  But if I place point between LogLevel and
> INFO and then execute M-x copy-from-above-command then the result is
>
>  #LogLevelcility AUTH INFO
>
> which is not what is needed in this situation.

I never knew about copy-from-above-command either.  It's not
bound to any keys.  It's not in the emacs manual.  I think
it's also named incorrectly.

In emacs terminology it's not copying the text (like to the
kill-ring) but inserting or yanking it into the buffer (just
not from the kill-ring but from the previous line). It seems
closer in concept to how dabbrev and hippie use the term
"expand".

-- 

Howard






^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: [External] : bug#46621: Copy line
  2021-02-22 19:41                         ` Howard Melman
@ 2021-02-22 19:46                           ` Drew Adams
  2021-02-23 19:29                             ` Dmitry Gutov
  0 siblings, 1 reply; 46+ messages in thread
From: Drew Adams @ 2021-02-22 19:46 UTC (permalink / raw)
  To: Howard Melman, 46621

Why on earth is this called `copy-from-above-command'?

"-command"?

Maybe it would help to add a more discoverable alias?






^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: Copy line
  2021-02-22 15:43                 ` Eli Zaretskii
  2021-02-22 16:28                   ` Helmut Eller
  2021-02-22 17:04                   ` Gregory Heytings
@ 2021-02-22 20:51                   ` Stephen Berman
  2 siblings, 0 replies; 46+ messages in thread
From: Stephen Berman @ 2021-02-22 20:51 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 46621, larsi, Juri Linkov, rms, mardani29

On Mon, 22 Feb 2021 17:43:28 +0200 Eli Zaretskii <eliz@gnu.org> wrote:

> Bottom line, if we want to consider this command, we should somehow
> come up with the relevant use cases, and then weigh them against the
> added complexity and maintenance costs.  I therefore urge people who
> think they know these details to please speak up and contribute to
> this discussion.

I frequently use the following command (bound to `C-c l'), which suits
my needs better than the proposed command would or dabbrev-expand does:

(defun srb-select-line ()
  "Select line at point and copy to kill ring."
  (interactive)
  (copy-region-as-kill (line-beginning-position) (line-end-position)))

A common use case for me is copying somewhat complex shell commands I
keep stored in a file; they are stored as one liners to be easy to copy.
I don't want them to be immediately yanked into the file and for these
cases I don't need the feature of multiple copies via a prefix argument
(though in some documents I often do want multiple copies of a single
line, but usually at different parts of the document, so then just
yanking at the different locations is better than moving the copies).

Steve Berman





^ permalink raw reply	[flat|nested] 46+ messages in thread

* bug#46621: [External] : bug#46621: Copy line
  2021-02-22 19:46                           ` bug#46621: [External] : " Drew Adams
@ 2021-02-23 19:29                             ` Dmitry Gutov
  0 siblings, 0 replies; 46+ messages in thread
From: Dmitry Gutov @ 2021-02-23 19:29 UTC (permalink / raw)
  To: Drew Adams, Howard Melman, 46621

On 22.02.2021 21:46, Drew Adams wrote:
> Why on earth is this called `copy-from-above-command'?
> 
> "-command"?
> 
> Maybe it would help to add a more discoverable alias?

Both good points.





^ permalink raw reply	[flat|nested] 46+ messages in thread

end of thread, other threads:[~2021-02-23 19:29 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-18 19:07 bug#46621: Copy line Juri Linkov
2021-02-18 19:30 ` bug#46621: [External] : " Drew Adams
2021-02-20  6:58   ` Richard Stallman
2021-02-19 13:09 ` Lars Ingebrigtsen
2021-02-19 20:27   ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-02-20  6:54     ` Eli Zaretskii
2021-02-20 13:05       ` Lars Ingebrigtsen
2021-02-20 13:12         ` Eli Zaretskii
2021-02-20 13:18           ` Lars Ingebrigtsen
2021-02-20 14:15             ` Eli Zaretskii
2021-02-20 14:35               ` Dmitry Gutov
2021-02-20 13:03     ` Lars Ingebrigtsen
2021-02-20 18:28       ` Juri Linkov
2021-02-21  6:16         ` Richard Stallman
2021-02-21  6:21         ` Richard Stallman
2021-02-21  8:54           ` Juri Linkov
2021-02-21 10:41             ` Eli Zaretskii
2021-02-21 13:12               ` Lars Ingebrigtsen
2021-02-21 13:19                 ` Eli Zaretskii
2021-02-21 15:51                   ` Lars Ingebrigtsen
2021-02-21 17:06                     ` Eli Zaretskii
2021-02-21 17:39                       ` Lars Ingebrigtsen
2021-02-21 18:00                     ` bug#46621: [External] : " Drew Adams
2021-02-21 17:45                 ` Drew Adams
2021-02-22  6:22                 ` Richard Stallman
2021-02-21 17:41               ` bug#46621: [External] : " Drew Adams
2021-02-21 20:37               ` Juri Linkov
2021-02-21 22:06                 ` bug#46621: [External] : " Drew Adams
2021-02-22 15:45                 ` Eli Zaretskii
2021-02-21 23:04             ` Howard Melman
2021-02-22  6:23             ` Richard Stallman
2021-02-22  9:07               ` Juri Linkov
2021-02-22 15:43                 ` Eli Zaretskii
2021-02-22 16:28                   ` Helmut Eller
2021-02-22 16:58                     ` Andreas Schwab
2021-02-22 18:32                       ` Helmut Eller
2021-02-22 19:41                         ` Howard Melman
2021-02-22 19:46                           ` bug#46621: [External] : " Drew Adams
2021-02-23 19:29                             ` Dmitry Gutov
2021-02-22 17:08                     ` Eli Zaretskii
2021-02-22 18:42                       ` Helmut Eller
2021-02-22 17:04                   ` Gregory Heytings
2021-02-22 17:16                     ` Eli Zaretskii
2021-02-22 17:54                       ` Gregory Heytings
2021-02-22 20:51                   ` Stephen Berman
2021-02-21 13:13         ` Lars Ingebrigtsen

unofficial mirror of bug-gnu-emacs@gnu.org 

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/emacs-bugs/0 emacs-bugs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 emacs-bugs emacs-bugs/ https://yhetil.org/emacs-bugs \
		bug-gnu-emacs@gnu.org
	public-inbox-index emacs-bugs

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.bugs
	nntp://news.gmane.io/gmane.emacs.bugs


AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git