branch: externals/ellama
commit 87d7b067c549d0f835ccc29b9109f1e0e50f4a1d
Author: Sergey Kostyaev <[email protected]>
Commit: Sergey Kostyaev <[email protected]>
Improve text processing in `ellama.el`
Added markers for beginning and end of the text range to handle text
transformation more accurately. Updated paragraph filling logic to avoid
unwanted behavior in `org-mode` by checking if the current position is
within a
code block before filling paragraphs.
Fix #271
---
ellama.el | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/ellama.el b/ellama.el
index c850f1a212..a4ab6b6def 100644
--- a/ellama.el
+++ b/ellama.el
@@ -1283,11 +1283,14 @@ If POINT is nil, current point will be used.
FILTER is a function for text transformation."
(with-current-buffer
buffer
- (let* ((end-marker (make-marker))
+ (let* ((beg-marker (make-marker))
+ (end-marker (make-marker))
(previous-filtered-text "")
(safe-common-prefix ""))
(set-marker end-marker (or point (point)))
+ (set-marker beg-marker end-marker)
(set-marker-insertion-type end-marker t)
+ (set-marker-insertion-type beg-marker nil)
(lambda
(text)
(with-current-buffer buffer
@@ -1310,14 +1313,19 @@ FILTER is a function for text transformation."
(delete-char (- wrong-chars-cnt))
(insert delta)
(when (and
- (not (eq major-mode 'org-mode))
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)))))
- (fill-paragraph))
+ (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))