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

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

Re: Move line


From: Eli Zaretskii
Subject: Re: Move line
Date: Sun, 01 Jun 2008 00:15:07 +0300

> 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.




reply via email to

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