Repository navigation
Defer the repair of foreign deletions to after the command - #726
Merged
Merged
Conversation
Looping deletion commands such as delete-indentation hung Emacs in live terminal-input modes: the after-change hook repaired every deletion with a synchronous full redraw, so the command never ran out of text to delete. A deletion now only flags the buffer and installs a one-shot post-command-hook member. That member runs one forced redraw after the command ends; the redraw is full while the flag is set and realigns point to the terminal cursor. Insertions made while the repair is pending are dropped with it instead of being forwarded to the PTY. A deletion made outside a command is repaired on the next redisplay. Fix #724
dakra
force-pushed
the
fix/deferred-deletion-repair
branch
from
October 12, 2026 11:39
6f5036a to
df8a540
Compare
This branch was previously deployed
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.
Fixes #724.
Problem
In live terminal-input modes (semi-char, char) the buffer is writable so that foreign insertions (
emoji-insert,insert-char, yank from a package, …) can be caught inafter-change-functionsand forwarded to the PTY. A foreign deletion of rendered text was repaired inside that same hook by a synchronous full redraw plus agoto-charto the terminal cursor.A command that deletes in a loop until a text condition holds never terminates under that scheme: every
delete-charis undone before the loop re-checks.delete-indentationhangs Emacs, and so does anything shaped like it.Change
The deletion branch of the hook no longer redraws. It sets a buffer-local flag, marks a redraw pending, and installs a one-shot buffer-local
post-command-hookmember. That member removes itself and runs one forced redraw after the command ends.ghostel--redraw-nowrenders a full frame while the flag is set and, after a successful render, clears it and realigns point to the terminal cursor.delete-indentationdeletes a newline and thenfixup-whitespaceinserts a space; onmainthat space reached the shell as a keystroke.ghostel--pending-redrawpath.Nothing is installed in the steady state: the renderer, the output filter and the text properties on rendered text are unchanged, so redraw time and scrollback memory are identical to
main. The after-change hook tests one more buffer-local variable per foreign change, and the redraw path one more when choosing full versus incremental.Visible behaviour
A looping deletion command finishes, then the terminal contents come back and point returns to the cursor. There is no error message. The mode stays semi-char, so the deferred point-leave check does not switch to copy mode.
Known gaps
M-x, now sends nothing to the PTY; onmainthe inserted text was forwarded after the repair.Alternative that was rejected
#725 (kept as a draft for reference) made rendered text
read-onlywithrear-nonstickytext properties so deletions signaltext-read-only. Benchmarks there showed 5 to 8 percent slower redraws of heavily styled output and 43 percent more live memory on styled scrollback, because Emacs copies the property list into every face-run interval. A singlecategoryproperty halved the memory but was slower still. This PR has no rendering cost.Tests
test/ghostel-insert-forward-test.el: the repair tests assert the deferral and the one-shot hook; new tests cover dropped insertions while pending,delete-indentationfinishing, repair on redisplay without a command, and the native path restoring text and realigning point.make -j8 allpasses.Verified live under elate with bash:
M-x delete-indentationas a key-driven command returns with the buffer restored, point on the cursor and the mode unchanged; an explicit deletion loop to the buffer start finishes; programmatickill-regionfills the kill ring and the text comes back;echo hiinserted into the buffer still reaches the shell.