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: Mathias Dahl
Subject: Re: Anyone have a 'move-line' function?
Date: Wed, 03 May 2006 10:17:53 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (windows-nt)

Joe Smith <jes@martnet.com> writes:

> 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

The following is quite ugly but seems to work. I am sure someone else
can come up with something much cleaner:

(defun move-line-up ()
  (interactive)
  (let ((col (current-column)))
    (beginning-of-line) 
    (kill-line 1)
    (previous-line 1)
    (yank)
    (previous-line 1)
    (beginning-of-line)
    (forward-char col)))

If you don't have `current-column' in your Emacs (for some reason, I
actually don't know why I believe this would be the case...), the
following does the same thing:

(defun move-line-up ()
  (interactive)
  (let ((col (- (point) 
                (save-excursion
                  (beginning-of-line)
                  (point)))))
    (beginning-of-line)
    (kill-line 1)
    (previous-line 1)
    (yank)
    (previous-line 1)
    (beginning-of-line)
    (forward-char col)))

/Mathias


reply via email to

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