copy/move line to an initial window

This commit is contained in:
denin 2016-01-06 18:23:14 +03:00
parent 212a132d5f
commit 15d0679385

8
avy.el
View File

@ -1117,6 +1117,7 @@ Otherwise, forward to `goto-line' with ARG."
"Copy a selected line above the current line. "Copy a selected line above the current line.
ARG lines can be used." ARG lines can be used."
(interactive "p") (interactive "p")
(let ((initial-window (selected-window)))
(avy-with avy-copy-line (avy-with avy-copy-line
(let* ((start (avy--line)) (let* ((start (avy--line))
(str (buffer-substring-no-properties (str (buffer-substring-no-properties
@ -1125,6 +1126,7 @@ ARG lines can be used."
(goto-char start) (goto-char start)
(move-end-of-line arg) (move-end-of-line arg)
(point))))) (point)))))
(select-window initial-window)
(cond ((eq avy-line-insert-style 'above) (cond ((eq avy-line-insert-style 'above)
(beginning-of-line) (beginning-of-line)
(save-excursion (save-excursion
@ -1134,18 +1136,20 @@ ARG lines can be used."
(insert "\n" str) (insert "\n" str)
(beginning-of-line)) (beginning-of-line))
(t (t
(user-error "Unexpected `avy-line-insert-style'")))))) (user-error "Unexpected `avy-line-insert-style'")))))))
;;;###autoload ;;;###autoload
(defun avy-move-line (arg) (defun avy-move-line (arg)
"Move a selected line above the current line. "Move a selected line above the current line.
ARG lines can be used." ARG lines can be used."
(interactive "p") (interactive "p")
(let ((initial-window (selected-window)))
(avy-with avy-move-line (avy-with avy-move-line
(let ((start (avy--line))) (let ((start (avy--line)))
(save-excursion (save-excursion
(goto-char start) (goto-char start)
(kill-whole-line arg)) (kill-whole-line arg))
(select-window initial-window)
(cond ((eq avy-line-insert-style 'above) (cond ((eq avy-line-insert-style 'above)
(beginning-of-line) (beginning-of-line)
(save-excursion (save-excursion
@ -1157,7 +1161,7 @@ ARG lines can be used."
(save-excursion (save-excursion
(insert (substring (current-kill 0) 0 -1)))) (insert (substring (current-kill 0) 0 -1))))
(t (t
(user-error "Unexpected `avy-line-insert-style'")))))) (user-error "Unexpected `avy-line-insert-style'")))))))
;;;###autoload ;;;###autoload
(defun avy-copy-region (arg) (defun avy-copy-region (arg)