help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Keybinding to transpose current line with next line


From: Yuri Khan
Subject: Re: Keybinding to transpose current line with next line
Date: Wed, 23 Sep 2020 11:29:31 +0700

On Wed, 23 Sep 2020 at 03:06, Emanuel Berg via Users list for the GNU
Emacs text editor <help-gnu-emacs@gnu.org> wrote:

> > Secondly, transposing lines is a useful low-level
> > primitive, but IMO a much more handy UI metaphor is
> > dragging the line at point up or down through the
> > surrounding lines while preserving the point’s
> > position in the line.
>
> You mean like this?
>
> (defun transpose-next-line ()
>   (interactive)
>   (let ((beg (point))
>         (lin (line-number-at-pos) ))
>     (beginning-of-line)
>     (kill-line)
>     (yank)
>     (kill-line)
>     (forward-line -1)
>     (yank)
>     (goto-char beg)
>     (unless (= lin (line-number-at-pos))
>       (goto-char (point-min))
>       (forward-line (1- lin))
>       (end-of-line) )))
> (defalias 'tnl #'transpose-next-line) ; [1]

This might be good for you but org-drag-line-* have a couple
advantages over this:

* They do not pollute the kill ring.
* As you drag the line, point stays on the same character where you started.

   Lorem
   ips|um
   dolor
   ↓ (org-drag-line-down)
   Lorem
   dolor
   ips|um



reply via email to

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