Function: ghostel--line-mode-clear-shell-readline

ghostel--line-mode-clear-shell-readline is a natively compiled function defined in ghostel-line-mode.el.

Signature

(ghostel--line-mode-clear-shell-readline)

Documentation

Erase the adopted prefix from the shell's readline buffer.

On line-mode entry we adopt any pre-existing input (chars the user already typed via the PTY) into the editable buffer, but the shell still holds those bytes in its own line-discipline / readline buffer. Before our next write to the PTY, send that many backspaces so the upcoming line lands on an empty prompt — without this the shell concatenates and echoes a duplicated line.

Backspaces work under any cooked-mode line discipline (bash, fish, zsh, vi-mode readline, python REPL); a readline-only kill like C-u would not. Resets ghostel--line-mode-adopted-count to 0.

Source Code

;; Defined in /nix/store/1252krff0gb2kisjcpp45m50cpdskfrl-emacs-packages-deps/share/emacs/site-lisp/ghostel-line-mode.el
(defun ghostel--line-mode-clear-shell-readline ()
  "Erase the adopted prefix from the shell's readline buffer.
On line-mode entry we adopt any pre-existing input (chars the user
already typed via the PTY) into the editable buffer, but the shell
still holds those bytes in its own line-discipline / readline
buffer.  Before our next write to the PTY, send that many
backspaces so the upcoming line lands on an empty prompt — without
this the shell concatenates and echoes a duplicated line.

Backspaces work under any cooked-mode line discipline (bash, fish,
zsh, vi-mode readline, python REPL); a readline-only kill like
`C-u' would not.  Resets `ghostel--line-mode-adopted-count' to 0."
  (when (and ghostel--line-mode-adopted-count
             (> ghostel--line-mode-adopted-count 0))
    (dotimes (_ ghostel--line-mode-adopted-count)
      (ghostel--send-encoded "backspace" "")))
  (setq ghostel--line-mode-adopted-count 0))