Re: [PATCH 1/2] Add Google Inc. to AUTHORS as a contributor.
[notmuch-archives.git] / 74 / 305c5b12592743a34823b9f971f71fd8054ac9
1 Return-Path: <tomi.ollila@iki.fi>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id C2373431FC3\r
6         for <notmuch@notmuchmail.org>; Fri, 31 May 2013 12:01:38 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id gEkoRqbrF3uz for <notmuch@notmuchmail.org>;\r
16         Fri, 31 May 2013 12:01:32 -0700 (PDT)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id 82573431FBD\r
19         for <notmuch@notmuchmail.org>; Fri, 31 May 2013 12:01:32 -0700 (PDT)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id 2E935100093;\r
22         Fri, 31 May 2013 22:01:28 +0300 (EEST)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
25 Subject: Re: [PATCH v2 2/5] emacs: Utilities to manage asynchronous notmuch\r
26         processes\r
27 In-Reply-To: <1369934016-22308-3-git-send-email-amdragon@mit.edu>\r
28 References: <1369934016-22308-1-git-send-email-amdragon@mit.edu>\r
29         <1369934016-22308-3-git-send-email-amdragon@mit.edu>\r
30 User-Agent: Notmuch/0.15.2+115~g12cf6af (http://notmuchmail.org) Emacs/24.3.1\r
31         (x86_64-unknown-linux-gnu)\r
32 Date: Fri, 31 May 2013 22:01:27 +0300\r
33 Message-ID: <m24ndjas8o.fsf@guru.guru-group.fi>\r
34 MIME-Version: 1.0\r
35 Content-Type: text/plain\r
36 X-BeenThere: notmuch@notmuchmail.org\r
37 X-Mailman-Version: 2.1.13\r
38 Precedence: list\r
39 List-Id: "Use and development of the notmuch mail system."\r
40         <notmuch.notmuchmail.org>\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
42         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
44 List-Post: <mailto:notmuch@notmuchmail.org>\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
48 X-List-Received-Date: Fri, 31 May 2013 19:01:38 -0000\r
49 \r
50 Austin Clements <amdragon@MIT.EDU> writes:\r
51 \r
52 > This provides a new notmuch-lib utility to start an asynchronous\r
53 > notmuch process that handles redirecting of stderr and checking of the\r
54 > exit status.  This is similar to `notmuch-call-notmuch-json', but for\r
55 > asynchronous processes (and it leaves output processing to the\r
56 > caller).\r
57 > ---\r
58 >  emacs/notmuch-lib.el |   77 +++++++++++++++++++++++++++++++++++++++++++++++---\r
59 \r
60 ...\r
61 \r
62 > +(defun notmuch-start-notmuch (name buffer sentinel &rest args)\r
63 > +  "Start and return an asynchronous notmuch command.\r
64 > +\r
65 > +This starts and returns an asynchronous process running\r
66 > +`notmuch-command' with ARGS.  The exit status is checked via\r
67 > +`notmuch-check-async-exit-status'.  Output written to stderr is\r
68 > +redirected and displayed when the process exits (even if the\r
69 > +process exits successfully).  NAME and BUFFER are the same as in\r
70 > +`start-process'.  SENTINEL is a process sentinel function to call\r
71 > +when the process exits, or nil for none.  The caller must *not*\r
72 > +invoke `set-process-sentinel' directly on the returned process,\r
73 > +as that will interfere with the handling of stderr and the exit\r
74 > +status."\r
75 > +\r
76 > +  ;; There is no way (as of Emacs 24.3) to capture stdout and stderr\r
77 > +  ;; separately for asynchronous processes, or even to redirect stderr\r
78 > +  ;; to a file, so we use a trivial shell wrapper to send stderr to a\r
79 > +  ;; temporary file and clean things up in the sentinel.\r
80 > +  (let* ((err-file (make-temp-file "nmerr"))\r
81 > +      ;; Use a pipe\r
82 > +      (process-connection-type nil)\r
83 > +      ;; Find notmuch using Emacs' `exec-path'\r
84 > +      (command (or (executable-find notmuch-command)\r
85 > +                   (error "command not found: %s" notmuch-command)))\r
86 > +      (proc (apply #'start-process name buffer\r
87 > +                   "sh" "-c"\r
88 \r
89 I'd suggest "/bin/sh".\r
90 \r
91 \r
92 > +                   "ERR=\"$1\"; shift; exec \"$0\" \"$@\" 2>\"$ERR\""\r
93 \r
94 An alternative to the above ...\r
95 \r
96 "exec 2>\"$1\"; shift; exec \"$0\" \"$@\""\r
97 \r
98 ... which one is better is a matter of quar^H^H^H^H^H taste :D\r
99 \r
100 Everything else in this patch series looks good to me (as far as\r
101 I understood -- test passed and works as expected).\r
102 \r
103 \r
104 Tomi\r
105 \r
106 > +                   command err-file args)))\r
107 > +    (process-put proc 'err-file err-file)\r
108 > +    (process-put proc 'sub-sentinel sentinel)\r
109 > +    (process-put proc 'real-command (cons notmuch-command args))\r
110 > +    (set-process-sentinel proc #'notmuch-start-notmuch-sentinel)\r
111 > +    proc))\r
112 > +\r