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

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

[nongnu] elpa/eldoc-diffstat 1a75ccb1ec 02/10: Use cached result if call


From: ELPA Syncer
Subject: [nongnu] elpa/eldoc-diffstat 1a75ccb1ec 02/10: Use cached result if called with same commit
Date: Fri, 13 Dec 2024 16:01:49 -0500 (EST)

branch: elpa/eldoc-diffstat
commit 1a75ccb1ec7e79ac368abd3e55de93c10a4ff8f2
Author: Johann Klähn <johann@jklaehn.de>
Commit: Johann Klähn <johann@jklaehn.de>

    Use cached result if called with same commit
    
    This is useful in, e.g., `vc-annotate-mode`, where consecutive lines often 
have
    the same commit.
---
 eldoc-diffstat.el | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/eldoc-diffstat.el b/eldoc-diffstat.el
index e4d372622e..dc2efdca42 100644
--- a/eldoc-diffstat.el
+++ b/eldoc-diffstat.el
@@ -52,7 +52,11 @@ Intended for `eldoc-documentation-functions'."
                                (boundp 'log-view-vc-backend)
                                (eq log-view-vc-backend 'Git)
                                (log-view-current-tag)))))
-    (eldoc-diffstat--docstring-1 commit callback)))
+    (if-let* (((processp eldoc-diffstat--process))
+              (result (process-get eldoc-diffstat--process :result))
+              ((equal commit (car result))))
+        (funcall callback (cdr result))
+      (eldoc-diffstat--docstring-1 commit callback))))
 
 (defun eldoc-diffstat--docstring-1 (commit callback &rest _ignored)
   "Display diffstat for COMMIT by calling CALLBACK."
@@ -73,6 +77,7 @@ Intended for `eldoc-documentation-functions'."
     (append eldoc-diffstat--command (list commit))
     :sentinel
     (apply-partially #'eldoc-diffstat--sentinel callback)))
+  (process-put eldoc-diffstat--process :commit commit)
 
   ;; Signal that the doc string is computed asynchronously.
   t)
@@ -100,7 +105,10 @@ Intended for `eldoc-documentation-functions'."
                          'face 'italic)
       (forward-line)
       (reverse-region (point) (point-max))
-      (funcall callback (buffer-string)))))
+      (let ((result (buffer-string))
+            (commit (process-get eldoc-diffstat--process :commit)))
+        (process-put eldoc-diffstat--process :result (cons commit result))
+        (funcall callback result)))))
 
 (provide 'eldoc-diffstat)
 ;;; eldoc-diffstat.el ends here



reply via email to

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