Literate Programming toolbox
Project description
Entangled
Entangled is a solution for Literate Programming, a technique in which the programmer writes a human narrative first, then implementing the program in code blocks. Literate programming was introduced by Donald Knuth in 1984 and has since then found several surges in popularity. One thing holding back the popularity of literate programming is the lack of maintainability under increasing program complexity. Entangled solves this issue by offering a two-way synchronisation mechanism. You can edit and debug your code as normal in your favourite IDE or text editor. Entangled will make sure that your Markdown files stay up-to-date with your code and vice-versa. Because Entangled works with Markdown, you can use it with most static document generators. To summarise, you keep using:
- your favourite editor: Entangled runs as a daemon in the background, keeping your text files synchronised.
- your favourite programming language: Entangled is agnostic to programming languages.
- your favourite document generator: Entangled is configurable to any dialect of Markdown.
Get started
To install Entangled, all you need is a Python installation. If you use poetry
,
poetry add entangled-cli[rich]
Or, if you prefer pip
,
pip install entangled-cli[rich]
Use
:warning: This version of Entangled is still in alpha. Configuration is not yet implemented.
Run the entangled watch
daemon in the root of your project folder. By default all Markdown files are monitored for fenced code blocks like so:
``` {.rust #hello file="src/world.rs"}
...
```
The syntax of code block properties is the same as CSS properties: #hello
gives the block the hello
identifier, .rust
adds the rust
class and the file
attribute is set to src/world.rs
(quotes are optional). For Entangled to know how to tangle this block, you need to specify a language and a target file. However, now comes the cool stuff. We can split our code in meaningful components by cross-refrences.
Hello World in C++
The combined code-blocks in this example compose a compilable source code for "Hello World". For didactic reasons we don't always give the listing of an entire source file in one go. In stead, we use a system of references known as noweb (after Ramsey 1994).
Inside source fragments you may encounter a line with <<...>>
marks like,
``` {.cpp file=hello_world.cc}
#include <cstdlib>
#include <iostream>
<<example-main-function>>
```
which is then elsewhere specified. Order doesn't matter,
``` {.cpp #hello-world}
std::cout << "Hello, World!" << std::endl;
```
So we can reference the <<hello-world>>
code block later on.
``` {.cpp #example-main-function}
int main(int argc, char **argv)
{
<<hello-world>>
}
```
A definition can be appended with more code as follows (in this case, order does matter!):
``` {.cpp #hello-world}
return EXIT_SUCCESS;
```
These blocks of code can be tangled into source files.
History
This is a rewrite of Entangled in Python. Older versions were written in Haskell. The rewrite in Python was motivated by ease of installation, larger community and quite frankly, a fit of mental derangement.
Contributing
If you have an idea for improving Entangled, please file an issue before creating a pull request. Code in this repository is formatted using black
and type checked using mypy
.
License
Copyright 2023 Netherlands eScience Center, written by Johan Hidding, licensed under the Apache 2 license, see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file entangled_cli-2.0.0a2.tar.gz
.
File metadata
- Download URL: entangled_cli-2.0.0a2.tar.gz
- Upload date:
- Size: 22.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9764e5dbdde64b9e8c68a6dbd8d74e9b3431cb1ae2b75e36ad3ce47f0b3b063 |
|
MD5 | aaec3aeff0d60e8207ee7018417ac70c |
|
BLAKE2b-256 | 48a438ec11373a3615abe354421724d2a9d9c33029a370fe1ed822cb08a6c40e |
File details
Details for the file entangled_cli-2.0.0a2-py3-none-any.whl
.
File metadata
- Download URL: entangled_cli-2.0.0a2-py3-none-any.whl
- Upload date:
- Size: 29.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3226291a6b0066d121fe4ac07cb15c2203fa7a2a052edceb609e022f3748cb38 |
|
MD5 | 375978bb7b8c9be30a830dd53faecd08 |
|
BLAKE2b-256 | d7bd146c3ae7ce668fbbb3c1a44584121a09513df35d990d99649193b0e0af76 |