Function: eca-chat--get-contexts-dwim

eca-chat--get-contexts-dwim is a natively compiled function defined in eca-chat-context.el.

Signature

(eca-chat--get-contexts-dwim)

Documentation

Get contexts in a DWIM manner.

Source Code

;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-chat-context.el
(defun eca-chat--get-contexts-dwim ()
  "Get contexts in a DWIM manner."
  (cond
   ((and (buffer-file-name)
         (use-region-p))
    (list
     (list :type "file"
           :path (buffer-file-name)
           :linesRange (eca-chat--region-lines-range))))

   ((derived-mode-p 'dired-mode)
    (--map (list :type (if (f-dir? it) "directory" "file")
                 :path it)
           (dired-get-marked-files)))

   ((derived-mode-p 'treemacs-mode)
    (when-let (path (-some-> (treemacs-node-at-point)
                      (treemacs-button-get :path)))
      (list
       (list :type (if (f-dir? path) "directory" "file")
             :path path))))

   ((buffer-file-name)
    (list
     (list :type "file" :path (buffer-file-name))))

   ;; Explicit selection in a non-file buffer (magit, vterm, the
   ;; chat itself, ...): intentional, so no predicate check.
   ((use-region-p)
    (list (eca-chat--buffer-context (current-buffer)
                                    (eca-chat--region-lines-range))))

   ((funcall eca-chat-context-buffer-predicate (current-buffer))
    (list (eca-chat--buffer-context (current-buffer))))))