[Top][All Lists]

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

Re: line-move-down-up

From: Alin Soare
Subject: Re: line-move-down-up
Date: Wed, 20 Apr 2011 20:22:53 +0300

> If I use C-x C-t, the cursor goes down, while the line goes up. I cannot
> move the line the second time.

Which line?  Obviously one line is moving down if another is moving up.
If you want point to move along with the upward-moving line rather than
the downward-moving one, use C-- C-x C-t (and then C-x z z ... as needed).

> And this only transposes the line, not move the line.

What's the difference?

This is a good question. Please, can you write 2 lambda functions that behaves exactly like the code below, and attach them to M-up , M-down ?

You should use only transpose-line, and none other function that deletes text, like delete-and-extract-region, kill-line, etc.

(defun line-move-- (n)
  (if (> (point-max) (point-at-eol))
      (let ((column (current-column) )
            (line (delete-and-extract-region (point-at-bol) (1+ (point-at-eol)))))
        (forward-line n)
        (insert-string line)
        (move-to-column column) ) ) )

(define-key global-map [(meta up)]
  (lambda (&optional n)
    (interactive "P")
    (line-move-- (- (if (numberp n) n 1) ) ) ) )

(define-key global-map [(meta down)]
  (lambda (&optional n)
    (interactive "P")
    (line-move-- (if (numberp n) n 1) )  ) )


Using transpose-line , it is much direct to simulate line-move--down than I did.

reply via email to

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