Subject: Re: bug#64185: proposal for new function: copy-line

From: Juri Linkov <[email-masked]>
Date: Fri, 23 Jun 2023 19:45:31 +0300

>>  'duplicate-dwim' duplicates the region if it is active.  If not, it
>>  works like 'duplicate-line'.  An active rectangular region is
>> -duplicated on its right-hand side.
>> +duplicated on its right-hand side.  The new user option
>> +'duplicate-line-final-position' specifies where to move point
>> +after duplicating the line.
>
> This makes it unclear to what extent the variable affects
> `duplicate-dwim`.  (For some reason it only does so when the region is
> inactive, which doesn't seem right.)

The new command `duplicate-line` would be useless for many users
without that option.  There is no such problem for `duplicate-dwim`
that is more complicated.  It would be a major undertaking to design
a similar option for `duplicate-dwim` for consistency with `duplicate-line`
because of more decisions necessary to make: whether to move point
to the beginning or the end of the copied regions, whether to select
all the copied regions or only one of them, etc.

> And I agree that allowing any integer as value isn't necessary the
> best choice here.  It's a false flexibility; nobody will ever set it
> to something other than 0, 1 or -1.  Symbols would probably be better,
> for several reasons.

For users of the Customization UI the choices are explained clearly:

  :type '(choice (const :tag "Leave point on old line" 0)
                 (const :tag "Move point to first new line" 1)
                 (const :tag "Move point to last new line" -1)
                 (integer))

For users who know Emacs Lisp and like to write plain values in ~/.emacs,
the values 0, 1, -1 are more intuitive and familiar due to functions
like `substring`, etc.

BTW, to my surprise the shortdoc of `substring` has no examples
of a negative argument.  I don't know whether this omission
is intentional to make the string section shorter.