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

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

[elpa] master 91caee8 2/5: Add a dynamic counsel-locate


From: Oleh Krehel
Subject: [elpa] master 91caee8 2/5: Add a dynamic counsel-locate
Date: Mon, 20 Apr 2015 17:32:59 +0000

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

    Add a dynamic counsel-locate
    
    * counsel.el (counsel-locate-function): New defun.
    (counsel-locate): New defun.
    
    * ivy.el (ivy--dynamic-function): New defvar.
    (ivy--exhibit): Re-compute candidates use `ivy--dynamic-function' if
    it's non-nil.
---
 counsel.el |   18 ++++++++++++++++++
 ivy.el     |   11 +++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/counsel.el b/counsel.el
index 1b5e260..85ab584 100644
--- a/counsel.el
+++ b/counsel.el
@@ -201,6 +201,24 @@
       (goto-char (point-min))
       (forward-line (1- (string-to-number (cadr lst)))))))
 
+(defun counsel-locate-function (str &rest _u)
+  (if (string= str "")
+      '("no" "matches")
+    (setq ivy--all-candidates
+          (split-string
+           (shell-command-to-string (concat "locate -l 20 " str)) "\n" t))
+    (setq ivy--old-re nil)
+    (setq ivy--old-cands nil)
+    (ivy--exhibit)))
+
+(defun counsel-locate ()
+  "Call locate."
+  (interactive)
+  (let* ((ivy--dynamic-function 'counsel-locate-function)
+         (val (ivy-read "pattern: " 'counsel-locate-function)))
+    (when val
+      (find-file val))))
+
 (defun counsel--generic (completion-fn)
   "Complete thing at point with COMPLETION-FN."
   (let* ((bnd (bounds-of-thing-at-point 'symbol))
diff --git a/ivy.el b/ivy.el
index 315b9d9..8e38ac3 100644
--- a/ivy.el
+++ b/ivy.el
@@ -542,11 +542,22 @@ Turning on Ivy mode will set `completing-read-function' to
       ;; get out of the prompt area
       (constrain-to-field nil (point-max)))))
 
+(defvar ivy--dynamic-function nil
+  "When this is non-nil, call it for each input change to get new candidates.")
+
 (defun ivy--exhibit ()
   "Insert Ivy completions display.
 Should be run via minibuffer `post-command-hook'."
   (setq ivy-text (ivy--input))
   (ivy--cleanup)
+  (when (and ivy--dynamic-function
+             (not (equal (ivy--regex ivy-text)
+                         ivy--old-re)))
+    (setq ivy--old-re nil)
+    (setq ivy--old-cands nil)
+    (let ((store ivy--dynamic-function)
+          (ivy--dynamic-function nil))
+      (setq ivy--all-candidates (funcall store ivy-text))))
   (when ivy--directory
     (if (string-match "/$" ivy-text)
         (if (member ivy-text ivy--all-candidates)



reply via email to

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