Block major-mode changes in live ghostel buffers#544
Merged
Conversation
Changing the major mode runs kill-all-local-variables, which wipes the buffer-locals the native module and PTY depend on, leaving a broken buffer (vterm guards this too, citing segfaults). Signal a user-error from change-major-mode-hook while the terminal process is live; the hook runs before any local state is destroyed, so the aborted switch leaves the buffer fully functional. Dead-process buffers may still change mode freely, which ghostel-compile's finalize/recompile flow relies on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changing the major mode in a ghostel buffer runs
kill-all-local-variables, which wipes the buffer-locals the native module and PTY depend on, leaving a broken buffer. vterm guards against the same thing, citing segfaults.ghostel-modenow adds a buffer-localchange-major-mode-hookthat signals auser-errorwhile the terminal process is live. The hook runs as the first statement ofkill-all-local-variables, before any local state is destroyed, so the aborted switch leaves the buffer fully functional.The guard is conditional on
(process-live-p ghostel--process)rather than unconditional because ghostel-compile legitimately switches modes in both directions (ghostel-mode→ghostel-compile-view-modeat finalize, and back on recompile) — always after tearing down the terminal, so those flows pass through untouched.Verified in a live session: programmatic and interactive mode changes are blocked in a running terminal (which keeps working afterwards), ghostel-compile finalize and
grecompile are unaffected, and mode changes succeed once the shell exits.