From: Andreas Politz <politza@fh-trier.de>
To: help-gnu-emacs@gnu.org
Subject: Re: Move selection up, down
Date: Wed, 20 Aug 2008 02:45:02 +0200 [thread overview]
Message-ID: <1219193209.777664@arno.fh-trier.de> (raw)
In-Reply-To: <1422fa24-05d5-436b-82e2-b436af0a00a3@m3g2000hsc.googlegroups.com>
jiri.pejchal@gmail.com wrote:
> Hi,
>
> in Netbeans when you press M-S-up/M-S-down you move the selected text
> up/down. When nothing is selected it moves the current line.
>
> With C-S-up/C-S-down you copy the selection up/down. When nothings is
> selected it copies the current line up/down.
>
> Is such functionality available in emacs?
>
> Jiri Pejchal
Heres some elisp. It binds M-S-up/down to commands
which move the active region (with respect to columns)
or the current line prefix arg lines up or down.
Have fun.
-ap
(defun move-text-internal (arg)
(cond
((and mark-active transient-mark-mode)
(if (> (point) (mark))
(exchange-point-and-mark))
(let ((column (current-column))
(text (delete-and-extract-region (point) (mark))))
(forward-line arg)
(move-to-column column t)
(set-mark (point))
(insert text)
(exchange-point-and-mark)
(setq deactivate-mark nil)))
(t
(beginning-of-line)
(when (or (> arg 0) (not (bobp)))
(forward-line)
(when (or (< arg 0) (not (eobp)))
(transpose-lines arg))
(forward-line -1)))))
(defun move-text-down (arg)
"Move region (transient-mark-mode active) or current line
arg lines down."
(interactive "*p")
(move-text-internal arg))
(defun move-text-up (arg)
"Move region (transient-mark-mode active) or current line
arg lines up."
(interactive "*p")
(move-text-internal (- arg)))
(global-set-key [\M-\S-up] 'move-text-up)
(global-set-key [\M-\S-down] 'move-text-down)
next prev parent reply other threads:[~2008-08-20 0:45 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-19 14:21 Move selection up, down jiri.pejchal
2008-08-19 21:27 ` harven
2008-08-19 22:43 ` Chat
2008-08-19 21:47 ` Lennart Borgman (gmail)
2008-08-19 22:31 ` Drew Adams
2008-08-19 22:58 ` Lennart Borgman (gmail)
2008-08-19 23:21 ` Drew Adams
2008-08-19 23:30 ` Lennart Borgman (gmail)
2008-08-19 23:40 ` Drew Adams
2008-08-19 23:48 ` Lennart Borgman (gmail)
2008-08-20 7:45 ` Jiri Pejchal
2008-08-20 8:15 ` martin rudalics
2008-08-20 23:11 ` Richard M. Stallman
2008-08-20 0:45 ` Andreas Politz [this message]
2008-09-11 17:04 ` Oleksandr Gavenko
2013-07-04 12:15 ` teemu.leisti
2014-12-12 19:14 ` jsglazer
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=1219193209.777664@arno.fh-trier.de \
--to=politza@fh-trier.de \
--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.