From: Eli Zaretskii <eliz@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Move line
Date: Sun, 01 Jun 2008 00:15:07 +0300 [thread overview]
Message-ID: <u3any89b8.fsf@gnu.org> (raw)
In-Reply-To: <c37a18d6-f455-46ad-a378-61a51663ee2f@c65g2000hsa.googlegroups.com>
> 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.
next prev parent reply other threads:[~2008-05-31 21:15 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-31 15:57 Move line rock69
2008-05-31 16:53 ` rock69
2008-05-31 21:15 ` Eli Zaretskii [this message]
2008-05-31 21:22 ` Lennart Borgman (gmail)
2008-06-01 3:14 ` Eli Zaretskii
[not found] ` <mailman.12500.1212268508.18990.help-gnu-emacs@gnu.org>
2008-05-31 23:03 ` Joost Kremers
2008-06-01 5:48 ` Thien-Thi Nguyen
2008-05-31 21:51 ` Peter Dyballa
2008-06-01 5:39 ` William Xu
2008-06-01 5:57 ` Bastien
2008-06-02 12:34 ` Ken Goldman
-- strict thread matches above, loose matches on Subject: below --
2008-06-01 7:39 martin rudalics
2008-06-01 7:54 ` Lennart Borgman (gmail)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=u3any89b8.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.