Function: eca-chat--key-pressed-deletion
eca-chat--key-pressed-deletion is a natively compiled function defined
in eca-chat.el.
Signature
(eca-chat--key-pressed-deletion SIDE-EFFECT-FN &rest ARGS)
Documentation
Apply SIDE-EFFECT-FN with ARGS before point.
Unless at the prompt field boundary.
Checks if it's in a context, removing it if so.
This is similar to actions like backward-delete-char but protects
the prompt/context line.
Source Code
;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-chat.el
(defun eca-chat--key-pressed-deletion (side-effect-fn &rest args)
"Apply SIDE-EFFECT-FN with ARGS before point.
Unless at the prompt field boundary.
Checks if it's in a context, removing it if so.
This is similar to actions like `backward-delete-char' but protects
the prompt/context line."
(if (derived-mode-p 'eca-chat-mode)
(let* ((cur-ov (car (overlays-in (line-beginning-position) (line-end-position))))
(prompt-ov (eca-chat--prompt-field-ov))
(context-ov (eca-chat--prompt-context-field-ov))
(text (thing-at-point 'symbol))
(in-prompt? (eca-chat--point-at-prompt-field-p))
;; On the context line, right above the prompt field. Not
;; derived from `cur-ov', which is whatever overlay happens
;; to come first on the line (hl-line, ...).
(in-context? (and context-ov
prompt-ov
(<= (overlay-start context-ov) (point))
(< (point) (overlay-start prompt-ov))))
(context-item (-some->> text
(get-text-property 0 'eca-chat-context-item)))
(item-str-length (-some->> text
(get-text-property 0 'eca-chat-item-str-length)))
;; The item the symbol at point starts in, unless point is
;; past its end, e.g. after text typed right after it.
(item-bounds (when item-str-length
(when-let* ((bounds (eca--property-run-bounds
(car (bounds-of-thing-at-point 'symbol))
'eca-chat-expanded-item-str)))
(when (<= (car bounds) (point) (cdr bounds))
bounds)))))
(cond
;; expandable item in context area
((and cur-ov
context-item
(not in-prompt?))
(setq-local eca-chat--context (delete context-item eca-chat--context))
(eca-chat--refresh-context))
;; expandable item in prompt: delete it whole, by its actual
;; bounds and never past the prompt start, since a partial
;; deletion can leave it shorter than `eca-chat-item-str-length'
((and cur-ov
item-bounds
in-prompt?)
(delete-region (max (car item-bounds) (overlay-start prompt-ov))
(cdr item-bounds)))
;; Handle some evil commands
((and in-prompt?
(or (eq #'evil-delete this-command)
(eq #'evil-change-line this-command)))
(setf (nth 2 args) nil) ;; do not delete prompt line passing nil argument
(apply side-effect-fn args))
;; start of the context line - its leading `@' is either the
;; first context or the unlinked prefix, and a backward deletion
;; would join the line with the progress area above.
((and in-context?
(= (point) (overlay-start context-ov)))
(ding))
;; start of the prompt - keep the guard everywhere above the
;; prompt-field start except on the context line (handled below,
;; see #306), but at the start itself block only *backward*
;; deletions. A forward deletion there (`delete-char' from
;; evil-invert-char ~, evil-replace r, evil-delete-char x,
;; evil-substitute s, or C-d) removes the first prompt char, which
;; is legitimate; everything else is unchanged. A negative count
;; (e.g. `C-u - C-d') makes `delete-char' delete backward, so still
;; guard that.
((and prompt-ov
(not in-context?)
(or (< (point) (overlay-start prompt-ov))
(and (= (point) (overlay-start prompt-ov))
(or (memq this-command eca-chat--prompt-boundary-guard-commands)
(and (integerp (car args)) (< (car args) 0))))
(and (eq 'backward-kill-word this-command)
(string-blank-p (buffer-substring-no-properties
(overlay-start prompt-ov) (point))))))
(ding))
;; in context area trying to remove a context space separator or
;; the `@' prefix of the typed query
((and in-context?
(not (eolp))
(or (string= " " (string (char-before (point))))
(string= eca-chat-context-prefix (string (char-before (point)))))))
;; in context area removing a context
((and in-context?
(string= eca-chat-context-prefix (string (char-before (point)))))
(setq-local eca-chat--context (delete (car (last eca-chat--context)) eca-chat--context))
(eca-chat--refresh-context)
(end-of-line))
;; in context area editing the typed query (#306)
(in-context?
(apply #'eca-chat--apply-within-context-line context-ov side-effect-fn args)
(eca-chat--sync-context-line context-ov))
(t (apply side-effect-fn args))))
(apply side-effect-fn args)))