From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.emacs.help Subject: Re: start-process and set-process-filter sequence Date: Thu, 14 Apr 2011 14:02:51 +0200 Message-ID: <87ipuh59ck.fsf@ambire.localdomain> References: <21glbp094jfn.fsf@gmail.com> <878vvdpgbo.fsf@gmail.com> <21gl39ll44z8.fsf@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1302784317 30511 80.91.229.12 (14 Apr 2011 12:31:57 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 14 Apr 2011 12:31:57 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: William Xu Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Apr 14 14:31:53 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QALiD-0007DJ-6l for geh-help-gnu-emacs@m.gmane.org; Thu, 14 Apr 2011 14:31:53 +0200 Original-Received: from localhost ([::1]:44374 helo=lists2.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QALiC-0007Y6-Or for geh-help-gnu-emacs@m.gmane.org; Thu, 14 Apr 2011 08:31:52 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:60999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QALi8-0007Y0-3G for help-gnu-emacs@gnu.org; Thu, 14 Apr 2011 08:31:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QALi7-0007Xm-5l for help-gnu-emacs@gnu.org; Thu, 14 Apr 2011 08:31:48 -0400 Original-Received: from smtp205.alice.it ([82.57.200.101]:39717) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QALi6-0007Xi-TJ for help-gnu-emacs@gnu.org; Thu, 14 Apr 2011 08:31:47 -0400 Original-Received: from ambire.localdomain (95.236.25.103) by smtp205.alice.it (8.5.124.08) id 4D0D00380A1AD777; Thu, 14 Apr 2011 14:03:26 +0200 Original-Received: from ttn by ambire.localdomain with local (Exim 4.69) (envelope-from ) id 1QALG7-0005VM-J4; Thu, 14 Apr 2011 14:02:51 +0200 In-Reply-To: <21gl39ll44z8.fsf@gmail.com> (William Xu's message of "Thu, 14 Apr 2011 16:22:35 +0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 82.57.200.101 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:80792 Archived-At: () William Xu () Thu, 14 Apr 2011 16:22:35 +0800 if you try: (prog1 (start-process "ls" "ls" "ls") (read-string "Mood: ") (set-process-filter (get-process "ls") 'foo) (setq a nil)) There will still be a similar problem.=20=20 Process output is distributed to filters when Emacs has nothing else to do, such as when pausing for interaction (=E2=80=98read-string=E2=80=99 = et al). (You can also explicitly request it via =E2=80=98accept-process-output=E2= =80=99 but that is not germane.) So the best strategy is to not allow such pauses in the first place. E.g., you could add an abstraction =E2=80=98start-filtered-process=E2=80=99= and make sure you use =E2=80=98start-filtered-process=E2=80=99 everywhere you'd norm= ally use a naked =E2=80=98start-process=E2=80=99. (defun start-filtered-process (filter &rest etc) "Like `start-process' with ETC, but associate FILTER as well. Return the newly created process." (let ((proc (apply 'start-process etc))) ;; Note to programmer: Do NOT tickle Emacs I/O-wise, here. ;; [Insert ref to help-gnu-emacs thread, here.] (set-process-filter proc filter) proc))