From: Austin Clements Date: Fri, 31 May 2013 23:41:30 +0000 (+2000) Subject: Re: [PATCH v2 2/5] emacs: Utilities to manage asynchronous notmuch processes X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8866840a1b7987bb2b77b8ddf892ae558c560038;p=notmuch-archives.git Re: [PATCH v2 2/5] emacs: Utilities to manage asynchronous notmuch processes --- diff --git a/24/8363058ba6861b7e949314b4939894baa0394d b/24/8363058ba6861b7e949314b4939894baa0394d new file mode 100644 index 000000000..6ff25aaa6 --- /dev/null +++ b/24/8363058ba6861b7e949314b4939894baa0394d @@ -0,0 +1,145 @@ +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 16556431FDC + for ; Fri, 31 May 2013 16:41:42 -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 TvA6BpPkSq3m for ; + Fri, 31 May 2013 16:41:34 -0700 (PDT) +Received: from dmz-mailsec-scanner-7.mit.edu (dmz-mailsec-scanner-7.mit.edu + [18.7.68.36]) + by olra.theworths.org (Postfix) with ESMTP id 5DB2D431FBD + for ; Fri, 31 May 2013 16:41:34 -0700 (PDT) +X-AuditID: 12074424-b7f8c6d0000028c4-f7-51a9352db106 +Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) + by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP + id 61.C0.10436.D2539A15; Fri, 31 May 2013 19:41:33 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id r4VNfW3G004129; + Fri, 31 May 2013 19:41:33 -0400 +Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r4VNfVhc004485 + (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); + Fri, 31 May 2013 19:41:32 -0400 +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80) + (envelope-from ) + id 1UiYws-0005Ve-VV; Fri, 31 May 2013 19:41:31 -0400 +From: Austin Clements +To: Tomi Ollila , notmuch@notmuchmail.org +Subject: Re: [PATCH v2 2/5] emacs: Utilities to manage asynchronous notmuch + processes +In-Reply-To: +References: <1369934016-22308-1-git-send-email-amdragon@mit.edu> + <1369934016-22308-3-git-send-email-amdragon@mit.edu> + +User-Agent: Notmuch/0.15.2+133~gf9ff9fd (http://notmuchmail.org) Emacs/23.4.1 + (i486-pc-linux-gnu) +Date: Fri, 31 May 2013 19:41:30 -0400 +Message-ID: <87zjvahg45.fsf@awakening.csail.mit.edu> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFnrAIsWRmVeSWpSXmKPExsUixCmqrKtrujLQ4OdHG4vrN2cyW7xZOY/V + gcnj8NeFLB7PVt1iDmCK4rJJSc3JLEst0rdL4Mq41p5WcESkYuqMTywNjMsFuhg5OSQETCTu + HNrPAmGLSVy4t54NxBYS2Mco0b5JrouRC8jeyCgxd28jE4RzmkliwaHTUM4SRonWh7PBWtgE + NCS27V/OCGKLCNhKXFlykhXEFhYIlVj96zk7iM0pYCDxcN1FFojmmYwS+9asAXI4OEQFEiUW + 7I4BqWERUJW49Okp2Em8QOd93NnKDmELSpyc+QQsziygJXHj30umCYwCs5CkZiFJLWBkWsUo + m5JbpZubmJlTnJqsW5ycmJeXWqRrrpebWaKXmlK6iREUkOwuKjsYmw8pHWIU4GBU4uE1WLEi + UIg1say4MvcQoyQHk5Iob67JykAhvqT8lMqMxOKM+KLSnNTiQ4wSHMxKIrz5c4DKeVMSK6tS + i/JhUtIcLErivNdTbvoLCaQnlqRmp6YWpBbBZGU4OJQkeDtAhgoWpaanVqRl5pQgpJk4OEGG + 8wANXwFSw1tckJhbnJkOkT/FqCglzjsPJCEAksgozYPrhSWMV4ziQK8I82aCVPEAkw1c9yug + wUxAg59YLwcZXJKIkJJqYIz4Mqci/M7j370hOVkXVzKsmfH176Ipt3K2z55zU+/fFzO1GdoP + 3YVO6qbeV53XWl+jd2v9+vu/ZLI7GNlnsheffBxUtvZh9uxrX8PbvOesqO+5KnHm2vHSqFWn + llzfON9qnXGH/KXw/T9mHTDdf63kCt+UvC05WZPq1/o8XvHuUsIbpwvhH8IClFiKMxINtZiL + ihMBCyqXDfMCAAA= +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: Fri, 31 May 2013 23:41:42 -0000 + +On Fri, 31 May 2013, Tomi Ollila wrote: +> Austin Clements writes: +> +>> This provides a new notmuch-lib utility to start an asynchronous +>> notmuch process that handles redirecting of stderr and checking of the +>> exit status. This is similar to `notmuch-call-notmuch-json', but for +>> asynchronous processes (and it leaves output processing to the +>> caller). +>> --- +>> emacs/notmuch-lib.el | 77 +++++++++++++++++++++++++++++++++++++++++++++++--- +> +> ... +> +>> +(defun notmuch-start-notmuch (name buffer sentinel &rest args) +>> + "Start and return an asynchronous notmuch command. +>> + +>> +This starts and returns an asynchronous process running +>> +`notmuch-command' with ARGS. The exit status is checked via +>> +`notmuch-check-async-exit-status'. Output written to stderr is +>> +redirected and displayed when the process exits (even if the +>> +process exits successfully). NAME and BUFFER are the same as in +>> +`start-process'. SENTINEL is a process sentinel function to call +>> +when the process exits, or nil for none. The caller must *not* +>> +invoke `set-process-sentinel' directly on the returned process, +>> +as that will interfere with the handling of stderr and the exit +>> +status." +>> + +>> + ;; There is no way (as of Emacs 24.3) to capture stdout and stderr +>> + ;; separately for asynchronous processes, or even to redirect stderr +>> + ;; to a file, so we use a trivial shell wrapper to send stderr to a +>> + ;; temporary file and clean things up in the sentinel. +>> + (let* ((err-file (make-temp-file "nmerr")) +>> + ;; Use a pipe +>> + (process-connection-type nil) +>> + ;; Find notmuch using Emacs' `exec-path' +>> + (command (or (executable-find notmuch-command) +>> + (error "command not found: %s" notmuch-command))) +>> + (proc (apply #'start-process name buffer +>> + "sh" "-c" +> +> I'd suggest "/bin/sh". + +Done. + +>> + "ERR=\"$1\"; shift; exec \"$0\" \"$@\" 2>\"$ERR\"" +> +> An alternative to the above ... +> +> "exec 2>\"$1\"; shift; exec \"$0\" \"$@\"" +> +> ... which one is better is a matter of quar^H^H^H^H^H taste :D + +I like it. Done. + +> Everything else in this patch series looks good to me (as far as +> I understood -- test passed and works as expected). +> +> +> Tomi +> +>> + command err-file args))) +>> + (process-put proc 'err-file err-file) +>> + (process-put proc 'sub-sentinel sentinel) +>> + (process-put proc 'real-command (cons notmuch-command args)) +>> + (set-process-sentinel proc #'notmuch-start-notmuch-sentinel) +>> + proc)) +>> +