From 8493f5c880acced4c2c512493565ccb98f50c99f Mon Sep 17 00:00:00 2001 From: Levi Neely <141506390+lneely@users.noreply.github.com> Date: Tue, 17 Sep 2024 20:16:27 +0200 Subject: [PATCH] pop-up buffer for ellama chat. much better. --- emacs/module/module-ellama-capture.el | 38 +++++++++++++++++++++++++++ emacs/module/module-llm.el | 14 ++++++++++ 2 files changed, 52 insertions(+) create mode 100644 emacs/module/module-ellama-capture.el diff --git a/emacs/module/module-ellama-capture.el b/emacs/module/module-ellama-capture.el new file mode 100644 index 0000000..bf776b1 --- /dev/null +++ b/emacs/module/module-ellama-capture.el @@ -0,0 +1,38 @@ +;;; module-ellama-capture.el -- improve ellama chat interaction +;;; +;;; Commentary: +;;; +;;; This module provides an org-capture-like functionality for +;;; interacting with Ellama. It allows users to pop up a temporary +;;; buffer for inputting and submitting text, which can then be fed +;;; into Ellama's underlying functions. + +;;; Code: + +(defun ellama-capture () + "Create a temporary pop-up buffer for Ellama input." + (interactive) + (let ((buf (get-buffer-create "*Ellama Input*"))) + (with-current-buffer buf + (erase-buffer) + (text-mode) + (use-local-map (copy-keymap text-mode-map)) + (local-set-key (kbd "C-c C-c") 'ellama-capture-finalize) + (local-set-key (kbd "C-c C-k") 'ellama-capture-abort)) + (pop-to-buffer buf) + (message "Type your message, then C-c C-c to send or C-c C-k to abort"))) + +(defun ellama-capture-finalize () + "Send the content of the Ellama input buffer to Ellama and kill the buffer." + (interactive) + (let ((content (buffer-string))) + (kill-buffer (current-buffer)) + (ellama-chat content))) + +(defun ellama-capture-abort () + "Kill the Ellama input buffer without sending its content." + (interactive) + (kill-buffer (current-buffer)) + (message "Ellama input aborted")) + +;;; module-ellama-capture.el ends here. diff --git a/emacs/module/module-llm.el b/emacs/module/module-llm.el index bf70dde..e0b2e9e 100644 --- a/emacs/module/module-llm.el +++ b/emacs/module/module-llm.el @@ -25,6 +25,18 @@ (with-eval-after-load 'ellama (ellama-setup-keymap)) +(defun ellama-context-add-marked-files () + "Add all marked files in Dired to Ellama context." + (interactive) + (let ((marked-files (dired-get-marked-files))) + (if (null marked-files) + (message "No files marked") + (dolist (file marked-files) + (ignore-errors (ellama-context-add-file file))) + (message "Added %d file(s) to Ellama context" (length marked-files))))) + +(with-eval-after-load 'dired + (define-key dired-mode-map (kbd "C-c e") #'ellama-context-add-marked-files)) ;;(pkg/require 'org-ai) (straight-use-package @@ -33,6 +45,8 @@ (require 'org-ai) (add-hook 'org-mode-hook #'org-ai-mode) +(require 'module-ellama-capture) + (provide 'module-llm) ;;; module-llm.el ends here.