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

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

RE: Anyone have a 'move-line' function?


From: Bourgneuf Francois
Subject: RE: Anyone have a 'move-line' function?
Date: Thu, 4 May 2006 14:11:05 +0200

I think the transpose-line command may be what you're looking for.

It is bound to C-x C-t.

Exchange current line and previous line, leaving point after both.
With argument ARG, takes previous line and moves it past ARG lines.
With argument 0, interchanges line point is in with line mark is in.

Bour9

-----Message d'origine-----
De : help-gnu-emacs-bounces+francois.bourgneuf=groupe-mma.fr@gnu.org 
[mailto:help-gnu-emacs-bounces+francois.bourgneuf=groupe-mma.fr@gnu.org] De la 
part de liyer.vijay@gmail.com
Envoyé : mercredi 3 mai 2006 23:04
À : help-gnu-emacs@gnu.org
Objet : Re: Anyone have a 'move-line' function?

Joe Smith wrote:
> If I start with this (^=point):
>
> one
> two
> th^ree
> four
>
> And I run 'move-line-up' (say by M-up), I want this:
>
> one
> th^ree
> two
> four
>
> Then run 'move-line-down' twice (say by M-down M-down) to get this:
>
> one
> two
> four
> th^ree

Here's a solution that doesn't add to the kill-ring (not that we'll
reach the kill ring limit :-)

(defun move-line-up (&optional n)
  "Moves current line up leaving point in place.  With a prefix
argument, moves up N lines."
  (interactive "p")
  (if (null n) (setq n 1))
  (let ((col (current-column)))
    (beginning-of-line)
    (next-line 1)
    (transpose-lines (- n))
    (previous-line 1)
    (forward-char col)))

Cheers
Vijay

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs





reply via email to

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