在http://blog.csdn.net/delphinew/archive/2008/02/29/2131689.aspx看到的, 滿不錯的整理一下自己備忘.
在Emacs中使用Alt+up Alt+down移動mark region
;; ----------------------------------------------------
;; Alt+up Alt+down 移動mark region
;; ----------------------------------------------------
(defun move-region-around (direction beg end)
(let (real-beg
real-end
target-beg
deactivate-mark
text)
(save-excursion
(goto-char beg)
(setq real-beg (line-beginning-position))
(when (equal direction 'up)
(setq target-beg (line-beginning-position 0)))
(goto-char end)
(setq real-end (line-beginning-position 2))
(when (equal direction 'down)
(setq target-beg (copy-marker (line-beginning-position 3)))) ;must use marker
(setq text (buffer-substring-no-properties real-beg real-end))
(delete-region real-beg real-end)
(goto-char target-beg)
(insert text)
)
(set-mark (+ target-beg (- real-end real-beg 1)))
(goto-char target-beg)
(setq transient-mark-mode 'only)))
(defun move-region-up (beg end)
(interactive "r")
(move-region-around 'up beg end))
(defun move-region-down (beg end)
(interactive "r")
(move-region-around 'down beg end))
(global-set-key (quote [M-up]) (quote move-region-up))
(global-set-key (quote [M-down]) (quote move-region-down))
(global-set-key "\C-c2" 'circle-windows)
Note
好會會造成transient-mark-mode disable ??
沒有留言:
張貼留言