Skip to content

Rewrite persistent output: reliably save results into the note (org-babel-style)#449

Open
nelsonlove wants to merge 6 commits into
twibiral:masterfrom
nelsonlove:persistent-output-vault-write
Open

Rewrite persistent output: reliably save results into the note (org-babel-style)#449
nelsonlove wants to merge 6 commits into
twibiral:masterfrom
nelsonlove:persistent-output-vault-write

Conversation

@nelsonlove

Copy link
Copy Markdown

Summary

The persistent output feature (saving a block's output into the note as an ```output block) currently relies on view.previewMode.renderer.sections and streaming `editor.replaceRange` calls. In practice this fails silently in most contexts: reading view, live preview, and `run-` prefixed blocks all end up with output on screen but nothing saved to the note.

This PR rewrites FileAppender around two ideas:

  1. Buffer per run, write once on completion — output chunks accumulate in memory; when the block finishes, the result is written in a single atomic Vault.process() call. No editor dependency, so it works identically in reading view, live preview, and for run- blocks.
  2. Locate the block robustly — primary: the markdown post-processor's ctx.getSectionInfo() (threaded through addToAllCodeBlocks and fetched lazily at write time, since line numbers shift); fallback: scan the note for the fenced block whose body matches the block's source. Covers run- blocks, where section info is unavailable.

Re-running a block replaces its previous ```output block instead of appending, like org-babel's #+RESULTS:. If the block genuinely can't be located (e.g. its source was edited since rendering), the user gets one Notice per run (builds on #448, whose commits are included here).

Testing

npm run build passes. Manually verified in a live vault (macOS) with "Save output in note" enabled:

  • Regular block, reading view → ```output block written into the note below the code block
  • Re-run → output block replaced, not duplicated
  • run- prefixed block (previously always failed) → output saved via the fallback matcher
  • Block producing no stdout → note untouched

🤖 Generated with Claude Code

nelsonlove and others added 6 commits July 11, 2026 06:29
…en the code block can't be located

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… render, not per execution

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ion start

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… completion

Locates the block via the post-processor's getSectionInfo when available,
falling back to matching the block's source text. Works in reading view,
live preview, and for run- prefixed blocks; re-running replaces the output
block instead of appending.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…output; hide live element once saved

Reading view used to hide saved ```output blocks via CSS (a workaround for
the old streaming write). Now that output is written once on completion,
the saved block IS the result display — render it in all views, insert it
with a blank line after the code block, and hide the ephemeral on-screen
output element once the note has been updated.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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