From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id UGgiKhPOv2WFFAEA62LTzQ:P1 (envelope-from ) for ; Sun, 04 Feb 2024 18:49:07 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id UGgiKhPOv2WFFAEA62LTzQ (envelope-from ) for ; Sun, 04 Feb 2024 18:49:07 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=excalamus.com header.s=zmail header.b=I9FHGI7S; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none; arc=pass ("zohomail.com:s=zohoarc:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1707068947; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=R9HOiUnaEuy+N1gVNGkFDozIzUH+G64gsH5gTwD8xWo=; b=pFyWx6PLXFp94j7OR7DoDkY2aMQ3wJyymYA6xlQV/wkvjieKL4E61vFJg4jyXfjpljQqww 99LP6aTnTSqFsWitrdirXn7m+vIbrtUE5C3r+Sct21jSI5fYL9OLGuMkdCWFmNpFfjdcZ5 ZeX6gh8z6kx53NgQlMW6cMYctEFI4+5dksmUtE+jil/zSzFDncWswKPmuhLnY4RIRHXa2P eodyqlhoDTttjYc0NMbMSL7vtzgHuK3HMXPNAn5h0xE8A6j9K6IN+BCZE5NUHTb5JTJHkS hjPgkR/CiKwDG7JyDo+RtK0IC0MxBTMKdWC0tsFGuYtSGuQvxaeQrmD3fHXENQ== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=excalamus.com header.s=zmail header.b=I9FHGI7S; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none; arc=pass ("zohomail.com:s=zohoarc:i=1") ARC-Seal: i=2; s=key1; d=yhetil.org; t=1707068947; a=rsa-sha256; cv=pass; b=MpE789hTn+nQZSmykD+9lJO/nOrco28APWeJcH60qVvw6I52bI0zMWLTYcP2tBMkR6SUR0 0ya4PE7Oh1asQaDdAGX4g2BSsH7EbQalq3ZArjt7bQzdd62Z3hYdkDnGXgyKwStW/KjAdg Ng+N7bhRd/mlqOiByn88SxXh3CXm1p8WdBu/MFnuaZWO4iDt4b5hUUO1gIFwR6cUzY8csu b0QJe/sOk1mjynzbt4Wdpi44tvDKaih0eYwoPNJjlLIxs8b35CrcOFr8x1eXvrlXJ/cheb nxRcl5NT+EkFbOaOwC5gEvsOX/i3RAk0TZx2qLwF4V+AA6I6HLRaXrEOAwACZQ== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6815A695F9 for ; Sun, 4 Feb 2024 18:49:07 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rWgbN-0003oI-Ku; Sun, 04 Feb 2024 12:48:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rWgbL-0003o6-Sy for emacs-orgmode@gnu.org; Sun, 04 Feb 2024 12:48:19 -0500 Received: from sender4-op-o10.zoho.com ([136.143.188.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rWgbJ-0001Kv-92 for emacs-orgmode@gnu.org; Sun, 04 Feb 2024 12:48:19 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1707068891; cv=none; d=zohomail.com; s=zohoarc; b=XD0yEc0HuMmGkZG2Gqub0LlFIuwa69i2PPiA0nxXqM8jKveELx7rCmRdzVoBIJYpBUyaSz8WXyODcNrr+Ujw4OHCosLHtPHYmYG0T7rNWJEvUF2TNQfyp5OB0+qcjDEsJxHqCodGN8+ymtnvL70phiCWzETsrHaJ1Csm/A1vbSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707068891; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=R9HOiUnaEuy+N1gVNGkFDozIzUH+G64gsH5gTwD8xWo=; b=QXjMSss6EnJiJH12oPxHuAVtaBx9QUijsvv6yfbOTgHO45wsyq/IIXYQqrc+48fKcJsRBpxDT+ywazxAfiURdW8O+ZpUX2Fittt5L0w+wTkjdi6PoeuoC+ghQx37bQH/l8WZKtqWj5iRV+izFDAXhTCCatKS4FZ77ZFUoqQh+a4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=excalamus.com; spf=pass smtp.mailfrom=matt@excalamus.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1707068891; s=zmail; d=excalamus.com; i=matt@excalamus.com; h=Date:Date:From:From:To:To:Message-ID:In-Reply-To:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To:Cc; bh=R9HOiUnaEuy+N1gVNGkFDozIzUH+G64gsH5gTwD8xWo=; b=I9FHGI7SxchTZiTC3dPpM/gFAiPK2FihZNSpxSNFV3yLooFuFr6V62g8AlYg3m94 MHn3Q/WYvszWq+5q63xXtLYW0ohhwSoHzaghXb1VZpRfNU++np6fnCb+9l+gwIGDTSF mY2JsKmf1T9S2dzhxZnA1DE0OHRBj1EMdyWH4ps8= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1707068890855801.2823307071922; Sun, 4 Feb 2024 09:48:10 -0800 (PST) Date: Sun, 04 Feb 2024 18:48:10 +0100 From: Matt To: "emacs-orgmode" Message-ID: <18d753c1e8a.cfb3e1921191837.5665565128507976741@excalamus.com> In-Reply-To: Subject: [BUG] Prompt appears in async shell results MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail Received-SPF: pass client-ip=136.143.188.10; envelope-from=matt@excalamus.com; helo=sender4-op-o10.zoho.com 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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -10.71 X-Migadu-Queue-Id: 6815A695F9 X-Spam-Score: -10.71 X-Migadu-Scanner: mx11.migadu.com X-TUID: 7g+SqE8JSC9Q * [BUG] Prompt appears in async shell results ** Minimal reproducible example #+begin_src emacs-lisp (org-babel-do-load-languages 'org-babel-load-languages '((shell . t))) #+end_src #+begin_src sh :results output :session *test* :async t cd /tmp echo "hello world" #+end_src #+RESULTS: : org_babel_sh_prompt> hello world or #+begin_src sh :results output :session *test* :async t # comment # comment #+end_src #+RESULTS: : org_babel_sh_prompt> org_babel_sh_prompt> or #+begin_src sh :results output :session *test* :async t # print message echo \"hello world\" #+end_src #+RESULTS: : org_babel_sh_prompt> "hello world" Interestingly, this returns without the prompt: ,#+begin_src sh :results output :session *test* :async t echo "hello" echo "world" #+end_src #+RESULTS: : hello : world ** Test Here's a test that checks one of the MREs: #+begin_src emacs-lisp (ert-deftest test-ob-shell/session-async-removes-prompt-from-results () "Test that async evaluation removes prompt from results." (let* ((session-name "test-ob-shell/session-async-removes-prompt-from-res= ults") (kill-buffer-query-functions nil) (start-time (current-time)) (wait-time (time-add start-time 3)) uuid-placeholder) (org-test-with-temp-text (concat "#+begin_src sh :session " session-name " :async t # print message echo \"hello world\" ,#+end_src") (setq uuid-placeholder (org-trim (org-babel-execute-src-block))) (catch 'too-long (while (string-match uuid-placeholder (buffer-string)) (progn (sleep-for 0.01) (when (time-less-p wait-time (current-time)) (throw 'too-long (ert-fail "Took too long to get result from = callback")))))) (search-forward "#+results") (beginning-of-line 2) (if (should (string=3D ": hello world\n" (buffer-substring-no-propertie= s (point) (point-max)))) (kill-buffer session-name))))) #+end_src ** Thoughts A quick fix is: #+begin_src diff modified lisp/ob-shell.el @@ -289,7 +289,7 @@ See `org-babel-comint-async-indicator'.") (defun ob-shell-async-chunk-callback (string) "Filter applied to results before insertion. See `org-babel-comint-async-chunk-callback'." - (replace-regexp-in-string comint-prompt-regexp "" string)) + (replace-regexp-in-string org-babel-sh-prompt "" string)) (defun org-babel-sh-evaluate (session body &optional params stdin cmdline) "Pass BODY to the Shell process in BUFFER. #+end_src I'm not sure this is the best way. There are two ways I can think to look at it: how text is passed to the pro= cess and what's done with it afterward. Regarding how text is passed to the process: Blocks without :session and :async are sent via =3Dprocess-file=3D. Blocks= with :session, including those with :async, are inserted into a process bu= ffer and sent to the process with =3Dcomint-send-input=3D. The details dif= fer, but I think the general concept holds: a chunk of text is inserted int= o the process buffer and that chunk is then sent to the process. This is i= n contrast to successive insert-send pairs. AFAICT, there's no major diffe= rence in how text is passed to the process between :session only and :sessi= on with :async. Regarding how process results are handled: AFAIU, =3Dprocess-file=3D interfaces directly with the process and no termi= nal emulation is involved. So, there's no prompt to worry about. Blocks w= ith only :session go through =3Dorg-babel-comint-with-output=3D which filte= rs out the prompt (https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tre= e/lisp/ob-comint.el#n110). Async block results go through =3Dorg-babel-com= int-async-filter=3D which doesn't filter results (https://git.savannah.gnu.= org/cgit/emacs/org-mode.git/tree/lisp/ob-comint.el#n212). It seems to me that we should extract the filter from =3Dorg-babel-comint-w= ith-output=3D and use it in both =3Dorg-babel-comint-with-output=3D and =3D= org-babel-comint-async-filter=3D. =20 Thoughts? -- Matt Trzcinski Emacs Org contributor (ob-shell) Learn more about Org mode at https://orgmode.org Support Org development at=C2=A0https://liberapay.com/org-mode