Skip to content

fix(compiler): preserve viewer_open and fire PreviewWatchingStopped event#61

Merged
barrettruth merged 3 commits intomainfrom
feat/watching-stopped-event
Mar 15, 2026
Merged

fix(compiler): preserve viewer_open and fire PreviewWatchingStopped event#61
barrettruth merged 3 commits intomainfrom
feat/watching-stopped-event

Conversation

@barrettruth
Copy link
Owner

Problem

When open is a fire-and-forget command (e.g. sioyek --instance-name), the spawned process exits immediately. The exit callback cleared viewer_open, causing every recompile to reopen the viewer and breaking toggle-off. Additionally, there was no user event for reacting to watch stop, making it impossible to clean up external state like SyncTeX forward-search entries.

Solution

Stop resetting viewer_open in the do_open exit callback — it now persists until stop_watching. Fire a new PreviewWatchingStopped user autocmd from stop_watching with bufnr and provider in the event data.

Problem: when `open` is a custom command like `sioyek --instance-name`,
the process exits immediately after delegating to the running instance.
The exit callback reset `viewer_open`, causing every recompile to reopen
the viewer and toggle to reopen instead of stopping.

Solution: stop clearing `viewer_open` in the `do_open` exit callback.
The flag now persists for the watch session and is only reset by
`stop_watching`.
Problem: there was no way for user config to react when preview watching
stops, e.g. to clean up forward-search state for SyncTeX.

Solution: fire a `PreviewWatchingStopped` user autocmd from
`stop_watching` with `bufnr` and `provider` in the event data.
Problem: the new `PreviewWatchingStopped` event was undocumented, and
the SyncTeX recipes never cleared `synctex_pdf` on watch stop.

Solution: add the event to the events section and update the shared
SyncTeX setup block to clear `synctex_pdf[bufnr]` on stop.
@barrettruth barrettruth merged commit a2fc382 into main Mar 15, 2026
7 checks passed
@barrettruth barrettruth deleted the feat/watching-stopped-event branch March 15, 2026 17:36
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