2023-04-10 14:28:40 -04:00
|
|
|
use std::path::Path;
|
|
|
|
use std::process::Command;
|
|
|
|
|
2023-04-11 16:28:56 -04:00
|
|
|
pub fn emacs_parse_org_document<'a, C>(file_path: C) -> Result<String, Box<dyn std::error::Error>>
|
2023-04-10 14:28:40 -04:00
|
|
|
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)?)
|
|
|
|
}
|