Skip to content

Block major-mode changes in live ghostel buffers#544

Merged
dakra merged 1 commit into
mainfrom
fix/lock-major-mode
Jul 15, 2026
Merged

Block major-mode changes in live ghostel buffers#544
dakra merged 1 commit into
mainfrom
fix/lock-major-mode

Conversation

@dakra

@dakra dakra commented Jul 14, 2026

Copy link
Copy Markdown
Owner

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-mode now adds a buffer-local change-major-mode-hook that signals a user-error while the terminal process is live. The hook runs as the first statement of kill-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-modeghostel-compile-view-mode at 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 g recompile are unaffected, and mode changes succeed once the shell exits.

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.
@dakra dakra merged commit f00d735 into main Jul 15, 2026
28 checks passed
@dakra dakra deleted the fix/lock-major-mode branch July 15, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant