Skip to content

Instantly share code, notes, and snippets.

@benlubas
Last active November 17, 2023 04:22
Show Gist options
  • Save benlubas/f145b6fe91a9eed5ee6bee9d3e100466 to your computer and use it in GitHub Desktop.
Save benlubas/f145b6fe91a9eed5ee6bee9d3e100466 to your computer and use it in GitHub Desktop.
---
Title: Testing Molten Features
Author: Ben Lubas
---
# Molten Nvim
In this file:
- molten-nvim feature showcase
- WIP features from other branches
---
## Molten Features
If you're contributing, make sure all of this stuff works as it used to (this file is not
necessarily exhaustive, but it'll give you a good idea of if you've broken anything).
```{python}
import random
size = 25
x = range(size)
y = [random.randint(0, 100) for _ in range(size)]
for i in y:
print(i)
```
### PyPlot
```{python}
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
img = ax.plot(x, y)
```
### SVG Rendering
```{python}
import svgwrite
drawing = svgwrite.Drawing(size=(300, 300))
drawing.add(drawing.circle(center=(150, 150), r=100, fill='#FEDE7F'))
drawing.add(drawing.circle(center=(100, 120), r=20, fill='black'))
drawing.add(drawing.circle(center=(200, 120), r=20, fill='black'))
drawing.add(drawing.ellipse(center=(150, 190), r=(50, 20), fill='black'))
drawing
```
### Latex Rendering
Both `sympy` expressions and `%%latex` blocks can be rendered as latex
```{python}
from sympy import symbols, sin, integrate, oo
x, y = symbols("x,y")
expr = integrate(sin((x + y) / y), (y, 0, oo))
expr
```
```{latex}
%%latex
This `\%\%latex` symbol is a "cell magic", it transforms the rest of the cell into latex. Lucky for
us, \% is the comment symbol in latex, so we can tell the markdown treesitter parser that this is
a latex cell without breaking the syntax highlighting even though we're sending it to the python
kernel to be evaluated.
Here is some math:
$$ \frac{(1 + n)}{n} $$
```
### Progress bars
Here you can see how the borders change color with the run state of the cell (this is configurable)
```{python}
from tqdm import tqdm
a = []
for b in tqdm(range(20000000)):
a.append(b)
a.clear()
```
### Errors
Errors get a custom border, this must be configured though.
```{python}
this is not valid python
```
### Multi Buffer
1. run the code cell below
2. open a new buffer
3. run `:MoltenInit shared <kernel>` where kernel is the same kernel this file is using
4. evaluate "qmd_variable" in your new buffer and you'll see the pre-existing value
```{python}
qmd_variable = "Hi from test.qmd!"
```
### MoltenInfo
run `:MoltenInfo` and make sure all the information looks good
### Status Line Stuff
Run the following (I just copy one at a time, type `:lua ` and then paste it)
```{lua}
-- should print molten
print(require('molten.status').initialized())
-- should print the kernels you have running in this buffer
print(require('molten.status').kernels())
-- should print all the kernels running
print(require('molten.status').all_kernels())
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment