emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 97cf30d 063/348: Add multiple-cursors support to ivy-compl


From: Oleh Krehel
Subject: [elpa] master 97cf30d 063/348: Add multiple-cursors support to ivy-completion-in-region-action
Date: Sat, 8 Apr 2017 11:03:25 -0400 (EDT)

branch: master
commit 97cf30dc9cb5473a1d6b0ff67950be556eb3de31
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Add multiple-cursors support to ivy-completion-in-region-action
    
    * ivy.el (ivy-completion-in-region-action): Do the same thing for each
      cursor as for point, with respective offset.
    
    Fixes #547
---
 ivy.el | 35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/ivy.el b/ivy.el
index b661a6d..f4f590d 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1635,20 +1635,37 @@ INHERIT-INPUT-METHOD is currently ignored."
 (defvar ivy-completion-end nil
   "Completion bounds end.")
 
+(declare-function mc/all-fake-cursors "ext:multiple-cursors-core")
+
 (defun ivy-completion-in-region-action (str)
   "Insert STR, erasing the previous one.
 The previous string is between `ivy-completion-beg' and `ivy-completion-end'."
   (when (stringp str)
     (with-ivy-window
-      (when ivy-completion-beg
-        (delete-region
-         ivy-completion-beg
-         ivy-completion-end))
-      (setq ivy-completion-beg
-            (move-marker (make-marker) (point)))
-      (insert (substring-no-properties str))
-      (setq ivy-completion-end
-            (move-marker (make-marker) (point))))))
+      (let ((fake-cursors (and (featurep 'multiple-cursors)
+                               (mc/all-fake-cursors)))
+            (pt (point))
+            (beg ivy-completion-beg)
+            (end ivy-completion-end))
+        (when ivy-completion-beg
+          (delete-region
+           ivy-completion-beg
+           ivy-completion-end))
+        (setq ivy-completion-beg
+              (move-marker (make-marker) (point)))
+        (insert (substring-no-properties str))
+        (setq ivy-completion-end
+              (move-marker (make-marker) (point)))
+        (save-excursion
+          (dolist (cursor fake-cursors)
+            (goto-char (overlay-start cursor))
+            (delete-region (+ (point) (- beg pt))
+                           (+ (point) (- end pt)))
+            (insert (substring-no-properties str))
+            ;; manually move the fake cursor
+            (move-overlay cursor (point) (1+ (point)))
+            (move-marker (overlay-get cursor 'point) (point))
+            (move-marker (overlay-get cursor 'mark) (point))))))))
 
 (defun ivy-completion-common-length (str)
   "Return the length of the first 'completions-common-part face in STR."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]