I have been using eclipse for a little while now and I did find some shortcuts highly useful, in particular the ability to move a rectangular selection of lines up and down using Alt+Up/Down. I have been looking around for this functionality in emacs. So far I have found the following script:
(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-up] 'move-text-up)
(global-set-key [\M-down] 'move-text-down)
This does work except for the fact that this moves the selection. I would rather move all lines (including trailing newline) included in the selection instead. Is there a way to realize this as well?