From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.devel Subject: Re: comint-output-filter-functions and multi-line input Date: Tue, 18 Oct 2022 05:28:39 +0000 Message-ID: <87pmepg0oo.fsf@localhost> References: <87y1tgqhmc.fsf@localhost> <87v8oidtzl.fsf@miha-pc> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35163"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: miha@kamnitnik.top Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Oct 18 07:29:56 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1okfAq-0008xr-7x for ged-emacs-devel@m.gmane-mx.org; Tue, 18 Oct 2022 07:29:56 +0200 Original-Received: from localhost ([::1]:49166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okfAo-0007vu-Sl for ged-emacs-devel@m.gmane-mx.org; Tue, 18 Oct 2022 01:29:54 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okf8w-00076E-LZ for emacs-devel@gnu.org; Tue, 18 Oct 2022 01:27:59 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:52531) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okf8u-0000sf-Lq for emacs-devel@gnu.org; Tue, 18 Oct 2022 01:27:58 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 1878D240101 for ; Tue, 18 Oct 2022 07:27:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1666070874; bh=VM7IY7dDnEwiHK/UNexPxhn3IsP0fD/U6W4m0fK5Mc8=; h=From:To:Cc:Subject:Date:From; b=lnAkQVIopRyP9fgxU6YJ6giE81wCB+cB4VVENX4jIosMcx3DBGKQmdKHA/lzJ+Nu2 nk34WOU39iJOyixpLJFTdKgNsIeb8Ph19HsLO5skFh6E9KeuRD1IKIt9i6U9Ffc9H4 EaZeKNUdGt61AEVw1HMsW5XEG2rtzLuTjBvOkVnSxM7W1ovVmIKN6mC3I90qw9ykQ9 1g+PKv7d6WVWLV0t+vz5iwKs5/osMtYgZMIdZGl7WJtppsDzpFiE0vxDyg4gYpY1br MJAazHzD+QHZOPWMMmgbVV0ueba0p6iz6xmGcGVxT9rPCEIav/oT+/ep+fL84zmLj+ N4FYYx+UvgeLw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Ms2SS4tBzz6tqh; Tue, 18 Oct 2022 07:27:51 +0200 (CEST) In-Reply-To: <87v8oidtzl.fsf@miha-pc> Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:298011 Archived-At: miha@kamnitnik.top writes: >> Is it possible to distinguish the actual script output, empty lines in >> the actual script output, and the incomplete prompts? > > You could prepend your multiline command with a dummy > 'echo multiline_starts_here' command have your > 'comint-output-filter-functions' discard output that arrives before > "multiline_starts_here". For context, I am asking because I am trying to figure out how ob-shell works in Org mode. My multiline command can be arbitrary bash script containing multiple single- and multi-line commands. It is hard to figure out which one is which. > Or maybe inject something like 'oldps=$PS2; PS2=""' before the command > and 'PS2=$oldps' after the command. But whether this works could depend > on the shell, some shells might have something like $PS3 or $RPS1, for > example. > You could also accept-process-output after sending each individual line > separately, but this depends on the user not customizing PS2="" in his > bashrc. But will accept-process-output correctly work with PS2=""? Org uses the following black magic to detect that output is actually produced: (org-babel-comint-with-output (session org-babel-sh-eoe-output t body) (dolist (line (append (split-string (org-trim body) "\n") (list org-babel-sh-eoe-indicator))) (insert line) (comint-send-input nil t) (while (save-excursion (goto-char comint-last-input-end) (not (re-search-forward comint-prompt-regexp nil t))) (accept-process-output (get-buffer-process (current-buffer)))))) Note that in addition to accept-process-output, we have to match against comint-prompt-regexp. Not doing so sometimes lead to infinite loops. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at