Function: eca-chat--apply-within-context-line

eca-chat--apply-within-context-line is a natively compiled function defined in eca-chat.el.

Signature

(eca-chat--apply-within-context-line CONTEXT-OV FN &rest ARGS)

Documentation

Apply FN to ARGS keeping the newlines around the context line.

CONTEXT-OV is the context area overlay. The newlines delimiting its line belong to the prompt block markup: a forward delete-char at the line end or a line-wise evil operator like dd would merge the line with the prompt field or the progress area and corrupt the block (see #305). The direction of a wrapped deletion cannot be told from its arguments (evil's insert-state backspace, for one, wraps delete-backward-char), so instead both newlines are made read-only while FN runs and the text-read-only it then signals is turned into a ding.

Source Code

;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-chat.el
(defun eca-chat--apply-within-context-line (context-ov fn &rest args)
  "Apply FN to ARGS keeping the newlines around the context line.
CONTEXT-OV is the context area overlay.  The newlines delimiting its
line belong to the prompt block markup: a forward `delete-char' at
the line end or a line-wise evil operator like `dd' would merge the
line with the prompt field or the progress area and corrupt the
block (see #305).  The direction of a wrapped deletion cannot be told
from its arguments (evil's insert-state backspace, for one, wraps
`delete-backward-char'), so instead both newlines are made
`read-only' while FN runs and the `text-read-only' it then signals
is turned into a `ding'."
  (let* ((start (overlay-start context-ov))
         (end (save-excursion (goto-char start) (line-end-position)))
         (newlines (->> (list (when (> start (point-min)) (1- start))
                              (when (< end (point-max)) end))
                        (-non-nil)
                        (--remove (get-text-property it 'read-only))
                        (-map #'copy-marker))))
    (with-silent-modifications
      (dolist (marker newlines)
        (put-text-property marker (1+ marker) 'read-only t)))
    (unwind-protect
        (condition-case nil
            (apply fn args)
          (text-read-only (ding)))
      (with-silent-modifications
        (dolist (marker newlines)
          (remove-list-of-text-properties marker (1+ marker) '(read-only))
          (set-marker marker nil))))))