Dump the elisp when running compare.

This commit is contained in:
Tom Alexander 2023-04-10 14:28:40 -04:00
parent 552ac974d5
commit 96d2cc7c6a
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 32 additions and 1 deletions

View File

@ -3,6 +3,7 @@ name = "toy"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
license = "0BSD" license = "0BSD"
default-run = "toy"
[[bin]] [[bin]]
name = "toy" name = "toy"

View File

@ -1 +1,2 @@
mod parse;
pub use parse::emacs_parse_org_document;

26
src/compare/parse.rs Normal file
View File

@ -0,0 +1,26 @@
use std::path::Path;
use std::process::Command;
pub fn emacs_parse_org_document<'a, C>(file_path: C) -> Result<String, Box<dyn std::error::Error>>
where
C: AsRef<Path>,
{
let elisp_script = r#"(progn
(org-mode)
(message "%s" (pp-to-string (org-element-parse-buffer)))
)"#;
let mut cmd = Command::new("emacs");
let proc = cmd
.arg("-q")
.arg("--no-site-file")
.arg("--no-splash")
.arg("--batch")
.arg("--insert")
.arg(file_path.as_ref().as_os_str())
.arg("--eval")
.arg(elisp_script);
let out = proc.output()?;
out.status.exit_ok()?;
let org_sexp = out.stderr;
Ok(String::from_utf8(org_sexp)?)
}

View File

@ -1,6 +1,9 @@
#![feature(round_char_boundary)] #![feature(round_char_boundary)]
#![feature(exit_status_error)]
use compare::emacs_parse_org_document;
mod compare; mod compare;
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
emacs_parse_org_document("./org_mode_samples/footnote_definition/simple.org")?;
Ok(()) Ok(())
} }