Function: ghostel-input-start-point
ghostel-input-start-point is a natively compiled function defined in
ghostel.el.
Signature
(ghostel-input-start-point)
Documentation
Return the buffer position where the current input begins.
The cursor's buffer position is the source of truth — whatever the
terminal has written sits before it, and user input goes after.
When ghostel--cursor-char-pos is nil (no live terminal, or
cursor not yet positioned), fall back to the rightmost
ghostel-prompt text-property character. When the cursor IS
available and the cursor's row carries ghostel-prompt characters
(OSC 133 shell integration), return the position right after the
last contiguous ghostel-prompt char on that row. Without the
prop, consult ghostel-prompt-regexp as a fallback; if neither
detects a prompt, return the cursor position itself. Returns nil
when nothing can locate a position (no cursor and no detection).
Source Code
;; Defined in /nix/store/1252krff0gb2kisjcpp45m50cpdskfrl-emacs-packages-deps/share/emacs/site-lisp/ghostel.el
(defun ghostel-input-start-point ()
"Return the buffer position where the current input begins.
The cursor's buffer position is the source of truth — whatever the
terminal has written sits before it, and user input goes after.
When `ghostel--cursor-char-pos' is nil (no live terminal, or
cursor not yet positioned), fall back to the rightmost
`ghostel-prompt' text-property character. When the cursor IS
available and the cursor's row carries `ghostel-prompt' characters
\(OSC 133 shell integration), return the position right after the
last contiguous `ghostel-prompt' char on that row. Without the
prop, consult `ghostel-prompt-regexp' as a fallback; if neither
detects a prompt, return the cursor position itself. Returns nil
when nothing can locate a position (no cursor and no detection)."
(let ((cursor-pos ghostel--cursor-char-pos))
(cond
(cursor-pos
(let* ((row-start (save-excursion
(goto-char cursor-pos)
(line-beginning-position)))
(pos cursor-pos))
;; Walk back from the cursor on its row, looking for the
;; rightmost `ghostel-prompt' character. The first prompt
;; char we hit (scanning right-to-left) is the end of the
;; prompt prefix - so its position+1, which is the current
;; `pos' when we stop, is the input boundary.
(while (and (> pos row-start)
(not (get-text-property (1- pos) 'ghostel-prompt)))
(setq pos (1- pos)))
(cond
((and (> pos row-start)
(get-text-property (1- pos) 'ghostel-prompt))
pos)
;; No OSC 133 prop - try the regex fallback.
((ghostel--regex-prompt-end cursor-pos))
;; Neither prop nor regex - the cursor itself is the boundary
(t cursor-pos))))
(t
;; No live terminal - fall back to the OSC 133 walk-back so the helper
;; stays useful in unit tests that exercise prompt markers in isolation.
(let ((pos (point-max))
(pmin (point-min)))
(while (and (> pos pmin)
(not (get-text-property (1- pos) 'ghostel-prompt)))
(setq pos (1- pos)))
(when (and (> pos pmin)
(get-text-property (1- pos) 'ghostel-prompt))
pos))))))