branch: master
commit a0414291f190b281535698a9eadb22a5e974f6ce
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>

    avy.el (avy-copy-region): Obey avy-line-insert-style
    
    Re #117
---
 avy.el |   30 ++++++++++++++++++------------
 1 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/avy.el b/avy.el
index 165087c..2d4b5a0 100644
--- a/avy.el
+++ b/avy.el
@@ -1138,18 +1138,24 @@ ARG lines can be used."
   "Select two lines and copy the text between them here."
   (interactive)
   (avy-with avy-copy-region
-    (let ((beg (avy--line))
-          (end (avy--line))
-          (pad (if (bolp) "" "\n")))
-      (move-beginning-of-line nil)
-      (save-excursion
-        (insert
-         (buffer-substring-no-properties
-          beg
-          (save-excursion
-            (goto-char end)
-            (line-end-position)))
-         pad)))))
+    (let* ((beg (avy--line))
+           (end (avy--line))
+           (str (buffer-substring-no-properties
+                 beg
+                 (save-excursion
+                   (goto-char end)
+                   (line-end-position)))))
+      (cond ((eq avy-line-insert-style 'above)
+             (beginning-of-line)
+             (save-excursion
+               (insert str "\n")))
+            ((eq avy-line-insert-style 'below)
+             (end-of-line)
+             (newline)
+             (save-excursion
+               (insert str)))
+            (t
+             (user-error "Unexpected `avy-line-insert-style'"))))))
 
 ;;;###autoload
 (defun avy-setup-default ()

Reply via email to