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

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

[elpa] master 9f6141f 345/399: counsel.el (counsel--browse-history): All


From: Oleh Krehel
Subject: [elpa] master 9f6141f 345/399: counsel.el (counsel--browse-history): Allow to remove elements with "C-k"
Date: Sat, 20 Jul 2019 14:57:54 -0400 (EDT)

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

    counsel.el (counsel--browse-history): Allow to remove elements with "C-k"
    
    * ivy.el (ivy-history-contents):
    (ivy-reverse-i-search-kill): Extend to rings.
    
    * counsel.el (counsel--browse-history): Set :keymap and use
      `ivy-history-contents'.
---
 counsel.el | 15 ++++++---------
 ivy.el     | 34 ++++++++++++++++++++++------------
 2 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/counsel.el b/counsel.el
index 3e6f795..368f8c4 100644
--- a/counsel.el
+++ b/counsel.el
@@ -4181,17 +4181,14 @@ An extra action allows to switch to the process buffer."
               :caller 'counsel-minibuffer-history)))
 
 ;;** `counsel-esh-history'
-(defun counsel--browse-history (elements)
-  "Use Ivy to navigate through ELEMENTS."
+(defun counsel--browse-history (ring)
+  "Use Ivy to navigate through RING."
   (setq ivy-completion-beg (point))
   (setq ivy-completion-end (point))
-  (let ((cands
-         (delete-dups
-          (when (> (ring-size elements) 0)
-            (ring-elements elements)))))
-    (ivy-read "Symbol name: " cands
-              :action #'ivy-completion-in-region-action
-              :caller 'counsel-shell-history)))
+  (ivy-read "Symbol name: " (ivy-history-contents ring)
+            :keymap ivy-reverse-i-search-map
+            :action #'ivy-completion-in-region-action
+            :caller 'counsel-shell-history))
 
 (defvar eshell-history-ring)
 
diff --git a/ivy.el b/ivy.el
index cec9da2..0bc863b 100644
--- a/ivy.el
+++ b/ivy.el
@@ -42,6 +42,7 @@
 (require 'ffap)
 (require 'ivy-overlay)
 (require 'colir)
+(require 'ring)
 
 ;;* Customization
 (defgroup ivy nil
@@ -4333,11 +4334,14 @@ This list can be rotated with 
`ivy-rotate-preferred-builders'."
   (interactive)
   (if (not (eolp))
       (ivy-kill-line)
-    (set
-     ivy--reverse-i-search-symbol
-     (delete
-      (ivy-state-current ivy-last)
-      (symbol-value ivy--reverse-i-search-symbol)))
+    (let ((current (ivy-state-current ivy-last)))
+      (if (symbolp ivy--reverse-i-search-symbol)
+          (set
+           ivy--reverse-i-search-symbol
+           (delete current (symbol-value ivy--reverse-i-search-symbol)))
+      (ring-remove
+       ivy--reverse-i-search-symbol
+       (ring-member ivy--reverse-i-search-symbol (ivy-state-current 
ivy-last)))))
     (ivy--kill-current-candidate)))
 
 (defvar ivy-reverse-i-search-map
@@ -4345,14 +4349,20 @@ This list can be rotated with 
`ivy-rotate-preferred-builders'."
     (define-key map (kbd "C-k") 'ivy-reverse-i-search-kill)
     map))
 
-(defun ivy-history-contents (history-variable)
-  "Copy contents of HISTORY-VARIABLE.
+(defun ivy-history-contents (sym-or-ring)
+  "Copy contents of SYM-OR-RING.
 A copy is necessary so that we don't clobber any string attributes.
-Also set `ivy--reverse-i-search-symbol' to HISTORY-VARIABLE."
-  (delete-dups
-   (copy-sequence
-    (symbol-value
-     (setq ivy--reverse-i-search-symbol history-variable)))))
+Also set `ivy--reverse-i-search-symbol' to SYM-OR-RING."
+  (setq ivy--reverse-i-search-symbol sym-or-ring)
+  (cond ((symbolp sym-or-ring)
+         (delete-dups
+          (copy-sequence (symbol-value sym-or-ring))))
+        ((ring-p sym-or-ring)
+         (delete-dups
+          (when (> (ring-size sym-or-ring) 0)
+            (ring-elements sym-or-ring))))
+        (t
+         (error "Expected a symbol or a ring: %S" sym-or-ring))))
 
 (defun ivy-reverse-i-search ()
   "Enter a recursive `ivy-read' session using the current history.



reply via email to

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