avy.el (avy-copy-region): Fix for multi-buffer use

Fixes #119
This commit is contained in:
Oleh Krehel 2015-12-07 11:01:52 +01:00
parent 54074c764d
commit fa6d1e1242

49
avy.el
View File

@ -1143,28 +1143,33 @@ ARG lines can be used."
(user-error "Unexpected `avy-line-insert-style'")))))) (user-error "Unexpected `avy-line-insert-style'"))))))
;;;###autoload ;;;###autoload
(defun avy-copy-region () (defun avy-copy-region (arg)
"Select two lines and copy the text between them here." "Select two lines and copy the text between them to point.
(interactive)
(avy-with avy-copy-region The window scope is determined by `avy-all-windows' or
(let* ((beg (avy--line)) `avy-all-windows-alt' when ARG is non-nil."
(end (avy--line)) (interactive "P")
(str (buffer-substring-no-properties (let ((initial-window (selected-window)))
beg (avy-with avy-copy-region
(save-excursion (let* ((beg (avy--line arg))
(goto-char end) (end (avy--line arg))
(line-end-position))))) (str (buffer-substring-no-properties
(cond ((eq avy-line-insert-style 'above) beg
(beginning-of-line) (save-excursion
(save-excursion (goto-char end)
(insert str "\n"))) (line-end-position)))))
((eq avy-line-insert-style 'below) (select-window initial-window)
(end-of-line) (cond ((eq avy-line-insert-style 'above)
(newline) (beginning-of-line)
(save-excursion (save-excursion
(insert str))) (insert str "\n")))
(t ((eq avy-line-insert-style 'below)
(user-error "Unexpected `avy-line-insert-style'")))))) (end-of-line)
(newline)
(save-excursion
(insert str)))
(t
(user-error "Unexpected `avy-line-insert-style'")))))))
;;;###autoload ;;;###autoload
(defun avy-setup-default () (defun avy-setup-default ()