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

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

[elpa] externals/llm 6955d8a4d6 1/2: Make streaming not repeatedly inser


From: ELPA Syncer
Subject: [elpa] externals/llm 6955d8a4d6 1/2: Make streaming not repeatedly insert the same thing (#72)
Date: Wed, 28 Aug 2024 21:58:28 -0400 (EDT)

branch: externals/llm
commit 6955d8a4d6d091915830ff7c309495f9ac9ee15d
Author: Paul Nelson <63298781+ultronozm@users.noreply.github.com>
Commit: GitHub <noreply@github.com>

    Make streaming not repeatedly insert the same thing (#72)
    
    * llm.el (llm-chat-streaming-to-point): Ignore common prefix between
    streamed text and buffer contents.
    * llm.el (llm-chat-streaming-to-point): Add comments, fill.
---
 llm.el | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/llm.el b/llm.el
index 5f5c1a3799..15421dc46a 100644
--- a/llm.el
+++ b/llm.el
@@ -427,8 +427,18 @@ be passed to `llm-cancel-request'."
                     (with-current-buffer (marker-buffer start)
                       (save-excursion
                         (goto-char start)
-                        (delete-region start end)
-                        (insert text)))))
+                        (let* ((current-text
+                                (buffer-substring-no-properties start end))
+                               (common-prefix
+                                (fill-common-string-prefix current-text text))
+                               (prefix-length (length common-prefix)))
+                          ;; Skip over common prefix of current text
+                          ;; and new text.
+                          (when (> prefix-length 0)
+                            (goto-char (+ start prefix-length)))
+                          (delete-region (point) end)
+                          ;; Insert new text, minus common prefix.
+                          (insert (substring text prefix-length)))))))
           (llm-chat-streaming provider prompt
                               (lambda (text) (insert-text text))
                               (lambda (text) (insert-text text)



reply via email to

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