Skip to content

Dispatch OSC 51;E elisp synchronously from the process filter#213

Merged
dakra merged 1 commit into
mainfrom
osc51-immediate-dispatch
May 1, 2026
Merged

Dispatch OSC 51;E elisp synchronously from the process filter#213
dakra merged 1 commit into
mainfrom
osc51-immediate-dispatch

Conversation

@dakra
Copy link
Copy Markdown
Owner

@dakra dakra commented Apr 30, 2026

Summary

  • OSC 51;E callbacks (the whitelisted elisp dispatch behind ghostel-eval-cmds) were piggy-backing on the redraw-timer flush of ghostel--pending-output, so find-file and friends ran tens of ms after the writer had already moved on.
  • Callers like b4 prep --edit-cover write the OSC inside a with tempfile.TemporaryDirectory(...) block and then continue immediately. The temp directory was being cleaned up before the deferred dispatch ran, surfacing as ghostel: error calling find-file: Setting current directory: No such file or directory, /tmp/b4-editorXXXX/.
  • Extend the existing immediate-flush regex in ghostel--filter (already used for OSC 4/10/11 color queries) to also cover OSC 51;E. This matches vterm, which runs OSC 51;E elisp synchronously inside term_redraw on the process-filter stack. OSC 51;A (directory tracking) intentionally stays deferred since it has no such race.

Fixes #209.

Test plan

  • make -j4 all (zig + elisp + native + lint) passes
  • make test-evil passes
  • New regression test ghostel-test-osc51-eval-filter-flush covers both the positive case (51;E flushes synchronously) and the negative case (51;A stays pending)
  • Manual smoke test against the issue's python reproducer (and/or b4 prep --edit-cover)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts ghostel’s PTY process filter so OSC 51;E (whitelisted elisp dispatch via ghostel-eval-cmds) is flushed/handled synchronously, preventing races where callers delete temporary directories/files before find-file (etc.) actually runs.

Changes:

  • Extend the process-filter “immediate flush” detection to include OSC 51;E (in addition to OSC 4/10/11 color queries).
  • Add an ERT regression test ensuring OSC 51;E dispatch happens before ghostel--filter returns, while OSC 51;A remains deferred.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lisp/ghostel.el Flush pending output immediately when an OSC 51;E sequence is observed in filter output.
test/ghostel-test.el Add regression test covering synchronous OSC 51;E dispatch and non-flushing OSC 51;A behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lisp/ghostel.el Outdated
@dakra dakra force-pushed the osc51-immediate-dispatch branch from 12da965 to ac26f8f Compare May 1, 2026 08:46
OSC 51;E callbacks were getting batched along with normal terminal
output and only dispatched when the redraw timer fired.  Callers like
`b4 prep --edit-cover' write the OSC and then race ahead — by the time
`find-file' ran, the temp directory had already been cleaned up by the
caller's `with tempfile.TemporaryDirectory' block, producing

  ghostel: error calling find-file: Setting current directory: \
    No such file or directory, /tmp/b4-editorXXXX/

Extend the existing OSC color-query immediate-flush in `ghostel--filter'
to also cover OSC 51;E.  This matches vterm's behavior, where the elisp
queued by `osc_callback' runs synchronously inside `term_redraw' on the
process filter's stack.  OSC 51;A (directory tracking) is left deferred
since it has no such race.

Fixes #209
@dakra dakra force-pushed the osc51-immediate-dispatch branch 2 times, most recently from cb715e0 to 3f8846c Compare May 1, 2026 09:27
@dakra dakra merged commit 3f8846c into main May 1, 2026
20 of 22 checks passed
@dakra dakra deleted the osc51-immediate-dispatch branch May 3, 2026 07:54
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.

ghostel should block while performing ghostel_cmd?

2 participants