all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* RE: Anyone have a 'move-line' function?
@ 2006-05-04 12:11 Bourgneuf Francois
  0 siblings, 0 replies; 10+ messages in thread
From: Bourgneuf Francois @ 2006-05-04 12:11 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Anyone have a 'move-line' function?
@ 2006-05-02 18:44 Joe Smith
  0 siblings, 0 replies; 10+ messages in thread
From: Joe Smith @ 2006-05-02 18:44 UTC (permalink / raw)


I'd like a function that moves the current line up (or down) in a 
buffer. I just make do with kill/yank or transpose-lines, but sometimes 
I'd just like to hit a key and move the line, preferably without losing 
point.

As an exercise, I played with writing such a function, and I have 
something that works but it turns out to be fairly tricky to get it 
exactly right. So if there's something already done, or I've missed 
something obvious (most likely), I'll study that before I keep banging away.

<Joe

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

end of thread, other threads:[~2006-05-05  0:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1234.1146610060.9609.help-gnu-emacs@gnu.org>
2006-05-02 23:33 ` Anyone have a 'move-line' function? Bastien
2006-05-03  3:46   ` Joe Smith
     [not found]   ` <mailman.1250.1146628814.9609.help-gnu-emacs@gnu.org>
2006-05-03  8:17     ` Mathias Dahl
2006-05-03 21:03     ` liyer.vijay
2006-05-04 15:29       ` Joe Smith
2006-05-04 16:24         ` John Conrad
2006-05-04 20:03           ` Joe Smith
     [not found]       ` <mailman.1411.1146756636.9609.help-gnu-emacs@gnu.org>
2006-05-05  0:09         ` liyer.vijay
2006-05-04 12:11 Bourgneuf Francois
  -- strict thread matches above, loose matches on Subject: below --
2006-05-02 18:44 Joe Smith

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.