Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id B020D429E53 for ; Thu, 24 Oct 2013 08:19:28 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nKhQWC4vx+2F for ; Thu, 24 Oct 2013 08:19:23 -0700 (PDT) Received: from dmz-mailsec-scanner-1.mit.edu (dmz-mailsec-scanner-1.mit.edu [18.9.25.12]) by olra.theworths.org (Postfix) with ESMTP id 74D02429E41 for ; Thu, 24 Oct 2013 08:19:18 -0700 (PDT) X-AuditID: 1209190c-b7fd38e0000009aa-24-52693a751991 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP id C0.5C.02474.67A39625; Thu, 24 Oct 2013 11:19:18 -0400 (EDT) Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id r9OFJFZ8030432; Thu, 24 Oct 2013 11:19:15 -0400 Received: from drake.dyndns.org (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [216.15.114.40]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r9OFJCh0012917 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Thu, 24 Oct 2013 11:19:14 -0400 Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1VZMgq-0006du-Pu; Thu, 24 Oct 2013 11:19:12 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v2 06/11] emacs: Support passing input via `notmuch-call-notmuch-*' Date: Thu, 24 Oct 2013 11:19:06 -0400 Message-Id: <1382627951-25252-7-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.8.4.rc3 In-Reply-To: <1382627951-25252-1-git-send-email-amdragon@mit.edu> References: <1382627951-25252-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrKIsWRmVeSWpSXmKPExsUixCmqrVtmlRlksKKJ2aJpurPF6rk8Ftdv zmR2YPbYOesuu8et+6/ZPZ6tusUcwBzFZZOSmpNZllqkb5fAlXFs3UrWggUSFW/7t7A1MN4U 7mLk4JAQMJF42RXbxcgJZIpJXLi3nq2LkYtDSGAfo8TXpxsZIZyNjBJLp09hhnDuMEmcmb2X BcKZC5T5f50VpJ9NQENi2/7ljCC2iIC0xM67s8HizALREkcuz2ADsYUFgiUerPrPDGKzCKhK /Nt1hgnE5hVwkNhxayo7xB1KEgtPbQPr5RRwlPj5+hrYTCGgml+/z7BMYORfwMiwilE2JbdK NzcxM6c4NVm3ODkxLy+1SNdQLzezRC81pXQTIzi0JHl2ML45qHSIUYCDUYmHV+NDepAQa2JZ cWXuIUZJDiYlUd57pplBQnxJ+SmVGYnFGfFFpTmpxYcYJTiYlUR4p+kB5XhTEiurUovyYVLS HCxK4rw3OeyDhATSE0tSs1NTC1KLYLIyHBxKErydlkCNgkWp6akVaZk5JQhpJg5OkOE8QMOX gtTwFhck5hZnpkPkTzEqSonzzgNJCIAkMkrz4Hphsf+KURzoFWHecpAqHmDagOt+BTSYCWjw lCVpIINLEhFSUg2MLY9dyibl8WZu+vA4LOgE5/TUUJO6EsNrS1Ia9bnbykVzOLzWGVn4yBRN 7PmQkbTumCnTrojVhUztL597Z8zLrJhgUXy4Mzo09oqC05mVcrtCFSsyzh9mO5V4XvNZvnbT PUkBPmaFjyqXGssOF9qYl3/2Pdtitegxf53gJzbJy8e+9z5TuKjEUpyRaKjFXFScCACYcusw 2AIAAA== X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Oct 2013 15:19:29 -0000 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. --- emacs/notmuch-lib.el | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 4e0604e..22156f1 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -534,28 +534,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)) -- 1.8.4.rc3