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

74
avy.el
View File

@ -1117,47 +1117,51 @@ 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")
(avy-with avy-copy-line (let ((initial-window (selected-window)))
(let* ((start (avy--line)) (avy-with avy-copy-line
(str (buffer-substring-no-properties (let* ((start (avy--line))
start (str (buffer-substring-no-properties
(save-excursion start
(goto-char start) (save-excursion
(move-end-of-line arg) (goto-char start)
(point))))) (move-end-of-line arg)
(cond ((eq avy-line-insert-style 'above) (point)))))
(beginning-of-line) (select-window initial-window)
(save-excursion (cond ((eq avy-line-insert-style 'above)
(insert str "\n"))) (beginning-of-line)
((eq avy-line-insert-style 'below) (save-excursion
(end-of-line) (insert str "\n")))
(insert "\n" str) ((eq avy-line-insert-style 'below)
(beginning-of-line)) (end-of-line)
(t (insert "\n" str)
(user-error "Unexpected `avy-line-insert-style'")))))) (beginning-of-line))
(t
(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")
(avy-with avy-move-line (let ((initial-window (selected-window)))
(let ((start (avy--line))) (avy-with avy-move-line
(save-excursion (let ((start (avy--line)))
(goto-char start) (save-excursion
(kill-whole-line arg)) (goto-char start)
(cond ((eq avy-line-insert-style 'above) (kill-whole-line arg))
(beginning-of-line) (select-window initial-window)
(save-excursion (cond ((eq avy-line-insert-style 'above)
(insert (beginning-of-line)
(current-kill 0)))) (save-excursion
((eq avy-line-insert-style 'below) (insert
(end-of-line) (current-kill 0))))
(newline) ((eq avy-line-insert-style 'below)
(save-excursion (end-of-line)
(insert (substring (current-kill 0) 0 -1)))) (newline)
(t (save-excursion
(user-error "Unexpected `avy-line-insert-style'")))))) (insert (substring (current-kill 0) 0 -1))))
(t
(user-error "Unexpected `avy-line-insert-style'")))))))
;;;###autoload ;;;###autoload
(defun avy-copy-region (arg) (defun avy-copy-region (arg)