From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nic Ferrier Newsgroups: gmane.emacs.devel Subject: Re: make-subprocess Date: Fri, 26 Sep 2014 10:38:15 +0100 Message-ID: <87a95md8mw.fsf@ferrier.me.uk> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1411725127 7910 80.91.229.3 (26 Sep 2014 09:52:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 26 Sep 2014 09:52:07 +0000 (UTC) Cc: emacs-devel@gnu.org To: ueno@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Sep 26 11:52:01 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XXSC1-0003zB-4t for ged-emacs-devel@m.gmane.org; Fri, 26 Sep 2014 11:52:01 +0200 Original-Received: from localhost ([::1]:46559 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XXSC0-000421-Pd for ged-emacs-devel@m.gmane.org; Fri, 26 Sep 2014 05:52:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XXRyu-0007iu-E1 for emacs-devel@gnu.org; Fri, 26 Sep 2014 05:38:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XXRyp-0001Ly-E8 for emacs-devel@gnu.org; Fri, 26 Sep 2014 05:38:28 -0400 Original-Received: from static.17.66.46.78.clients.your-server.de ([78.46.66.17]:60549 helo=po1.ferrier.me.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XXRyp-0001LY-8n; Fri, 26 Sep 2014 05:38:23 -0400 Original-Received: from nicferrier-dell-xps (140.35.155.90.in-addr.arpa [90.155.35.140]) by po1.ferrier.me.uk (Postfix) with ESMTPA id 71797AC007A; Fri, 26 Sep 2014 11:53:46 +0200 (CEST) Original-Received: from nicferrier-XPS13-9333 (localhost [127.0.0.1]) by nicferrier-dell-xps (Postfix) with ESMTPS id 0B68B60255; Fri, 26 Sep 2014 10:38:16 +0100 (BST) In-Reply-To: (ueno@gnu.org's message of "Fri, 26 Sep 2014 18:23:04 +0900") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 78.46.66.17 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:174717 Archived-At: ueno@gnu.org writes: > Hello, > > An Elisp program communicating with a subprocess is typically written > as: > > (let* ((process-connection-type nil) > (process (start-process "cat" nil "cat" "/etc/motd"))) > (set-process-filter process #'my-filter) > (set-process-sentinel process #'my-sentinel) > ...) > > It is a bit tricky and error prone. On the other hand, Python and GLib > provide a simple way to spawn and communicate with subprocess: > > http://legacy.python.org/dev/peps/pep-0324/ > https://developer.gnome.org/gio/unstable/GSubprocess.html > > So I would like to propose something similar: > > * Provide a function 'make-subprocess' similar to 'make-network-process' > or 'make-serial-process', which can be used as: > > (make-subprocess :name "cat" :program "cat" :args '("/etc/motd") > :filter #'my-filter :sentinel #'my-sentinel > :coding '(utf-8 . utf-8)) > > * Rewrite 'start-process' as an Elisp wrapper around 'make-subprocess'. > > This also has the following benefits: > > * We could collect stderr output naturally. 'make-subprocess' could > have a keyword, say :error, to prepare a pipe for stderr when spawning > a process. > > * Maybe it could share the same code to handle the standard keywords > (:coding, :filter, :sentinel, etc.) with 'make-network-process' and > 'make-serial-process'. > > What do people think? I'm attaching a patch as POC. I like the idea. I've written several wrappers that do this myself. What about make-network-process? that could be extended to take the same sentinel and filter arguments. I think your function should be called: make-sub-process to fit in with make-network-process. I'd also like to have a: set-default-sentintel function which would make a particular sentinel the default if one was not specified. Maybe make-sub-process and make-network-process could have a default-sentinel variable that they consulted if a sentinel was not specified? Nic