branch: externals/ellama
commit 7c49cba7fd959c80c6b2997140b14ba2381c4740
Author: Sergey Kostyaev <[email protected]>
Commit: Sergey Kostyaev <[email protected]>
Improve text insertion handling
Added `use-hard-newlines` variable and updated text insertion to use hard
newlines. Ensured that text is inserted only if there is a delta, and
improved
the conditional logic for filling paragraphs.
---
ellama.el | 41 +++++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 20 deletions(-)
diff --git a/ellama.el b/ellama.el
index 722c33789b..b93f52d2a8 100644
--- a/ellama.el
+++ b/ellama.el
@@ -1235,6 +1235,7 @@ FILTER is a function for text transformation."
(goto-char end-marker)
(let* ((filtered-text
(funcall filter text))
+ (use-hard-newlines t)
(common-prefix (concat
safe-common-prefix
(ellama-max-common-prefix
@@ -1248,26 +1249,26 @@ FILTER is a function for text transformation."
(length common-prefix)))
(delta (string-remove-prefix common-prefix filtered-text)))
(delete-char (- wrong-chars-cnt))
- (insert delta)
- (when (and
- ellama-fill-paragraphs
- (pcase ellama-fill-paragraphs
- ((cl-type function) (funcall ellama-fill-paragraphs))
- ((cl-type boolean) ellama-fill-paragraphs)
- ((cl-type list) (and (apply #'derived-mode-p
- ellama-fill-paragraphs)))))
- (if (not (eq major-mode 'org-mode))
- (fill-paragraph)
- (when (not (save-excursion
- (re-search-backward
- "#\\+BEGIN_SRC"
- beg-marker t)))
- (org-fill-paragraph))))
- (set-marker end-marker (point))
- (when (and ellama-auto-scroll (not ellama--stop-scroll))
- (ellama--scroll buffer end-marker))
- (setq safe-common-prefix (ellama--string-without-last-line
common-prefix))
- (setq previous-filtered-text filtered-text))))))))
+ (when delta (insert (propertize delta 'hard t))
+ (when (and
+ ellama-fill-paragraphs
+ (pcase ellama-fill-paragraphs
+ ((cl-type function) (funcall
ellama-fill-paragraphs))
+ ((cl-type boolean) ellama-fill-paragraphs)
+ ((cl-type list) (and (apply #'derived-mode-p
+
ellama-fill-paragraphs)))))
+ (if (not (eq major-mode 'org-mode))
+ (fill-paragraph)
+ (when (not (save-excursion
+ (re-search-backward
+ "#\\+BEGIN_SRC"
+ beg-marker t)))
+ (org-fill-paragraph))))
+ (set-marker end-marker (point))
+ (when (and ellama-auto-scroll (not ellama--stop-scroll))
+ (ellama--scroll buffer end-marker))
+ (setq safe-common-prefix (ellama--string-without-last-line
common-prefix))
+ (setq previous-filtered-text filtered-text)))))))))
(defun ellama--handle-partial (insert-text insert-reasoning reasoning-buffer)
"Handle partial llm callback.