syscfg/emacs/module/module-ellama-capture.el

50 lines
1.7 KiB
EmacsLisp

;;; 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)
(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)
(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
"(ellama-capture) C-c C-c: send, C-c C-k: abort, C-c f: add file, C-c i: add info node")))
(pop-to-buffer buf)
(message "Type your message, then use the commands shown in the header line")))
(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"))
(global-set-key (kbd "C-x A e SPC") #'ellama-capture)
(provide 'module-ellama-capture)
;;; module-ellama-capture.el ends here.