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

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

[elpa] externals/ellama a9c48d4416 2/7: Ensure user nick is present at t


From: ELPA Syncer
Subject: [elpa] externals/ellama a9c48d4416 2/7: Ensure user nick is present at the end of session buffer
Date: Fri, 29 Nov 2024 18:58:09 -0500 (EST)

branch: externals/ellama
commit a9c48d44164408aa111a277fc69f4d745363ce4b
Author: Sergey Kostyaev <sskostyaev@gmail.com>
Commit: Sergey Kostyaev <sskostyaev@gmail.com>

    Ensure user nick is present at the end of session buffer
    
    Ensured that the user's nick is always present at the end of the session
    buffer. Added checks and insertions to handle cases where the buffer
    might not have the user's nick, especially for new sessions or empty
    buffers. Adjusted the insertion points and conditions to maintain
    consistency across different scenarios.
---
 ellama.el | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/ellama.el b/ellama.el
index a42faa5df8..3c942d0163 100644
--- a/ellama.el
+++ b/ellama.el
@@ -779,6 +779,16 @@ If EPHEMERAL non nil new session will not be associated 
with any file."
        (save-buffer)
        (goto-char (point-min))))
     (with-current-buffer buffer
+      ;; support sessions without user nick at the end of buffer
+      (when (not (save-excursion
+                  (save-match-data
+                    (goto-char (point-max))
+                    (and (search-backward (concat 
(ellama-get-nick-prefix-for-mode) " " ellama-user-nick ":\n") nil t)
+                         (search-forward (concat 
(ellama-get-nick-prefix-for-mode) " " ellama-user-nick ":\n") nil t)
+                         (equal (point) (point-max))))))
+       (goto-char (point-max))
+       (insert (ellama-get-nick-prefix-for-mode) " " ellama-user-nick ":\n")
+       (save-buffer))
       (let ((session (read session-buffer)))
        (setq ellama--current-session
              (make-ellama-session
@@ -1566,7 +1576,7 @@ Extract profession from this message. Be short and 
concise."
 Will call `ellama-chat-done-callback' and ON-DONE on TEXT."
   (save-excursion
     (goto-char (point-max))
-    (insert "\n\n")
+    (insert "\n\n" (ellama-get-nick-prefix-for-mode) " " ellama-user-nick 
":\n")
     (when ellama-session-auto-save
       (save-buffer)))
   (when ellama-chat-done-callback
@@ -1699,9 +1709,12 @@ the full response text when the request completes (with 
BUFFER current)."
       (with-current-buffer buffer
        (save-excursion
          (goto-char (point-max))
-         (insert (ellama-get-nick-prefix-for-mode) " " ellama-user-nick ":\n"
-                 (ellama--format-context session) (ellama--fill-long-lines 
prompt) "\n\n"
-                 (ellama-get-nick-prefix-for-mode) " " ellama-assistant-nick 
":\n")
+         (if (equal (point-min) (point-max)) ;; empty buffer
+             (insert (ellama-get-nick-prefix-for-mode) " " ellama-user-nick 
":\n"
+                     (ellama--format-context session) (ellama--fill-long-lines 
prompt) "\n\n"
+                     (ellama-get-nick-prefix-for-mode) " " 
ellama-assistant-nick ":\n")
+           (insert (ellama--format-context session) (ellama--fill-long-lines 
prompt) "\n\n"
+                   (ellama-get-nick-prefix-for-mode) " " ellama-assistant-nick 
":\n"))
          (ellama-stream prompt
                         :session session
                         :on-done (if donecb (list 'ellama-chat-done donecb)



reply via email to

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