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

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

[elpa] master 2404db1 053/167: Add feedback for long-running async proce


From: Oleh Krehel
Subject: [elpa] master 2404db1 053/167: Add feedback for long-running async processes
Date: Tue, 08 Dec 2015 10:49:51 +0000

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

    Add feedback for long-running async processes
    
    * counsel.el (counsel--async-time): New defvar.
    (counsel--async-filter): New defun.
    (counsel--async-command): Use `counsel--async-filter'.
    
    Each time 0.5s pass after the last input, if the external process hasn't
    finished yet, update minibuffer with the amount of candidates collected
    so far. This is useful to see that long running commands like
    `counsel-locate' or `counsel-ag' (when in a very large directory) aren't
    stuck.
---
 counsel.el |   26 +++++++++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/counsel.el b/counsel.el
index 96b7b00..5d5263b 100644
--- a/counsel.el
+++ b/counsel.el
@@ -500,6 +500,10 @@ Skip some dotfiles unless `ivy-text' requires them."
                  candidates))
         (setq ivy--old-re regexp))))
 
+(defvar counsel--async-time nil
+  "Store the time when a new process was started.
+Or the time of the last minibuffer update.")
+
 (defun counsel--async-command (cmd)
   (let* ((counsel--process " *counsel*")
          (proc (get-process counsel--process))
@@ -512,7 +516,9 @@ Skip some dotfiles unless `ivy-text' requires them."
                 counsel--process
                 counsel--process
                 cmd))
-    (set-process-sentinel proc #'counsel--async-sentinel)))
+    (setq counsel--async-time (current-time))
+    (set-process-sentinel proc #'counsel--async-sentinel)
+    (set-process-filter proc #'counsel--async-filter)))
 
 (defun counsel--async-sentinel (process event)
   (if (string= event "finished\n")
@@ -529,6 +535,24 @@ Skip some dotfiles unless `ivy-text' requires them."
           (setq ivy--old-cands ivy--all-candidates)
           (ivy--exhibit)))))
 
+(defun counsel--async-filter (process str)
+  "Receive from PROCESS the output STR.
+Update the minibuffer with the amount of lines collected every
+0.5 seconds since the last update."
+  (with-current-buffer (process-buffer process)
+    (insert str))
+  (let (size)
+    (when (time-less-p
+           ;; 0.5s
+           '(0 0 500000 0)
+           (time-since counsel--async-time))
+      (with-current-buffer (process-buffer process)
+        (goto-char (point-min))
+        (setq size (- (buffer-size) (forward-line (buffer-size)))))
+      (ivy--insert-minibuffer
+       (format "\ncollected: %d" size))
+      (setq counsel--async-time (current-time)))))
+
 (defun counsel-locate-action-extern (x)
   "Use xdg-open shell command on X."
   (call-process shell-file-name nil



reply via email to

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