728x90
반응형

Emacs에서는 기본적으로 다른 에디터에서 많이 사용되는 기능 중에 하나인 한 줄을 위아래로 옮길 수 없다.

 

이를 사용하기 위해서 init.el에 다음을 추가하면 된다.

(defun move-line (n)
  "Move the current line up or down by N lines."
  (interactive "p")
  (setq col (current-column))
  (beginning-of-line) (setq start (point))
  (end-of-line) (forward-char) (setq end (point))
  (let ((line-text (delete-and-extract-region start end)))
    (forward-line n)
    (insert line-text)
    ;; restore point to original column in moved line
    (forward-line -1)
    (forward-char col)))

(defun move-line-up (n)
  "Move the current line up by N lines."
  (interactive "p")
  (move-line (if (null n) -1 (- n))))

(defun move-line-down (n)
  "Move the current line down by N lines."
  (interactive "p")
  (move-line (if (null n) 1 n)))

(global-set-key (kbd "M-<up>") 'move-line-up)
(global-set-key (kbd "M-<down>") 'move-line-down)

 

참고 문헌

  1. https://www.emacswiki.org/emacs/MoveLine

반응형

+ Recent posts