Function: eca-chat-add-context-to-user-prompt

eca-chat-add-context-to-user-prompt is an interactive and natively compiled function defined in eca-chat.el.

Signature

(eca-chat-add-context-to-user-prompt &optional ARG)

Documentation

Add context to user prompt in chat in a DWIM manner.

- If a region selected, add the file or the buffer content in
  that lines range.
- If in Dired, add the marked files/dirs or current file/dir at point.
- If in Treemacs, add selected file/dir.
- Else add current file or the whole buffer content.

With prefix ARG, add the context without selecting the chat window, leaving point where it was.

Key Bindings

This command is not in any keymaps.

Source Code

;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-chat.el
;;;###autoload
(defun eca-chat-add-context-to-user-prompt (&optional arg)
  "Add context to user prompt in chat in a DWIM manner.

- If a region selected, add the file or the buffer content in
  that lines range.
- If in Dired, add the marked files/dirs or current file/dir at point.
- If in Treemacs, add selected file/dir.
- Else add current file or the whole buffer content.

With prefix ARG, add the context without selecting the chat
window, leaving point where it was."
  (interactive "P")
  (eca-assert-session-running (eca-session))
  (let* ((contexts (eca-chat--get-contexts-dwim)))
    (unless contexts
      (user-error "No context for this buffer; select a region to add its content"))
    (eca-chat--with-current-buffer (eca-chat--get-last-buffer (eca-session))
      (seq-doseq (context contexts)
        (eca-chat--insert-prompt (concat (eca-chat--context->str context 'static)
                                         " ")))
      (unless arg
        (eca-chat--select-window)
        (goto-char (line-end-position))))))