Add make-process-fn function

This commit is contained in:
Jeremy Dormitzer 2019-04-23 10:25:46 -04:00
parent 0dc7323f17
commit 6023baf8b6

View File

@ -272,6 +272,23 @@ Some utilities for calling out to other processes.
(kill-buffer buf)))))
#+END_SRC
A function to call a process passing some string as stdin and returning the process output:
#+BEGIN_SRC emacs-lisp
(defun make-process-fn (program &rest args)
"Returns a function that, when called, call `program` with arguments `args`,
passing the function argument as stdin"
(lambda (&optional input)
(let ((infile
(when input
(let ((tmp-file (make-temp-file "make-process-input")))
(with-temp-file tmp-file
(insert input)
tmp-file)))))
(with-temp-buffer
(apply #'call-process program infile t nil args)
(buffer-substring-no-properties (point-min) (point-max))))))
#+END_SRC
* Customization File
I don't want anything to write to my init.el, so save customizations in a separate file:
#+BEGIN_SRC emacs-lisp