Clean up code duplication.

This commit is contained in:
Tom Alexander
2023-09-29 15:35:57 -04:00
parent 2012e5a6d5
commit 7a854838ef
2 changed files with 3 additions and 58 deletions

View File

@@ -14,39 +14,7 @@ fn global_settings_elisp(global_settings: &GlobalSettings) -> String {
ret
}
pub fn emacs_parse_anonymous_org_document<C>(
file_contents: C,
) -> Result<String, Box<dyn std::error::Error>>
where
C: AsRef<str>,
{
let escaped_file_contents = escape_elisp_string(file_contents);
let elisp_script = format!(
r#"(progn
(erase-buffer)
(require 'org)
(defun org-table-align () t)
(insert "{escaped_file_contents}")
(org-mode)
(message "%s" (pp-to-string (org-element-parse-buffer)))
)"#,
escaped_file_contents = escaped_file_contents
);
let mut cmd = Command::new("emacs");
let cmd = cmd
.arg("-q")
.arg("--no-site-file")
.arg("--no-splash")
.arg("--batch")
.arg("--eval")
.arg(elisp_script);
let out = cmd.output()?;
out.status.exit_ok()?;
let org_sexp = out.stderr;
Ok(String::from_utf8(org_sexp)?)
}
pub fn emacs_parse_anonymous_org_document_with_settings<C>(
pub(crate) fn emacs_parse_anonymous_org_document<C>(
file_contents: C,
global_settings: &GlobalSettings,
) -> Result<String, Box<dyn std::error::Error>>