Permalink
Browse files

Add move region

  • Loading branch information...
jimweirich committed Mar 28, 2013
1 parent a9b547c commit 522df247848f2d7ca3fd556856e8217e1c33ff49
Showing with 29 additions and 0 deletions.
  1. +2 −0 keys.el
  2. +27 −0 move-region.el
View
@@ -22,6 +22,8 @@
;;; Meta *
(global-set-key (kbd "M-g") 'goto-line)
(global-set-key (kbd "M-n") 'move-region-down)
(global-set-key (kbd "M-p") 'move-region-up)
(global-set-key (kbd "M-q") 'jw-fill-paragraph)
(global-set-key (kbd "M-]") 'jw-indent-block)
(global-set-key (kbd "M-[") 'jw-outdent-block)
View
@@ -0,0 +1,27 @@
(defun move-line-region-up (start end n)
(interactive "r\np")
(if (region-active-p) (move-region-up start end n) (move-line-up n)))
(defun move-line-region-down (start end n)
(interactive "r\np")
(if (region-active-p) (move-region-down start end n) (move-line-down n)))
(defun move-region (start end n)
"Move the current region up or down by N lines."
(interactive "r\np")
(let ((line-text (delete-and-extract-region start end)))
(forward-line n)
(let ((start (point)))
(insert line-text)
(setq deactivate-mark nil)
(set-mark start))))
(defun move-region-up (start end n)
"Move the current line up by N lines."
(interactive "r\np")
(move-region start end (if (null n) -1 (- n))))
(defun move-region-down (start end n)
"Move the current line down by N lines."
(interactive "r\np")
(move-region start end (if (null n) 1 n)))

0 comments on commit 522df24

Please sign in to comment.