* Re: master 6362f65474: Add new command `duplicate-line' [not found] ` <20220617173432.17B6FC00BAF@vcs2.savannah.gnu.org> @ 2022-06-17 17:44 ` Visuwesh 2022-06-17 17:47 ` Lars Ingebrigtsen 2022-06-18 16:30 ` Ergus 0 siblings, 2 replies; 10+ messages in thread From: Visuwesh @ 2022-06-17 17:44 UTC (permalink / raw) To: emacs-devel; +Cc: Lars Ingebrigtsen [வெள்ளி ஜூன் 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 > \f > * 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: master 6362f65474: Add new command `duplicate-line' 2022-06-17 17:44 ` master 6362f65474: Add new command `duplicate-line' Visuwesh @ 2022-06-17 17:47 ` Lars Ingebrigtsen 2022-06-18 16:30 ` Ergus 1 sibling, 0 replies; 10+ messages in thread From: Lars Ingebrigtsen @ 2022-06-17 17:47 UTC (permalink / raw) To: Visuwesh; +Cc: emacs-devel Visuwesh <visuweshm@gmail.com> writes: >> +Also see the `copy-line' command." > > Shouldn't this be `duplicate-line'? Yup; now fixed. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: master 6362f65474: Add new command `duplicate-line' 2022-06-17 17:44 ` master 6362f65474: Add new command `duplicate-line' Visuwesh 2022-06-17 17:47 ` Lars Ingebrigtsen @ 2022-06-18 16:30 ` Ergus 2022-06-18 16:52 ` Eli Zaretskii 2022-06-19 11:06 ` Lars Ingebrigtsen 1 sibling, 2 replies; 10+ messages in thread From: Ergus @ 2022-06-18 16:30 UTC (permalink / raw) To: emacs-devel, Lars Ingebrigtsen 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 > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: master 6362f65474: Add new command `duplicate-line' 2022-06-18 16:30 ` Ergus @ 2022-06-18 16:52 ` Eli Zaretskii 2022-06-18 22:22 ` Ergus 2022-06-19 11:06 ` Lars Ingebrigtsen 1 sibling, 1 reply; 10+ messages in thread From: Eli Zaretskii @ 2022-06-18 16:52 UTC (permalink / raw) To: Ergus; +Cc: emacs-devel, larsi > Date: Sat, 18 Jun 2022 18:30:43 +0200 > From: Ergus <spacibba@aol.com> > > 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? Isn't that what transpose-lines already provides? ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: master 6362f65474: Add new command `duplicate-line' 2022-06-18 16:52 ` Eli Zaretskii @ 2022-06-18 22:22 ` Ergus 2022-06-19 5:55 ` Eli Zaretskii 2022-06-19 11:55 ` Andreas Schwab 0 siblings, 2 replies; 10+ messages in thread From: Ergus @ 2022-06-18 22:22 UTC (permalink / raw) To: Eli Zaretskii; +Cc: emacs-devel, larsi On Sat, Jun 18, 2022 at 07:52:30PM +0300, Eli Zaretskii wrote: >> Date: Sat, 18 Jun 2022 18:30:43 +0200 >> From: Ergus <spacibba@aol.com> >> >> 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? > >Isn't that what transpose-lines already provides? > Actually no, transpose-lines is very confusing from the user point of view... because the line moved is not the current one, but the previous one... but also, the cursor moves with it but not to it, but to the beginning of the next one, so we lost the current column position and line; so it looks like a command that acts outside the current position and moves the cursor to random places. Moving the current line one row up means all these steps: (let ((column (current-column))) (next-line) (transpose-lines -1) (previous-line) (forward-char column)) Could we make user live easier for simple editing stuff?? These commands + a repeat keymap are very useful? Best, Ergus ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: master 6362f65474: Add new command `duplicate-line' 2022-06-18 22:22 ` Ergus @ 2022-06-19 5:55 ` Eli Zaretskii 2022-06-19 11:55 ` Andreas Schwab 1 sibling, 0 replies; 10+ messages in thread From: Eli Zaretskii @ 2022-06-19 5:55 UTC (permalink / raw) To: Ergus; +Cc: emacs-devel, larsi > Date: Sun, 19 Jun 2022 00:22:25 +0200 > From: Ergus <spacibba@aol.com> > Cc: emacs-devel@gnu.org, larsi@gnus.org > > On Sat, Jun 18, 2022 at 07:52:30PM +0300, Eli Zaretskii wrote: > >> Date: Sat, 18 Jun 2022 18:30:43 +0200 > >> From: Ergus <spacibba@aol.com> > >> > >> 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? > > > >Isn't that what transpose-lines already provides? > > > Actually no, transpose-lines is very confusing from the user point of > view... because the line moved is not the current one, but the previous > one... > > but also, the cursor moves with it but not to it, but to the beginning > of the next one, so we lost the current column position and line; so it > looks like a command that acts outside the current position and moves > the cursor to random places. This just means you don't use that command frequently, or not at all. It's one of the oldest and more useful text-editing commands in Emacs. The solution to all of your problems is just one C-n (or C-p, as the case may be), and that IMNSHO is a much smaller penalty than introduction of a new command, binding it to some key that is both short enough to be convenient and unused by other commands, and many other repercussions all over the place. > Could we make user live easier for simple editing stuff?? Since when moving a line is an important enough operation for us to try to make it much easier than it already is? How many times do you need to move a line in your editing, and for what purposes? > These commands + a repeat keymap are very useful? I'm guessing you are used to it in "some other editor", so your muscle memory longs for it. Right? ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: master 6362f65474: Add new command `duplicate-line' 2022-06-18 22:22 ` Ergus 2022-06-19 5:55 ` Eli Zaretskii @ 2022-06-19 11:55 ` Andreas Schwab 1 sibling, 0 replies; 10+ messages in thread From: Andreas Schwab @ 2022-06-19 11:55 UTC (permalink / raw) To: Ergus; +Cc: Eli Zaretskii, emacs-devel, larsi On Jun 19 2022, Ergus wrote: > Actually no, transpose-lines is very confusing from the user point of > view... because the line moved is not the current one, but the previous > one... It actually exchanges the two items around point, and works like all other transpose commands in that regard. -- 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] 10+ messages in thread
* Re: master 6362f65474: Add new command `duplicate-line' 2022-06-18 16:30 ` Ergus 2022-06-18 16:52 ` Eli Zaretskii @ 2022-06-19 11:06 ` Lars Ingebrigtsen 2022-06-19 17:10 ` [External] : " Drew Adams 1 sibling, 1 reply; 10+ messages in thread From: Lars Ingebrigtsen @ 2022-06-19 11:06 UTC (permalink / raw) To: Ergus; +Cc: emacs-devel Ergus <spacibba@aol.com> writes: > 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 [...] > 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? I feel like most of these line based commands exist in other editors because they don't have Emacs' `C-k'. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [External] : Re: master 6362f65474: Add new command `duplicate-line' 2022-06-19 11:06 ` Lars Ingebrigtsen @ 2022-06-19 17:10 ` Drew Adams 0 siblings, 0 replies; 10+ messages in thread From: Drew Adams @ 2022-06-19 17:10 UTC (permalink / raw) To: Lars Ingebrigtsen, Ergus; +Cc: emacs-devel@gnu.org > I feel like most of these line based commands exist > in other editors because they don't have Emacs' `C-k'. More generally, they don't have Emacs... ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: master 6362f65474: Add new command `duplicate-line' @ 2022-06-19 5:53 Pedro Andres Aranda Gutierrez 0 siblings, 0 replies; 10+ messages in thread From: Pedro Andres Aranda Gutierrez @ 2022-06-19 5:53 UTC (permalink / raw) To: emacs-devel [-- Attachment #1: Type: text/plain, Size: 1189 bytes --] Hi I'm lagging behind the list... I recently saw the new duplicate-line function and I feel I have an alternative, which also takes the region into account: ;; ;; Duplicate region ;; (defun duplicate-region-after (beg end add-cr) "Insert a newline and duplicate after selection" (let ((dupstr (buffer-substring-no-properties beg end))) (goto-char end) (when add-cr (insert "\n")) (insert dupstr))) (defun duplicate-line-or-region (arg) "Duplicate the region or the line when nothing is selected" (interactive "p") (save-excursion (let ((b (if mark-active (region-beginning) (line-beginning-position))) (e (if mark-active (region-end) (line-end-position))) _ign) (dotimes (_ign arg) (duplicate-region-after b e (not mark-active))) ))) When and if I have CPU cycles I'd like to expand this to take a rectangular region into account. Best, /PA -- Fragen sind nicht da um beantwortet zu werden, Fragen sind da um gestellt zu werden Georg Kreisler Headaches with a Juju log: unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run a leader-deposed hook here, but we can't yet [-- Attachment #2: Type: text/html, Size: 2124 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-06-19 17:10 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <165548727183.24473.6170306052807994962@vcs2.savannah.gnu.org> [not found] ` <20220617173432.17B6FC00BAF@vcs2.savannah.gnu.org> 2022-06-17 17:44 ` master 6362f65474: Add new command `duplicate-line' Visuwesh 2022-06-17 17:47 ` Lars Ingebrigtsen 2022-06-18 16:30 ` Ergus 2022-06-18 16:52 ` Eli Zaretskii 2022-06-18 22:22 ` Ergus 2022-06-19 5:55 ` Eli Zaretskii 2022-06-19 11:55 ` Andreas Schwab 2022-06-19 11:06 ` Lars Ingebrigtsen 2022-06-19 17:10 ` [External] : " Drew Adams 2022-06-19 5:53 Pedro Andres Aranda Gutierrez
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).