[Top][All Lists]

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

Re: Move selection up, down

From: Andreas Politz
Subject: Re: Move selection up, down
Date: Wed, 20 Aug 2008 02:45:02 +0200
User-agent: Mozilla-Thunderbird (X11/20080724)

address@hidden wrote:

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.

(defun move-text-internal (arg)
   ((and mark-active transient-mark-mode)
    (if (> (point) (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)
      (setq deactivate-mark nil)))
    (when (or (> arg 0) (not (bobp)))
      (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)

reply via email to

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