unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Austin Clements <amdragon@MIT.EDU>
To: Tomi Ollila <tomi.ollila@iki.fi>, notmuch@notmuchmail.org
Subject: Re: [PATCH v2 2/5] emacs: Utilities to manage asynchronous notmuch processes
Date: Fri, 31 May 2013 19:41:30 -0400	[thread overview]
Message-ID: <87zjvahg45.fsf@awakening.csail.mit.edu> (raw)
In-Reply-To: <m24ndjas8o.fsf@guru.guru-group.fi>

On Fri, 31 May 2013, Tomi Ollila <tomi.ollila@iki.fi> wrote:
> Austin Clements <amdragon@MIT.EDU> 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))
>> +

  reply	other threads:[~2013-05-31 23:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-30 17:13 [PATCH v2 0/5] Make Emacs search use sexp format Austin Clements
2013-05-30 17:13 ` [PATCH v2 1/5] test: Remove extraneous Emacs error handling test Austin Clements
2013-05-30 17:13 ` [PATCH v2 2/5] emacs: Utilities to manage asynchronous notmuch processes Austin Clements
2013-05-31 19:01   ` Tomi Ollila
2013-05-31 23:41     ` Austin Clements [this message]
2013-05-30 17:13 ` [PATCH v2 3/5] emacs: Use async process helper for search Austin Clements
2013-05-30 17:13 ` [PATCH v2 4/5] emacs: Streaming S-expression parser Austin Clements
2013-05-30 17:13 ` [PATCH v2 5/5] emacs: Use streaming S-expr parser for search Austin Clements
2013-05-31 22:38 ` [PATCH v2 0/5] Make Emacs search use sexp format Mark Walters
2013-05-31 23:43   ` Austin Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zjvahg45.fsf@awakening.csail.mit.edu \
    --to=amdragon@mit.edu \
    --cc=notmuch@notmuchmail.org \
    --cc=tomi.ollila@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).