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

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

[elpa] master f164cfe 33/54: counsel.el (counsel-yank-pop): New command


From: Oleh Krehel
Subject: [elpa] master f164cfe 33/54: counsel.el (counsel-yank-pop): New command
Date: Tue, 29 Sep 2015 14:09:58 +0000

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

    counsel.el (counsel-yank-pop): New command
    
    * counsel.el (counsel-yank-pop-truncate): New defcustom. Choose whether
      to truncate strings over 4 lines.
    (counsel-yank-pop-action): New defun.
    
    Fixes #218
---
 counsel.el |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/counsel.el b/counsel.el
index 7d2745a..fa1475d 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1034,6 +1034,52 @@ INITIAL-INPUT can be given as the initial minibuffer 
input."
                           (unless (string-match "pdf$" x)
                             (swiper ivy-text)))))))
 
+(defcustom counsel-yank-pop-truncate nil
+  "When non-nil, truncate the display of long strings.")
+
+(defun counsel-yank-pop ()
+  "Ivy replacement for `yank-pop'."
+  (interactive)
+  (if (eq last-command 'yank)
+      (progn
+        (setq counsel-completion-end (point))
+        (setq counsel-completion-beg
+              (save-excursion
+                (search-backward (car kill-ring))
+                (point))))
+    (setq counsel-completion-beg (point))
+    (setq counsel-completion-end (point)))
+  (let ((candidates (cl-remove-if
+                     (lambda (s)
+                       (or (< (length s) 3)
+                           (string-match "\\`[\n[:blank:]]+\\'" s)))
+                     (delete-dups kill-ring))))
+    (when counsel-yank-pop-truncate
+      (setq candidates
+            (mapcar (lambda (s)
+                      (if (string-match "\\`\\(.*\n.*\n.*\n.*\\)\n" s)
+                          (progn
+                            (let ((s (copy-sequence s)))
+                              (put-text-property
+                               (match-end 1)
+                               (length s)
+                               'display
+                               " [...]"
+                               s)
+                              s))
+                        s))
+                    candidates)))
+    (ivy-read "kill-ring: " candidates
+              :action 'counsel-yank-pop-action)))
+
+(defun counsel-yank-pop-action (s)
+  "Insert S into the buffer, overwriting the previous yank."
+  (with-ivy-window
+    (delete-region counsel-completion-beg
+                   counsel-completion-end)
+    (insert (substring-no-properties s))
+    (setq counsel-completion-end (point))))
+
 (provide 'counsel)
 
 ;;; counsel.el ends here



reply via email to

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