Function: ghostel--line-mode-teardown
ghostel--line-mode-teardown is a natively compiled function defined in
ghostel-line-mode.el.
Signature
(ghostel--line-mode-teardown &optional PAUSE)
Documentation
Clean up line-mode state and hand any pending input back to the shell.
Any in-progress input is forwarded to the PTY raw (no newline) so
the user can continue editing it at the shell's own prompt after
the mode switch instead of losing what they typed. Callers that
have already handled the input themselves (like
ghostel-line-mode-send and ghostel-line-mode-interrupt) delete
it from the buffer before calling this, so no double-send happens.
Forces a final redraw so the buffer truncation done at entry is re-materialized from libghostty.
When PAUSE is non-nil, skip forwarding pending input to the PTY,
skip the readline-clearing backspaces (the alt-screen TUI would receive them),
and skip the trailing redraw; used by ghostel--line-mode-pause,
which discards any type-ahead and runs inside ghostel--redraw-now.
Source Code
;; Defined in /nix/store/1252krff0gb2kisjcpp45m50cpdskfrl-emacs-packages-deps/share/emacs/site-lisp/ghostel-line-mode.el
(defun ghostel--line-mode-teardown (&optional pause)
"Clean up line-mode state and hand any pending input back to the shell.
Any in-progress input is forwarded to the PTY raw (no newline) so
the user can continue editing it at the shell's own prompt after
the mode switch instead of losing what they typed. Callers that
have already handled the input themselves (like
`ghostel-line-mode-send' and `ghostel-line-mode-interrupt') delete
it from the buffer before calling this, so no double-send happens.
Forces a final redraw so the buffer truncation done at entry is
re-materialized from libghostty.
When PAUSE is non-nil, skip forwarding pending input to the PTY,
skip the readline-clearing backspaces (the alt-screen TUI would receive them),
and skip the trailing redraw; used by `ghostel--line-mode-pause',
which discards any type-ahead and runs inside `ghostel--redraw-now'."
;; Undo is off outside line mode; disable it before the teardown edits
;; below so none of them are recorded.
(setq buffer-undo-list t)
(unless pause
(let ((input (ghostel--line-mode-input-text)))
;; Erase the adopted prefix from the shell's readline before
;; handing back our (possibly edited) version, so the shell ends
;; up holding exactly INPUT instead of "<adopted>INPUT".
(ghostel--line-mode-clear-shell-readline)
(when (> (length input) 0)
(ghostel--write-pty ghostel--term input))))
(ghostel--line-mode-delete-input)
;; Drop the `read-only' and `rear-nonsticky' properties that
;; protected the scrollback region during line mode; after this teardown
;; the whole ghostel buffer returns to the default renderer-owned lock.
(let ((inhibit-read-only t))
(remove-text-properties (point-min) (point-max)
'(read-only nil rear-nonsticky nil)))
(setq buffer-read-only t)
(when (markerp ghostel--line-input-start)
(set-marker ghostel--line-input-start nil))
(when (markerp ghostel--line-input-end)
(set-marker ghostel--line-input-end nil))
(setq ghostel--line-input-start nil)
(setq ghostel--line-input-end nil)
(setq ghostel--line-mode-history-index nil)
(setq ghostel--line-mode-adopted-count nil)
(setq ghostel--line-mode-on-alt-screen nil)
(when ghostel--line-mode-saved-cursor-type
(setq cursor-type (car ghostel--line-mode-saved-cursor-type))
(setq ghostel--line-mode-saved-cursor-type nil))
(unless pause
(when ghostel--term
(let ((inhibit-read-only t)
(inhibit-modification-hooks t))
(ghostel--redraw ghostel--term t t))
(ghostel--schedule-link-detection))))