From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: mail@xuchunyang.me Newsgroups: gmane.emacs.help Subject: Re: How to post-process the buffer populated by the async `start-process' Date: Sat, 12 Jan 2019 14:32:09 +0800 Message-ID: <4191547274729@myt1-8f46c049cd43.qloud-c.yandex.net> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1547274639 21572 195.159.176.226 (12 Jan 2019 06:30:39 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 12 Jan 2019 06:30:39 +0000 (UTC) To: Kaushal Modi , Help Gnu Emacs mailing list Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jan 12 07:30:35 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1giCoU-0005Ui-Sy for geh-help-gnu-emacs@m.gmane.org; Sat, 12 Jan 2019 07:30:35 +0100 Original-Received: from localhost ([127.0.0.1]:48895 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1giCqb-0000a1-Q3 for geh-help-gnu-emacs@m.gmane.org; Sat, 12 Jan 2019 01:32:45 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:59003) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1giCq7-0000Zt-4J for help-gnu-emacs@gnu.org; Sat, 12 Jan 2019 01:32:15 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1giCq6-0006Wv-44 for help-gnu-emacs@gnu.org; Sat, 12 Jan 2019 01:32:15 -0500 Original-Received: from forward500o.mail.yandex.net ([37.140.190.195]:53151) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1giCq5-0006Vg-S3 for help-gnu-emacs@gnu.org; Sat, 12 Jan 2019 01:32:14 -0500 Original-Received: from mxback20j.mail.yandex.net (mxback20j.mail.yandex.net [IPv6:2a02:6b8:0:1619::114]) by forward500o.mail.yandex.net (Yandex) with ESMTP id 0829460276; Sat, 12 Jan 2019 09:32:10 +0300 (MSK) Original-Received: from localhost (localhost [::1]) by mxback20j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id um87dScIje-W94q3r8B; Sat, 12 Jan 2019 09:32:09 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xuchunyang.me; s=mail; t=1547274729; bh=ZsTEpTZ5G1pIxde4OPCyQoT9XvTK0tsCPLHxItm/8Pc=; h=From:To:In-Reply-To:References:Subject:Date:Message-Id; b=az2zKwXNNi//haWPbBEJc55qztBOyXoYRmb/4Xx7HB7FuyYuTGFrhcFcI0iWaiC1G xjHFyIaWR1Mt647ngW+HuG68yAh06yqZaMQw2uCijdXJz07ZUjdZEuCN1l/MC80McI NoFO8CMLH8VvcijODm+rjGu9vxsoUXxpcbd5HdCM= Authentication-Results: mxback20j.mail.yandex.net; dkim=pass header.i=@xuchunyang.me Original-Received: by myt1-8f46c049cd43.qloud-c.yandex.net with HTTP; Sat, 12 Jan 2019 09:32:09 +0300 In-Reply-To: X-Mailer: Yamail [ http://yandex.ru ] 5.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 37.140.190.195 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.help:119109 Archived-At: 12.01.2019, 11:36, "Kaushal Modi" : > Hello, > > I am using a package which starts a command in a subprocess (async) usi= ng > `start-process' and the results of the command are dumped in the buffer= arg > passed to subprocess. > > But the stdout sent to the buffer has ANSI escape codes. > > If I manually visit that buffer, and eval (ansi-color-apply-on-region-i= nt > (point-min) (point-max)), I can see the ANSI color codes nicely rendere= d. > > But I cannot figure out how to do that *when* the start-process initiat= ed > command ends *in* the specified stdout buffer. > > If I do: > > (apply #'start-process ..) > (with-current-buffer buffer > =C2=A0=C2=A0(ansi-color-apply-on-region-int (point-min) (point-max)) ) > > .. it of course doesn't work because the a-c-a-o-r-i is getting called > before start-process initiated command ends. > > So I somehow need to define a hook that can get triggered when that com= mand > ends, and then call the a-c-a-o-r-i function. But I don't know how. Have you tried (info "(elisp) Sentinels")? The info already provides a ni= ce example, here is another example: (set-process-sentinel (start-process "sleep" "*sleep*" "sleep" "3") (lambda (_process event) (when (string=3D event "finished\n") (message "TODO Do something")))) > -- > Kaushal Modi