Created
October 4, 2010 22:29
-
-
Save jasonm23/610579 to your computer and use it in GitHub Desktop.
move-text.el for emacs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 | |
(let ((column (current-column))) | |
(beginning-of-line) | |
(when (or (> arg 0) (not (bobp))) | |
(forward-line) | |
(when (or (< arg 0) (not (eobp))) | |
(transpose-lines arg)) | |
(forward-line -1)) | |
(move-to-column column t))))) | |
(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))) | |
(provide 'move-text) | |
(global-set-key [M-up] 'move-text-up) | |
(global-set-key [M-down] 'move-text-down) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment