[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ellama 99c8075040 4/5: Merge pull request #30 from Steb
From: |
ELPA Syncer |
Subject: |
[elpa] externals/ellama 99c8075040 4/5: Merge pull request #30 from Stebalien/steb/simplify |
Date: |
Sat, 23 Dec 2023 12:58:05 -0500 (EST) |
branch: externals/ellama
commit 99c80750403d03d2068e3a3bcc100e3665d4398e
Merge: cb0fbac035 8131113c4c
Author: Sergey Kostyaev <s-kostyaev@users.noreply.github.com>
Commit: GitHub <noreply@github.com>
Merge pull request #30 from Stebalien/steb/simplify
Simplify ellama-stream
---
ellama.el | 88 +++++++++++++++++++++++++++++----------------------------------
1 file changed, 41 insertions(+), 47 deletions(-)
diff --git a/ellama.el b/ellama.el
index 1ddd841233..18fa043103 100644
--- a/ellama.el
+++ b/ellama.el
@@ -206,53 +206,47 @@ when the request completes (with BUFFER current)."
(llm-chat-prompt-append-response
ellama--chat-prompt prompt)
(setq ellama--chat-prompt (llm-make-simple-chat-prompt prompt)))
- (unwind-protect
- (save-excursion
- (let* ((start (make-marker))
- (end (make-marker))
- (window (selected-window))
- (insert-text
- (lambda (text)
- ;; Erase and insert the new text between the marker cons.
- (with-current-buffer (marker-buffer start)
- (let ((pt (point)))
- (save-excursion
- (goto-char start)
- (delete-region start end)
- (insert (funcall filter text))
- (fill-region start (point)))
- (goto-char pt))
- (when ellama-auto-scroll
- (select-window (get-window-with-predicate
- (lambda (_)
- (eq (current-buffer)
- (get-buffer buffer))))
- t)
- (goto-char (point-max))
- (recenter -1)
- (select-window window))))))
- (setq ellama--change-group (prepare-change-group))
- (activate-change-group ellama--change-group)
- (set-marker start point)
- (set-marker end point)
- (set-marker-insertion-type start nil)
- (set-marker-insertion-type end t)
- (spinner-start ellama-spinner-type)
- (llm-chat-streaming ellama-provider
- ellama--chat-prompt
- insert-text
- (lambda (text)
- (funcall insert-text text)
- (with-current-buffer buffer
- (undo-amalgamate-change-group
ellama--change-group)
- (accept-change-group ellama--change-group)
- (spinner-stop)
- (funcall donecb text)))
- (lambda (_ msg)
- (with-current-buffer buffer
- (cancel-change-group ellama--change-group)
- (spinner-stop)
- (funcall errcb msg))))))))))
+ (let* ((start (make-marker))
+ (end (make-marker))
+ (insert-text
+ (lambda (text)
+ ;; Erase and insert the new text between the marker cons.
+ (with-current-buffer buffer
+ ;; Manually save/restore point as save-excursion doesn't
restore the point into
+ ;; the middle of replaced text.
+ (let ((pt (point)))
+ (goto-char start)
+ (delete-region start end)
+ (insert (funcall filter text))
+ (fill-region start (point))
+ (goto-char pt))
+ (when-let ((ellama-auto-scroll)
+ (window (get-buffer-window buffer)))
+ (with-selected-window window
+ (goto-char (point-max))
+ (recenter -1)))))))
+ (setq ellama--change-group (prepare-change-group))
+ (activate-change-group ellama--change-group)
+ (set-marker start point)
+ (set-marker end point)
+ (set-marker-insertion-type start nil)
+ (set-marker-insertion-type end t)
+ (spinner-start ellama-spinner-type)
+ (llm-chat-streaming ellama-provider
+ ellama--chat-prompt
+ insert-text
+ (lambda (text)
+ (funcall insert-text text)
+ (with-current-buffer buffer
+ (undo-amalgamate-change-group
ellama--change-group)
+ (accept-change-group ellama--change-group)
+ (spinner-stop)
+ (funcall donecb text)))
+ (lambda (_ msg)
+ (with-current-buffer buffer
+ (cancel-change-group ellama--change-group)
+ (spinner-stop)
+ (funcall errcb msg))))))))
;;;###autoload
(defun ellama-chat (prompt)