Add ghostel-pre-spawn-hook for env injection at spawn time#227
Conversation
|
@claude review |
|
Claude finished @dakra's task in 2m 42s —— View job Claude Code review
Overall: small, self-contained, and well-motivated. The two spawn paths and the docstring contract line up; integration shape matches Findings1. Test coverage skips 2. Hook order in 3. Docstring at 4. 5. CHANGELOG not updated (NIT) Non-issues I checked
|
|
@claude review |
|
Claude finished @dakra's task in 3m 46s —— View job Claude Code review
Overall: this v2 redesign is a meaningful win over the v1 post-spawn-hook approach — env injection at fork time sidesteps the byte-stream race against shell rc, keeps TUI spawns clean, and the firing site (inside
A few remaining observations, all NIT. Findings1. Test exercises 2. A pre-spawn-hook error leaks remote temp paths (NIT) 3. Docstring could note that 4. Test asserts on a process that hasn't been awaited (NIT) Non-issues I checked
|
82ada83 to
f5e31b2
Compare
Provide a hook that fires inside `ghostel--spawn-pty' immediately before `make-process', with `process-environment' dynamically bound to the env that will be passed to the child. Hook functions can `setenv' to inject or override entries that the spawned process inherits at fork time. One firing site covers both spawn paths (`ghostel--start-process' used by `ghostel'/`ghostel-project', and `ghostel-exec'). `ghostel-compile' has its own `make-process' call and is not covered, matching today's separation. Motivation: third-party packages like with-editor need to set `EDITOR' so Magit's commit-edit / rebase-edit flows pop their files in the running Emacs instead of trying to launch a new editor. The value isn't known statically (it depends on the live Emacs server), so `ghostel-environment' can't carry it; and a static mode-hook fires too early — before the PTY exists. Pre-spawn env injection (this hook) is preferable to post-spawn wire injection (sending `export EDITOR=...\\n' to a live shell) because env inheritance avoids: the shell-rc race, the leading- space history-suppress dance, visible buffer noise, and the footgun where the export bytes would land as keystrokes when `ghostel-exec' is used to launch a TUI like htop or claude. Test drives a real `/bin/sh' through `ghostel--start-process', has the hook `setenv' a sentinel, and asserts the value reached `make-process'.
Summary
ghostel-pre-spawn-hookdefcustom that fires insideghostel--spawn-ptyimmediately beforemake-process, withprocess-environmentdynamically bound to the about-to-be-spawned env.setenvto inject or override entries that the spawned process inherits at fork time.ghostel--start-processandghostel-exec).ghostel-compilehas its ownmake-processand is not covered, matching today's separation.Replaces the earlier post-spawn
ghostel-exec-hookdesignThe first revision of this branch added a post-spawn hook that fired after
make-process, intended to be paired withwith-editor-export-editor(which sendsexport EDITOR=…\nto a live shell). On review, pre-spawn env injection turned out to be strictly better:ghostel-exec-hook(v1)ghostel-pre-spawn-hook(this PR)add-hookadd-hookcondbranch inwith-editor-export-editorwith-editor-setup-environment)export …line)htop,claudeviaghostel-exec)Motivation
with-editor needs to set
EDITORso Magit's commit-edit / rebase-edit flows pop their files in the running Emacs. The value can't be put inghostel-environment(it depends on the live Emacs server'sserver-name/server-process/server-auth-dir, computed at runtime), and a mode-hook fires too early — before the PTY exists.Intended user config (after the matching with-editor patch)
The
with-editor-setup-environmentside is a small upstream change — a public wrapper around the existing privatewith-editor--setup— and will be proposed separately.Test plan
make -j4 allclean (build + lint + test + test-native, 219/219).ghostel-test-pre-spawn-hook-injects-into-process-environmentdrives a real/bin/shthroughghostel--start-process, has the hooksetenva sentinel value, and asserts the value reachedmake-process'sprocess-environment(also addresses the v1 review's NITs about real-process coverage).git commit --allow-emptyfrom a ghostel buffer popsCOMMIT_EDITMSG;C-c C-creturns the shell with exit 0.