diff --git a/Cargo.toml b/Cargo.toml index 540389a..7041f50 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ name = "toy" version = "0.1.0" edition = "2021" license = "0BSD" +default-run = "toy" [[bin]] name = "toy" diff --git a/src/compare/mod.rs b/src/compare/mod.rs index 8b13789..e694bcb 100644 --- a/src/compare/mod.rs +++ b/src/compare/mod.rs @@ -1 +1,2 @@ - +mod parse; +pub use parse::emacs_parse_org_document; diff --git a/src/compare/parse.rs b/src/compare/parse.rs new file mode 100644 index 0000000..79633a9 --- /dev/null +++ b/src/compare/parse.rs @@ -0,0 +1,26 @@ +use std::path::Path; +use std::process::Command; + +pub fn emacs_parse_org_document<'a, C>(file_path: C) -> Result> +where + C: AsRef, +{ + 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)?) +} diff --git a/src/org_compare.rs b/src/org_compare.rs index 96e940e..7fd6685 100644 --- a/src/org_compare.rs +++ b/src/org_compare.rs @@ -1,6 +1,9 @@ #![feature(round_char_boundary)] +#![feature(exit_status_error)] +use compare::emacs_parse_org_document; mod compare; fn main() -> Result<(), Box> { + emacs_parse_org_document("./org_mode_samples/footnote_definition/simple.org")?; Ok(()) }