From 65c5abb03aad31fa30e1469bf76a4e52986a67d3 Mon Sep 17 00:00:00 2001 From: Tomi Ollila Date: Fri, 31 May 2013 22:01:27 +0300 Subject: [PATCH] Re: [PATCH v2 2/5] emacs: Utilities to manage asynchronous notmuch processes --- 74/305c5b12592743a34823b9f971f71fd8054ac9 | 112 ++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 74/305c5b12592743a34823b9f971f71fd8054ac9 diff --git a/74/305c5b12592743a34823b9f971f71fd8054ac9 b/74/305c5b12592743a34823b9f971f71fd8054ac9 new file mode 100644 index 000000000..e1a2c3fc3 --- /dev/null +++ b/74/305c5b12592743a34823b9f971f71fd8054ac9 @@ -0,0 +1,112 @@ +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 C2373431FC3 + for ; Fri, 31 May 2013 12:01:38 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + 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 gEkoRqbrF3uz for ; + Fri, 31 May 2013 12:01:32 -0700 (PDT) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id 82573431FBD + for ; Fri, 31 May 2013 12:01:32 -0700 (PDT) +Received: from guru.guru-group.fi (localhost [IPv6:::1]) + by guru.guru-group.fi (Postfix) with ESMTP id 2E935100093; + Fri, 31 May 2013 22:01:28 +0300 (EEST) +From: Tomi Ollila +To: Austin Clements , notmuch@notmuchmail.org +Subject: Re: [PATCH v2 2/5] emacs: Utilities to manage asynchronous notmuch + processes +In-Reply-To: <1369934016-22308-3-git-send-email-amdragon@mit.edu> +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+115~g12cf6af (http://notmuchmail.org) Emacs/24.3.1 + (x86_64-unknown-linux-gnu) +Date: Fri, 31 May 2013 22:01:27 +0300 +Message-ID: +MIME-Version: 1.0 +Content-Type: text/plain +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 19:01:38 -0000 + +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". + + +> + "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 + +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)) +> + -- 2.26.2