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

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

[nongnu] elpa/diff-ansi c189b8206c: Support showing progress for progres


From: ELPA Syncer
Subject: [nongnu] elpa/diff-ansi c189b8206c: Support showing progress for progressive ansi conversion
Date: Thu, 7 Jul 2022 19:58:14 -0400 (EDT)

branch: elpa/diff-ansi
commit c189b8206ccff38a4079740330ee07a308470b82
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>

    Support showing progress for progressive ansi conversion
    
    It can be useful when viewing very large diffs to know when conversion
    is complete.
---
 diff-ansi.el | 37 ++++++++++++++++++++++++++++++-------
 readme.rst   |  4 ++++
 2 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/diff-ansi.el b/diff-ansi.el
index 602dc27171..b4fdae75a4 100644
--- a/diff-ansi.el
+++ b/diff-ansi.el
@@ -92,6 +92,12 @@ Used for `progressive' and `multiprocess' methods."
 A nil value detects the number of processes on the system (when supported)."
   :type 'integer)
 
+(defcustom diff-ansi-verbose-progress nil
+  "When enabled, show the progress of progressive conversion in the echo area.
+
+It can be useful to show progress when viewing very large diffs."
+  :type 'boolean)
+
 ;; ---------------------------------------------------------------------------
 ;; Internal Variables
 
@@ -651,8 +657,9 @@ Store the result in TARGET-BUF when non-nil."
   (cancel-timer diff-ansi--ansi-color-timer)
   (setq diff-ansi--ansi-color-timer nil))
 
-(defun diff-ansi-progressive-highlight-impl (buf range timer)
-  "Callback to update colors for BUF in RANGE for TIMER."
+(defun diff-ansi-progressive-highlight-impl (buf beg range timer)
+  "Callback to update colors for BUF in RANGE for TIMER.
+Argument BEG is only used to calculate the progress percentage."
   (unless (input-pending-p)
     (with-current-buffer buf
       (cond
@@ -674,20 +681,36 @@ Store the result in TARGET-BUF when non-nil."
                   (save-excursion
                     (goto-char (min (+ disp-beg diff-ansi-chunks-size) end))
                     (line-end-position)))))
-            ;;
             (save-excursion
               (cond
                 ((eq disp-beg disp-end)
                   (when diff-ansi--ansi-color-timer
-                    (diff-ansi--ansi-color-timer-cancel)))
+                    (diff-ansi--ansi-color-timer-cancel)
+                    (when diff-ansi-verbose-progress
+                      (message nil))))
                 (t
                   (let ((disp-end-mark (set-marker (make-marker) disp-end)))
                     (diff-ansi--ansi-color-apply-on-region-with-bg disp-beg 
disp-end)
 
                     (setq do-redisplay t)
                     ;; Update the display start and actual end.
-                    (setcar range (marker-position disp-end-mark))
-                    (setcdr range (- (buffer-size) end-trailing-chars))))))
+                    (let
+                      (
+                        (disp-beg-next (marker-position disp-end-mark))
+                        (end-next (- (buffer-size) end-trailing-chars)))
+
+                      (setcar range disp-beg-next)
+                      (setcdr range end-next)
+
+                      (when diff-ansi-verbose-progress
+                        (let ((message-log-max nil))
+                          (message
+                            "diff-ansi: %2d%% complete"
+                            (min
+                              (/ (* 100 (- disp-beg-next beg)) (- end-next 
beg))
+                              ;; Never show 100 because there is work left to 
do,
+                              ;; actual completion will hide the message.
+                              99)))))))))
 
             ;; Re-display outside the block that moves the cursor.
             (when do-redisplay
@@ -722,7 +745,7 @@ Store the result in TARGET-BUF when non-nil."
           (timer-set-function
             diff-ansi--ansi-color-timer
             #'diff-ansi-progressive-highlight-impl
-            (list (current-buffer) (cons beg end) 
diff-ansi--ansi-color-timer)))
+            (list (current-buffer) beg (cons beg end) 
diff-ansi--ansi-color-timer)))
         (timer-activate diff-ansi--ansi-color-timer)))))
 
 
diff --git a/readme.rst b/readme.rst
index 73800c46ab..300dc0d165 100644
--- a/readme.rst
+++ b/readme.rst
@@ -82,6 +82,10 @@ but may be extended to adjust default behavior.
    - ``'progressive`` uses a timer (avoids blocking input).
    - ``'multiprocess`` to span multiple external processes for improved 
performance on large diffs.
 
+``diff-ansi-verbose-progress``: nil
+   Display progress for progressive conversion in the echo area for
+   when ``diff-ansi-method`` is set to ``progressive``.
+
 ``diff-ansi-chunks-size``: 8192
    The number of characters to process at a time for
    when ``diff-ansi-method`` is set to ``progressive`` or ``multiprocess``.



reply via email to

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