;;; 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: (require 'ellama) (defvar ellama-capture-buffer-name "*Ellama Input*" "Name of the buffer used for Ellama input capture.") (defun ellama-capture () "Create a temporary pop-up buffer for Ellama input." (interactive) (let ((buf (get-buffer-create ellama-capture-buffer-name))) (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) (local-set-key (kbd "C-c f") 'ellama-context-add-file) (local-set-key (kbd "C-c i") 'ellama-context-add-info-node) (setq header-line-format (substitute-command-keys "C-c C-c: send, C-c C-k: abort, C-c f: add file, C-c i: add info node"))) (let ((display-buffer-alist `(((lambda (buffer-name _) (equal buffer-name ,ellama-capture-buffer-name)) (display-buffer-in-side-window) (side . bottom) (slot . 0) (window-height . 0.3))))) (pop-to-buffer buf)) (message "Chat with the bot using this buffer. C-c C-c to send, C-c C-k to cancel."))) (defun ellama-capture-finalize () "Send the content of the Ellama input buffer to Ellama and close the window." (interactive) (let ((content (buffer-string))) (quit-window t) (ellama-chat content))) (defun ellama-capture-abort () "Kill the Ellama input buffer without sending its content." (interactive) (quit-window t) (message "Ellama input aborted")) (global-set-key (kbd "C-x A SPC") #'ellama-capture) (provide 'module-ellama-capture) ;;; module-ellama-capture.el ends here.