Function: eca-chat--buffer-context-content

eca-chat--buffer-context-content is a natively compiled function defined in eca-chat-context.el.

Signature

(eca-chat--buffer-context-content BUFFER &optional LINES-RANGE)

Documentation

Return BUFFER text limited to eca-chat-context-buffer-max-chars.

When LINES-RANGE is non-nil, a (:start N :end M) plist, restrict to those lines first, resolved against the live buffer state. When over the limit the tail is kept, where recent output lives.

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--buffer-context-content (buffer &optional lines-range)
  "Return BUFFER text limited to `eca-chat-context-buffer-max-chars'.
When LINES-RANGE is non-nil, a (:start N :end M) plist, restrict
to those lines first, resolved against the live buffer state.
When over the limit the tail is kept, where recent output lives."
  (with-current-buffer buffer
    (save-restriction
      (widen)
      (-let* (((&plist :start start-line :end end-line) lines-range)
              (region-start (if start-line
                                (save-excursion
                                  (goto-char (point-min))
                                  (forward-line (1- start-line))
                                  (point))
                              (point-min)))
              (region-end (if end-line
                              (save-excursion
                                (goto-char (point-min))
                                (forward-line (1- end-line))
                                (line-end-position))
                            (point-max)))
              (max-chars eca-chat-context-buffer-max-chars)
              (start (if (and max-chars (> (- region-end region-start) max-chars))
                         (- region-end max-chars)
                       region-start)))
        (buffer-substring-no-properties start region-end)))))