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

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

Re: Move line


From: Lennart Borgman (gmail)
Subject: Re: Move line
Date: Sat, 31 May 2008 23:22:57 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666

Eli Zaretskii wrote:
From: rock69 <rocco.rossi@gmail.com>
Date: Sat, 31 May 2008 09:53:35 -0700 (PDT)

(defun move-line (n)
   "Move the current line up or down by N lines."
   (interactive "p")
   (let ((col (current-column))
         start
         end)
     (beginning-of-line)
     (setq start (point))
     (end-of-line)
     (forward-char)
     (setq end (point))
     (let ((line-text (delete-and-extract-region start end)))
       (forward-line n)
       (insert line-text)
       ;; restore point to original column in moved line
       (forward-line -1)
       (forward-char col))))

(defun move-line-up (n)
   "Move the current line up by N lines."
   (interactive "p")
   (move-line (if (null n) -1 (- n))))

(defun move-line-down (n)
   "Move the current line down by N lines."
   (interactive "p")
   (move-line (if (null n) 1 n)))

(global-set-key (kbd "M-<up>") 'move-line-up)
(global-set-key (kbd "M-<down>") 'move-line-down)

Thanks all.

I have this in my ~/.emacs, which I think does what you want with much
less fuss:

 (global-set-key "\M-z" (function (lambda () (interactive) (scroll-down 1))))
 (global-set-key "\C-z" (function (lambda () (interactive) (scroll-up 1))))

Of course, I'm used to different keybindings, but the point is that
the code is much simpler and shorter.

But it moves the point instead of the line ...




reply via email to

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