aboutsummaryrefslogtreecommitdiffhomepage
path: root/emacs
diff options
context:
space:
mode:
authorGravatar Austin Clements <amdragon@MIT.EDU>2013-10-24 11:19:06 -0400
committerGravatar David Bremner <david@tethera.net>2013-11-08 20:28:44 -0400
commit662e097984780165e57c7fa1f0ddf450dfeab83d (patch)
treebc008f30390951012598294ed5153cbe1e4b819e /emacs
parentddc44ae0d02c7f92640b5e560fca5fddbd7b6c98 (diff)
emacs: Support passing input via `notmuch-call-notmuch-*'
This adds support for passing a string to write to notmuch's stdin to `notmuch-call-notmuch-process' and `notmuch-call-notmuch-sexp'. Since this makes both interfaces a little more complicated, it also unifies their documentation better.
Diffstat (limited to 'emacs')
-rw-r--r--emacs/notmuch-lib.el39
1 files changed, 33 insertions, 6 deletions
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index b8d0198d..17040ed8 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -628,28 +628,55 @@ You may need to restart Emacs or upgrade your notmuch package."))
;; `notmuch-logged-error' does not return.
))))
+(defun notmuch-call-notmuch--helper (destination args)
+ "Helper for synchronous notmuch invocation commands.
+
+This wraps `call-process'. DESTINATION has the same meaning as
+for `call-process'. ARGS is as described for
+`notmuch-call-notmuch-process'."
+
+ (let (stdin-string)
+ (while (keywordp (car args))
+ (case (car args)
+ (:stdin-string (setq stdin-string (cadr args)
+ args (cddr args)))
+ (otherwise
+ (error "Unknown keyword argument: %s" (car args)))))
+ (if (null stdin-string)
+ (apply #'call-process notmuch-command nil destination nil args)
+ (insert stdin-string)
+ (apply #'call-process-region (point-min) (point-max)
+ notmuch-command t destination nil args))))
+
(defun notmuch-call-notmuch-process (&rest args)
- "Synchronously invoke \"notmuch\" with the given list of arguments.
+ "Synchronously invoke `notmuch-command' with ARGS.
+
+The caller may provide keyword arguments before ARGS. Currently
+supported keyword arguments are:
+
+ :stdin-string STRING - Write STRING to stdin
If notmuch exits with a non-zero status, output from the process
will appear in a buffer named \"*Notmuch errors*\" and an error
will be signaled."
(with-temp-buffer
- (let ((status (apply #'call-process notmuch-command nil t nil args)))
+ (let ((status (notmuch-call-notmuch--helper t args)))
(notmuch-check-exit-status status (cons notmuch-command args)
(buffer-string)))))
(defun notmuch-call-notmuch-sexp (&rest args)
"Invoke `notmuch-command' with ARGS and return the parsed S-exp output.
-If notmuch exits with a non-zero status, this will pop up a
-buffer containing notmuch's output and signal an error."
+This is equivalent to `notmuch-call-notmuch-process', but parses
+notmuch's output as an S-expression and returns the parsed value.
+Like `notmuch-call-notmuch-process', if notmuch exits with a
+non-zero status, this will report its output and signal an
+error."
(with-temp-buffer
(let ((err-file (make-temp-file "nmerr")))
(unwind-protect
- (let ((status (apply #'call-process
- notmuch-command nil (list t err-file) nil args)))
+ (let ((status (notmuch-call-notmuch--helper (list t err-file) args)))
(notmuch-check-exit-status status (cons notmuch-command args)
(buffer-string) err-file)
(goto-char (point-min))