]> code.delx.au - gnu-emacs-elpa/commitdiff
Make counsel-locate use a process
authorOleh Krehel <ohwoeowho@gmail.com>
Tue, 30 Jun 2015 07:15:47 +0000 (09:15 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Tue, 30 Jun 2015 07:17:17 +0000 (09:17 +0200)
* counsel.el (counsel-locate-function): Update.
(counsel--async-command): New defun.
(counsel--async-sentinel): New defun.
(counsel-locate): Switch to :action, thus allowing "C-M-n" and `ivy-resume'.

* swiper.el: Bump version.

counsel.el
swiper.el

index acc4ca5bdc1d403ab3fd3cb9d79f514432a9cba9..94c8608eee308daa3b2e87bb1a7e53f1c7815607 100644 (file)
@@ -401,16 +401,43 @@ Skip some dotfiles unless `ivy-text' requires them."
   (if (< (length str) 3)
       (list ""
             (format "%d chars more" (- 3 (length ivy-text))))
-    (split-string
-     (shell-command-to-string (concat "locate -i -l 20 --regex " (ivy--regex str))) "\n" t)))
+    (counsel--async-command
+     (concat "locate -i --regex " (ivy--regex str)))))
+
+(defun counsel--async-command (cmd)
+  (let* ((counsel--process " *counsel*")
+         (proc (get-process counsel--process))
+         (buff (get-buffer counsel--process)))
+    (when proc
+      (delete-process proc))
+    (when buff
+      (kill-buffer buff))
+    (setq proc (start-process-shell-command
+                counsel--process
+                counsel--process
+                cmd))
+    (set-process-sentinel proc #'counsel--async-sentinel)))
+
+(defun counsel--async-sentinel (process event)
+  (if (string= event "finished\n")
+      (progn
+        (with-current-buffer (process-buffer process)
+          (setq ivy--all-candidates (split-string (buffer-string) "\n" t))
+          (setq ivy--old-cands ivy--all-candidates))
+        (ivy--insert-minibuffer
+         (ivy--format ivy--all-candidates)))
+    (if (string= event "exited abnormally with code 1\n")
+        (message "Error"))))
 
 ;;;###autoload
 (defun counsel-locate ()
   "Call locate."
   (interactive)
-  (let ((val (ivy-read "pattern: " 'counsel-locate-function)))
-    (when val
-      (find-file val))))
+  (ivy-read "pattern: " nil
+            :dynamic-collection #'counsel-locate-function
+            :action (lambda (val)
+                      (when val
+                        (find-file val)))))
 
 (defun counsel--generic (completion-fn)
   "Complete thing at point with COMPLETION-FN."
index 9ce5864816a68f67d83b4686cfc117101ff29778..1975ae2d0aad873887fb64057d8df873d9c6f800 100644 (file)
--- a/swiper.el
+++ b/swiper.el
@@ -4,7 +4,7 @@
 
 ;; Author: Oleh Krehel <ohwoeowho@gmail.com>
 ;; URL: https://github.com/abo-abo/swiper
-;; Version: 0.4.1
+;; Version: 0.5.1
 ;; Package-Requires: ((emacs "24.1"))
 ;; Keywords: matching