lisp/move-line.el
changeset 70 88c4f68cb191
parent 65 839e0a541c76
equal deleted inserted replaced
69:b3baf25406f8 70:88c4f68cb191
       
     1 ;; http://www.emacswiki.org/emacs/MoveLine
       
     2 
       
     3 (defun move-line (n)
       
     4   "Move the current line up or down by N lines."
       
     5   (interactive "p")
       
     6   (setq col (current-column))
       
     7   (beginning-of-line) (setq start (point))
       
     8   (end-of-line) (forward-char) (setq end (point))
       
     9   (let ((line-text (delete-and-extract-region start end)))
       
    10     (forward-line n)
       
    11     (insert line-text)
       
    12     ;; restore point to original column in moved line
       
    13     (forward-line -1)
       
    14     (forward-char col)))
       
    15 
       
    16 (defun move-line-up (n)
       
    17   "Move the current line up by N lines."
       
    18   (interactive "p")
       
    19   (move-line (if (null n) -1 (- n))))
       
    20 
       
    21 (defun move-line-down (n)
       
    22   "Move the current line down by N lines."
       
    23   (interactive "p")
       
    24   (move-line (if (null n) 1 n)))
       
    25 
       
    26 (message "Loading move-line...done")
       
    27 (provide 'move-line)