Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactive markdown #1304

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

garlic0x1
Copy link
Collaborator

@garlic0x1 garlic0x1 commented Feb 17, 2024

This adds interactive features to markdown code blocks, like how src blocks in org-mode work.

The API consists of 3 commands: markdown-eval-block, markdown-eval-block-and-insert, and markdown-kill-block-result, as well as one macro, register-block-evaluator for users to add support for other languages (lisp and bash work by default).

markdown-eval-block evaluates the source block your cursor is in, and outputs the result to a popup buffer (just like lisp-macroexpand)

markdown-eval-block-and-insert evaluates the block and inserts it's result below the block. If there was already a result there, it first deletes the old one.

markdown-kill-block-result deletes the result block below the code block your cursor is in, this is run automatically before markdown-eval-block-and-insert.

If you try to evaluate a block and there is no registered evaluator, a message is displayed saying so. If you use any of these commands outside a code block, nothing happens. If you use these commands while not in markdown-mode, a warning is displayed.

Evaluation commands work asynchronously and you can do whatever you want while it is working.

Here is a demo:
Screencast from 2024-02-17 14-15-46.webm


(defmacro with-constant-position ((point) &body body)
"This allows you to move around the point without worry."
`(let ((tmp (copy-point ,point)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you know of with-point(s)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Doesn't seem to work the same, I will play around with it for a bit though and see if I can get it to work.

I tried to replace

(with-constant-position (point)
  ...)

with

(with-point ((point point))
  ...)

Copy link
Member

Choose a reason for hiding this comment

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

If you don't call delete-point for copy-point, the memory leaks.

@garlic0x1
Copy link
Collaborator Author

garlic0x1 commented Feb 22, 2024

What is your guys' opinions on adding a feature like this that allows custom post-processing:

```http
GET http://localhost/json
```json

The idea is that this could be added on to output formatted JSON, this could be used in any situation where the ~a
format is not desired. Examples include formatted JSON and HTML as well as using ~s or custom functions handling database tables.

Downside is that it doesn't look pretty in a markdown renderer, although for default behavior it would change nothing.

What are your thoughts?

Edit: prototype here https://github.com/garlic0x1/lem/tree/block-metadata

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants