branch: externals/ivy
commit 790042e81e338f7b4848e5af5cda47ee31bae022
Author: Basil L. Contovounesios <ba...@contovou.net>
Commit: Basil L. Contovounesios <ba...@contovou.net>

    Fix kill-ring-save for swiper-isearch
    
    The default M-w binding of ivy-kill-ring-save expects ivy--old-cands
    to be a list of strings, but swiper-isearch has long switched to a
    list of buffer positions instead.
    
    * ivy.el (ivy-kill-ring-save): Prefer use-region-p over
    region-active-p.  Use string-join.  Tweak docstring.
    * swiper.el: Set swiper and swiper-isearch actions closer to their
    corresponding commands.
    (swiper--isearch-kill-ring-save): New command modeled after
    ivy-kill-ring-save.
    (swiper-isearch-map): Remap ivy-kill-ring-save and kill-ring-save to
    it.  By default, the former remap is defensive, and only the latter
    is needed.
    
    Fixes #3000.
---
 ivy.el    | 12 ++++--------
 swiper.el | 25 +++++++++++++++++++++----
 2 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/ivy.el b/ivy.el
index 26a31d2927..5a221bc395 100644
--- a/ivy.el
+++ b/ivy.el
@@ -4912,16 +4912,12 @@ The \"pulse\" duration is determined by 
`ivy-pulse-delay'."
     (setq ivy--pulse-overlay nil)))
 
 (defun ivy-kill-ring-save ()
-  "Store the current candidates into the kill ring.
+  "Save the current candidates in the kill ring.
 If the region is active, forward to `kill-ring-save' instead."
   (interactive)
-  (if (region-active-p)
-      (call-interactively 'kill-ring-save)
-    (kill-new
-     (mapconcat
-      #'identity
-      ivy--old-cands
-      "\n"))))
+  (if (use-region-p)
+      (call-interactively #'kill-ring-save)
+    (kill-new (string-join ivy--old-cands "\n"))))
 
 (defun ivy-insert-current ()
   "Make the current candidate into current input.
diff --git a/swiper.el b/swiper.el
index bbe05a992d..359e463932 100644
--- a/swiper.el
+++ b/swiper.el
@@ -858,6 +858,9 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
   :unwind-fn #'swiper--cleanup
   :index-fn #'ivy-recompute-index-swiper)
 
+(ivy-add-actions 'swiper
+                 `(("w" ,#'swiper-action-copy "copy")))
+
 (defun swiper-toggle-face-matching ()
   "Toggle matching only the candidates with `swiper-invocation-face'."
   (interactive)
@@ -1567,10 +1570,6 @@ completion."
     ;; In case of unexpected error.
     (goto-char swiper--opoint)))
 
-(ivy-add-actions 'swiper-isearch '(("w" swiper-isearch-action-copy "copy")))
-(ivy-add-actions 'swiper-isearch '(("i" swiper-isearch-action-insert 
"insert")))
-(ivy-add-actions 'swiper '(("w" swiper-action-copy "copy")))
-
 (defun swiper--isearch-insert-current ()
   "Replace minibuffer contents with the current candidate.
 Like `ivy-insert-current', but tailored for `swiper-isearch'."
@@ -1579,6 +1578,16 @@ Like `ivy-insert-current', but tailored for 
`swiper-isearch'."
   (let ((cur (ivy-state-current ivy-last)))
     (insert (with-ivy-window (swiper--isearch-candidate-string cur)))))
 
+(defun swiper--isearch-kill-ring-save ()
+  "Save the current candidates in the kill ring.
+If the region is active, forward to `kill-ring-save' instead.
+Like `ivy-kill-ring-save', but tailored for `swiper-isearch'."
+  (interactive)
+  (if (use-region-p)
+      (call-interactively #'kill-ring-save)
+    (kill-new (with-ivy-window
+                (mapconcat #'swiper--line-at-point ivy--old-cands "\n")))))
+
 (defun swiper-isearch-thing-at-point ()
   "Insert `symbol-at-point' into the minibuffer of `swiper-isearch'.
 When not running `swiper-isearch' already, start it."
@@ -1621,6 +1630,10 @@ When the input is empty, browse the search history 
instead."
     (set-keymap-parent map swiper-map)
     (define-key map `[remap ,#'ivy-insert-current]
                 #'swiper--isearch-insert-current)
+    (define-key map `[remap ,#'ivy-kill-ring-save]
+                #'swiper--isearch-kill-ring-save)
+    (define-key map `[remap ,#'kill-ring-save]
+                #'swiper--isearch-kill-ring-save)
     (define-key map (kbd "M-n") #'swiper-isearch-thing-at-point)
     (define-key map (kbd "C-r") #'swiper-isearch-C-r)
     map)
@@ -1769,6 +1782,10 @@ When the input is empty, browse the search history 
instead."
   :unwind-fn #'swiper--isearch-unwind
   :format-fn #'swiper-isearch-format-function)
 
+(ivy-add-actions 'swiper-isearch
+                 `(("w" ,#'swiper-isearch-action-copy "copy")
+                   ("i" ,#'swiper-isearch-action-insert "insert")))
+
 ;;;###autoload
 (defun swiper-isearch-backward (&optional initial-input)
   "Like `swiper-isearch' but the first result is before the point."

Reply via email to