include_org!() { /* proc-macro */ }Expand description
Include code from within a source block in an Org file.
Two arguments are required: a file path relative to the current source file,
and a name defined with #+NAME: immediately before the source block as shown below.
All Org source code blocks are supported.
§Examples
Consider the following source block in a crate README.org Org file:
#+NAME: example
#+BEGIN_SRC rust
let m = example()?;
assert_eq!(format!("{m:?}"), r#"Model { name: "example" }"#);
#+END_SRCIn Rust documentation comments, we can use # line to hide setup code.
That’s not possible in Org, so we can include only the code we want to demonstrate;
however, we can still compile and even run it in Rust tests:
struct Model {
name: String,
}
fn example() -> Result<Model, Box<dyn std::error::Error>> {
Ok(Model { name: "example".into() })
}
#[test]
fn test_example() -> Result<(), Box<dyn std::error::Error>> {
include_org!("../README.org", "example");
Ok(())
}