Function: ghostel--spawn-pty

ghostel--spawn-pty is a natively compiled function defined in ghostel.el.

Signature

(ghostel--spawn-pty PROGRAM PROGRAM-ARGS EXTRA-ENV &optional REMOTE-P)

Documentation

Spawn PROGRAM with PROGRAM-ARGS as a PTY-backed process in the current buffer.

The native local path execs PROGRAM directly and configures the PTY in C (see ghostel--spawn-via-native). The Emacs path wraps PROGRAM in /bin/sh -c so stty can configure the PTY before PROGRAM reads its terminal attributes (see ghostel--spawn-via-emacs). EXTRA-ENV is prepended to process-environment. Non-nil REMOTE-P spawns the process via the TRAMP file handler (for remote shells).

Returns the lifecycle process object for the PTY path: the shell process for Emacs-owned PTYs, or the event pipe process that stands in for the native child process.

Source Code

;; Defined in /nix/store/1252krff0gb2kisjcpp45m50cpdskfrl-emacs-packages-deps/share/emacs/site-lisp/ghostel.el
(defun ghostel--spawn-pty (program program-args extra-env &optional remote-p)
  "Spawn PROGRAM with PROGRAM-ARGS as a PTY-backed process in the current buffer.

The native local path execs PROGRAM directly and configures the PTY
in C (see `ghostel--spawn-via-native').  The Emacs path wraps PROGRAM
in `/bin/sh -c' so `stty' can configure the PTY before PROGRAM reads
its terminal attributes (see `ghostel--spawn-via-emacs').  EXTRA-ENV
is prepended to `process-environment'.  Non-nil REMOTE-P spawns the
process via the TRAMP file handler (for remote shells).

Returns the lifecycle process object for the PTY path: the shell
process for Emacs-owned PTYs, or the event pipe process that stands in
for the native child process."
  (let* ((process-environment
          (append
           ghostel-environment
           (cons "INSIDE_EMACS=ghostel"
                 ;; The remote wrapper sets TERM/TERMINFO/COLORTERM/
                 ;; TERM_PROGRAM* itself; keeping the local entries
                 ;; here would also push the local TERMINFO path,
                 ;; which is meaningless on the remote and (per
                 ;; terminfo(5)) makes ncurses ignore system entries.
                 (if remote-p '() (ghostel--terminal-env)))
           extra-env
           (ghostel--logical-pwd-env remote-p)
           process-environment))
         ;; Large TUI redraws (Claude Code, pi on resize) can emit
         ;; hundreds of KB in one write.  Before Emacs 31,
         ;; `process-adaptive-read-buffering' defaults to t and
         ;; throttles the filter to ~40 KB/s for bursty processes,
         ;; making resize feel like a slow cascade.
         ;; Also raise the per-read cap so one filter call can
         ;; consume a full redraw frame.  Both are captured at
         ;; `make-process' time, so they must be let-bound here.
         (process-adaptive-read-buffering nil)
         (read-process-output-max (max read-process-output-max (* 1024 1024))))
    ;; Pre-spawn hook: runs while `process-environment' is dynamically
    ;; bound to the about-to-be-spawned env, so hook functions can
    ;; `setenv' to inject/override entries that the child inherits.
    ;; See `ghostel-pre-spawn-hook'.
    (run-hooks 'ghostel-pre-spawn-hook)
    (ghostel--spawn-process program program-args remote-p)))