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

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

[elpa] master e722d6a 046/167: swiper.el (swiper-mc): Add and bind to "C


From: Oleh Krehel
Subject: [elpa] master e722d6a 046/167: swiper.el (swiper-mc): Add and bind to "C-7"
Date: Tue, 08 Dec 2015 10:49:48 +0000

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

    swiper.el (swiper-mc): Add and bind to "C-7"
    
    * swiper.el (swiper-map): Update.
    (swiper-mc): New command.
    (swiper--ivy): Use :action.
    (swiper--action): Update arglist.
---
 swiper.el |   61 +++++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 41 insertions(+), 20 deletions(-)

diff --git a/swiper.el b/swiper.el
index 361769e..8ad9c54 100644
--- a/swiper.el
+++ b/swiper.el
@@ -109,6 +109,7 @@
     (define-key map (kbd "M-q") 'swiper-query-replace)
     (define-key map (kbd "C-l") 'swiper-recenter-top-bottom)
     (define-key map (kbd "C-'") 'swiper-avy)
+    (define-key map (kbd "C-7") 'swiper-mc)
     map)
   "Keymap for swiper.")
 
@@ -190,6 +191,27 @@
         (ivy-quit-and-run
          (avy-action-goto (caar candidate)))))))
 
+(declare-function mc/create-fake-cursor-at-point "ext:multiple-cursors-core")
+(declare-function mc/maybe-multiple-cursors-mode "ext:multiple-cursors-core")
+
+;;;###autoload
+(defun swiper-mc ()
+  (interactive)
+  (unless (require 'multiple-cursors nil t)
+    (error "multiple-cursors isn't installed"))
+  (let ((cands (nreverse ivy--old-cands)))
+    (unless (string= ivy-text "")
+      (ivy-set-action
+       (lambda (_)
+         (let (cand)
+           (while (setq cand (pop cands))
+             (swiper--action cand)
+             (when cands
+               (mc/create-fake-cursor-at-point))))
+         (mc/maybe-multiple-cursors-mode)))
+      (setq ivy-exit 'done)
+      (exit-minibuffer))))
+
 (defun swiper-recenter-top-bottom (&optional arg)
   "Call (`recenter-top-bottom' ARG)."
   (interactive "P")
@@ -319,24 +341,23 @@ When non-nil, INITIAL-INPUT is the initial search 
pattern."
         (preselect (buffer-substring-no-properties
                     (line-beginning-position)
                     (line-end-position)))
-        (minibuffer-allow-text-properties t)
-        res)
+        (minibuffer-allow-text-properties t))
     (unwind-protect
-         (setq res (ivy-read
-                    "Swiper: "
-                    candidates
-                    :initial-input initial-input
-                    :keymap swiper-map
-                    :preselect preselect
-                    :require-match t
-                    :update-fn #'swiper--update-input-ivy
-                    :unwind #'swiper--cleanup
-                    :re-builder #'swiper--re-builder
-                    :history 'swiper-history
-                    :caller 'swiper))
-      (if (null ivy-exit)
-          (goto-char swiper--opoint)
-        (swiper--action res ivy-text)))))
+        (ivy-read
+         "Swiper: "
+         candidates
+         :initial-input initial-input
+         :keymap swiper-map
+         :preselect preselect
+         :require-match t
+         :update-fn #'swiper--update-input-ivy
+         :unwind #'swiper--cleanup
+         :action #'swiper--action
+         :re-builder #'swiper--re-builder
+         :history 'swiper-history
+         :caller 'swiper)
+      (when (null ivy-exit)
+        (goto-char swiper--opoint)))))
 
 (defun swiper--ensure-visible ()
   "Remove overlays hiding point."
@@ -436,8 +457,8 @@ BEG and END, when specified, are the point bounds."
                     (overlay-put overlay 'priority i)))
                 (cl-incf i)))))))))
 
-(defun swiper--action (x input)
-  "Goto line X and search for INPUT."
+(defun swiper--action (x)
+  "Goto line X."
   (if (null x)
       (user-error "No candidates")
     (goto-char (point-min))
@@ -446,7 +467,7 @@ BEG and END, when specified, are the point bounds."
                #'forward-line)
              (1- (read (get-text-property 0 'display x))))
     (re-search-forward
-     (ivy--regex input) (line-end-position) t)
+     (ivy--regex ivy-text) (line-end-position) t)
     (swiper--ensure-visible)
     (when (/= (point) swiper--opoint)
       (unless (and transient-mark-mode mark-active)



reply via email to

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