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

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

[elpa] externals/ellama 6ecde6aa8b 5/7: Add display action functions for


From: ELPA Syncer
Subject: [elpa] externals/ellama 6ecde6aa8b 5/7: Add display action functions for chat and instant modes
Date: Fri, 29 Nov 2024 18:58:09 -0500 (EST)

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

    Add display action functions for chat and instant modes
    
    Added custom options `ellama-chat-display-action-function` and
    `ellama-instant-display-action-function` to control the display
    behavior of chat and instant buffers respectively. Updated relevant
    functions to use these new options when displaying buffers.
---
 README.org |  6 ++++++
 ellama.el  | 40 +++++++++++++++++++++++++++++++---------
 2 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/README.org b/README.org
index ed7f721104..8665b93851 100644
--- a/README.org
+++ b/README.org
@@ -85,6 +85,10 @@ In that case you should customize ellama configuration like 
this:
             :embedding-model "nomic-embed-text"
             :default-chat-non-standard-params
             '(("num_ctx" . 32768))))
+      ;; customize display buffer behaviour
+      ;; see ~(info "(elisp) Buffer Display Action Functions")~
+      (setopt ellama-chat-display-action-function #'display-buffer-full-frame)
+      (setopt ellama-instant-display-action-function 
#'display-buffer-at-bottom)
       :config
       ;; send last message in chat buffer with C-c C-c
       (add-hook 'org-ctrl-c-ctrl-c-hook #'ellama-chat-send-last-message))
@@ -357,6 +361,8 @@ argument generated text string.
   ~ellama-provider~ will be used if not set.
 - ~ellama-show-quotes~: Show quotes content in chat buffer. Disabled
   by default.
+- ~ellama-chat-display-action-function~: Display action function for 
~ellama-chat~.
+- ~ellama-instant-display-action-function~: Display action function for 
~ellama-instant~.
 
 ** Acknowledgments
 
diff --git a/ellama.el b/ellama.el
index 61d6f96d5b..c493c274b9 100644
--- a/ellama.el
+++ b/ellama.el
@@ -386,6 +386,16 @@ Too low value can break generated code by splitting long 
comment lines."
   :group 'ellama
   :type 'boolean)
 
+(defcustom ellama-chat-display-action-function nil
+  "Display action function for `ellama-chat'."
+  :group 'ellama
+  :type 'function)
+
+(defcustom ellama-instant-display-action-function nil
+  "Display action function for `ellama-instant'."
+  :group 'ellama
+  :type 'function)
+
 (define-minor-mode ellama-session-mode
   "Minor mode for ellama session buffers."
   :interactive nil
@@ -803,7 +813,8 @@ If EPHEMERAL non nil new session will not be associated 
with any file."
               buffer ellama--active-sessions)
       (ellama-session-mode +1))
     (kill-buffer session-buffer)
-    (display-buffer buffer)))
+    (display-buffer buffer (when ellama-chat-display-action-function
+                            `((ignore . 
(,ellama-chat-display-action-function)))))))
 
 ;;;###autoload
 (defun ellama-session-remove ()
@@ -842,7 +853,8 @@ If EPHEMERAL non nil new session will not be associated 
with any file."
              (hash-table-keys ellama--active-sessions)))
         (buffer (ellama-get-session-buffer id)))
     (ellama-activate-session id)
-    (display-buffer buffer)))
+    (display-buffer buffer (when ellama-chat-display-action-function
+                            `((ignore . 
(,ellama-chat-display-action-function)))))))
 
 ;;;###autoload
 (defun ellama-session-rename ()
@@ -1478,7 +1490,10 @@ last step only.
                                      (ellama-generate-name provider 
real-this-command prompt)))
                (ellama-get-session-buffer ellama--current-session-id))))
     (when show
-      (display-buffer buf))
+      (display-buffer buf (if chat (when ellama-chat-display-action-function
+                                    `((ignore . 
(,ellama-chat-display-action-function))))
+                           (when ellama-instant-display-action-function
+                             `((ignore . 
(,ellama-instant-display-action-function)))))))
     (with-current-buffer buf
       (funcall ellama-major-mode))
     (if chat
@@ -1556,12 +1571,14 @@ Extract profession from this message. Be short and 
concise."
                         "Provide short final answer based on final 
solution.")))))
 
 (declare-function org-export-to-buffer "ox")
+(defvar org-export-show-temporary-export-buffer)
 
 (defun ellama-convert-org-to-md (text)
   "Translate TEXT from org syntax to markdown syntax."
   (require 'ox)
   (require 'ox-md)
-  (let ((buf (make-temp-name "ellama-")))
+  (let ((buf (make-temp-name "ellama-"))
+       (org-export-show-temporary-export-buffer nil))
     (with-temp-buffer
       (insert "#+OPTIONS: toc:nil\n" text)
       (org-export-to-buffer 'md buf
@@ -1598,7 +1615,8 @@ Will call `ellama-chat-done-callback' and ON-DONE on 
TEXT."
   "Translate generated text into TRANSLATION-BUFFER."
   (lambda (generated)
     (ellama-chat-done generated)
-    (display-buffer translation-buffer)
+    (display-buffer translation-buffer (when 
ellama-chat-display-action-function
+                                        `((ignore . 
(,ellama-chat-display-action-function)))))
     (with-current-buffer translation-buffer
       (save-excursion
        (goto-char (point-max))
@@ -1620,7 +1638,8 @@ Will call `ellama-chat-done-callback' and ON-DONE on 
TEXT."
       (goto-char (point-max))
       (delete-char -2)
       (delete-char (- (length result))))
-    (display-buffer buffer)
+    (display-buffer buffer (when ellama-chat-display-action-function
+                            `((ignore . 
(,ellama-chat-display-action-function)))))
     (with-current-buffer buffer
       (save-excursion
        (goto-char (point-max))
@@ -1635,7 +1654,8 @@ Will call `ellama-chat-done-callback' and ON-DONE on 
TEXT."
 
 (defun ellama--translate-interaction (prompt translation-buffer buffer session)
   "Translate chat PROMPT in TRANSLATION-BUFFER for BUFFER with SESSION."
-  (display-buffer translation-buffer)
+  (display-buffer translation-buffer (when ellama-chat-display-action-function
+                                      `((ignore . 
(,ellama-chat-display-action-function)))))
   (with-current-buffer translation-buffer
     (save-excursion
       (goto-char (point-max))
@@ -1715,7 +1735,8 @@ the full response text when the request completes (with 
BUFFER current)."
                                 (get-buffer-create (ellama-session-id 
session))))))
     (if ellama-chat-translation-enabled
        (ellama--translate-interaction prompt translation-buffer buffer session)
-      (display-buffer buffer)
+      (display-buffer buffer (when ellama-chat-display-action-function
+                              `((ignore . 
(,ellama-chat-display-action-function)))))
       (with-current-buffer buffer
        (save-excursion
          (goto-char (point-max))
@@ -1875,7 +1896,8 @@ ARGS contains keys for fine control.
       (funcall ellama-major-mode)
       (when (derived-mode-p 'org-mode)
        (setq filter 'ellama--translate-markdown-to-org-filter)))
-    (display-buffer buffer)
+    (display-buffer buffer (when ellama-instant-display-action-function
+                            `((ignore . 
(,ellama-instant-display-action-function)))))
     (ellama-stream prompt
                   :buffer buffer
                   :filter filter



reply via email to

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