Skip to content

RFC: Add session option#27

Open
laburnumT wants to merge 2 commits into
gpanders:masterfrom
laburnumT:master
Open

RFC: Add session option#27
laburnumT wants to merge 2 commits into
gpanders:masterfrom
laburnumT:master

Conversation

@laburnumT

Copy link
Copy Markdown

Adds a session option to codeblocks so previous results can be used.

To check that a command is done running, we wait for an eof_token to appear. This allows us to not cut off commands with output early, but also doesn't rely on using sleep.

@laburnumT

Copy link
Copy Markdown
Author

This is an RFC for adding session support to vim-medieval. It's currently quite
hacky, because repl's aren't always accessed the same way. But that's why it's a
first draft.

It currently has some checks in there for python (because that's what I use in
markdown for the most part).

This should probably be integrated into g:medieval_langs, or a new config
variable, but I just wanted to know if there is any interest in functionality
like this before I do that work.

@laburnumT

Copy link
Copy Markdown
Author

The main problem this is trying to address is where something is either costly
to run or not idempotent. As a rather stupid example:

<!-- session: example -->
```python
import random
import time

time.sleep(5)
x = 42
```

<!-- session: example -->
```python
print(random.randint(1, x))
```

Using require here would make the print block always take 5 seconds, whereas
with a session it would run instantly (as long as the first code block has been
run at least once)

laburnumT added 2 commits July 9, 2026 09:59
Adds a session option to codeblocks so previous results can be used.

To check that a command is done running, we wait for an eof_token to
appear. This allows us to not cut off commands with output early, but
also doesn't rely on using sleep.

**This commit does not support neovim**
Splits up retrieving the data from s:session_read_cb into separate
helper functions for vim and nvim.
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