Skip to content

Instantly share code, notes, and snippets.

@nobrowser
Created August 26, 2015 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobrowser/dbeb2df55bdcbe93d39f to your computer and use it in GitHub Desktop.
Save nobrowser/dbeb2df55bdcbe93d39f to your computer and use it in GitHub Desktop.
In emacs, run a synchronous subprocess, piping the region to it, and returning its output as a string.
(defun itz-program-output-on-region (start end prog &rest args)
"Run PROG with ARGS synchronously, passing it text between START END.
Return its output as a string."
(with-output-to-string
(let ((exit-status
(apply 'call-process-region
start end prog nil standard-output nil args)))
(cond
((stringp exit-status)
(error "Program killed: %s" exit-status))
((/= 0 exit-status)
(error "Program failed: %d" exit-status))
(t nil)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment