* Move selection up, down
@ 2008-08-19 14:21 jiri.pejchal
2008-08-19 21:27 ` harven
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: jiri.pejchal @ 2008-08-19 14:21 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Move selection up, down
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-20 0:45 ` Andreas Politz
2014-12-12 19:14 ` jsglazer
2 siblings, 1 reply; 7+ messages in thread
From: harven @ 2008-08-19 21:27 UTC (permalink / raw)
To: help-gnu-emacs
On Aug 19, 4:21 pm, "jiri.pejc...@gmail.com" <jiri.pejc...@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
There are similar functionalities in emacs,
although the bindings are different. For example, the command that
transposes two
consecutive lines is called transpose-lines and is bound to C-x C-t by
default. Other transpose commands include transpose-region, transpose-
char, transpose-paragraphs, transpose-words, transpose-sentences.
You can also redefine such functionalities
by hand using a bit of lisp code. For example,
if I want to exchange two consecutive lines, I can define the
following command:
(defun line-down ()
(interactive)
(save-excursion
(beginning-of-line)
(kill-line 1)
(next-line)
(yank))
(next-line))
and bind it to C-S-down:
(global-set-key (kbd "C-S-<down>") 'line-down)
This may convince you that new functionalities
are easily added to emacs.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Move selection up, down
2008-08-19 21:27 ` harven
@ 2008-08-19 22:43 ` Chat
0 siblings, 0 replies; 7+ messages in thread
From: Chat @ 2008-08-19 22:43 UTC (permalink / raw)
To: help-gnu-emacs
harven <harven@free.fr> writes:
> On Aug 19, 4:21 pm, "jiri.pejc...@gmail.com" <jiri.pejc...@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
>
> There are similar functionalities in emacs,
> although the bindings are different. For example, the command that
> transposes two
> consecutive lines is called transpose-lines and is bound to C-x C-t by
> default. Other transpose commands include transpose-region, transpose-
> char, transpose-paragraphs, transpose-words, transpose-sentences.
>
> You can also redefine such functionalities
> by hand using a bit of lisp code. For example,
> if I want to exchange two consecutive lines, I can define the
> following command:
>
> (defun line-down ()
> (interactive)
> (save-excursion
> (beginning-of-line)
> (kill-line 1)
> (next-line)
> (yank))
> (next-line))
>
> and bind it to C-S-down:
>
> (global-set-key (kbd "C-S-<down>") 'line-down)
>
> This may convince you that new functionalities
> are easily added to emacs.
For simple things like this, reading the secion "emacs" -> "keyboard macros" in
M-x info also helps.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Move selection up, down
2008-08-19 14:21 Move selection up, down jiri.pejchal
2008-08-19 21:27 ` harven
@ 2008-08-20 0:45 ` Andreas Politz
2008-09-11 17:04 ` Oleksandr Gavenko
2013-07-04 12:15 ` teemu.leisti
2014-12-12 19:14 ` jsglazer
2 siblings, 2 replies; 7+ messages in thread
From: Andreas Politz @ 2008-08-20 0:45 UTC (permalink / raw)
To: help-gnu-emacs
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)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Move selection up, down
2008-08-20 0:45 ` Andreas Politz
@ 2008-09-11 17:04 ` Oleksandr Gavenko
2013-07-04 12:15 ` teemu.leisti
1 sibling, 0 replies; 7+ messages in thread
From: Oleksandr Gavenko @ 2008-09-11 17:04 UTC (permalink / raw)
To: help-gnu-emacs
Andreas Politz wrote:
> 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)
After that code people decide stay in NetBeans than move to Emacs :).
Humor about ability of emacs (butterfly-mode):
http://www.digitalsanctuary.com/tech-blog/general/why-use-emacs-instead-of-vi.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Move selection up, down
2008-08-20 0:45 ` Andreas Politz
2008-09-11 17:04 ` Oleksandr Gavenko
@ 2013-07-04 12:15 ` teemu.leisti
1 sibling, 0 replies; 7+ messages in thread
From: teemu.leisti @ 2013-07-04 12:15 UTC (permalink / raw)
To: help-gnu-emacs
On Wednesday, 20 August 2008 03:45:02 UTC+3, Andreas Politz wrote:
> 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.
Brilliant! Thanks for this.
-- Teemu Leisti
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Move selection up, down
2008-08-19 14:21 Move selection up, down jiri.pejchal
2008-08-19 21:27 ` harven
2008-08-20 0:45 ` Andreas Politz
@ 2014-12-12 19:14 ` jsglazer
2 siblings, 0 replies; 7+ messages in thread
From: jsglazer @ 2014-12-12 19:14 UTC (permalink / raw)
To: help-gnu-emacs
On Tuesday, August 19, 2008 10:21:38 AM UTC-4, jiri.p...@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
Fantastic, thank you!
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-12-12 19:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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-20 0:45 ` Andreas Politz
2008-09-11 17:04 ` Oleksandr Gavenko
2013-07-04 12:15 ` teemu.leisti
2014-12-12 19:14 ` jsglazer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).