From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id oIyfJKMqsWWReQAAqHPOHw:P1 (envelope-from ) for ; Wed, 24 Jan 2024 16:20:03 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id oIyfJKMqsWWReQAAqHPOHw (envelope-from ) for ; Wed, 24 Jan 2024 16:20:03 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b="Rd2Yh1M/"; dmarc=pass (policy=none) header.from=posteo.net; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1706109603; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=NDdOFVDPBOhWbh/bakC4PkVB+O0TeP4HpbLTZjiroJk=; b=sNnQwnu8GJUFduaXN9OEu/rkmCpURXeeaXNMl1/AE0Q/d66ii2yI7UEpuloudgfpZRG03l DTx57JUGxMPC3skks7h470l2Gm6f/OmFIJ7pAi8rUVMxqAc/RZnN8M9t/56CRaZ7A72eMt Wm8hB0cEqLzhxDMHOWgNTqQmDlba6G7idRyTPW+jzmHmmeHBsiRTA8iMGqiwk1a8tPDMVO MpZ+5ydMGHL9QB4oXJhGOC/oCxN1o0Vl5ZBHe1LoVGprsTVy0twrZDHNnom5rAJfKGTlwh Xlzr8q9wMLBF9coB2XuUfJIkABNl1drYLvC6YZ0XfITJ2zPdexLqL139n1VF+Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b="Rd2Yh1M/"; dmarc=pass (policy=none) header.from=posteo.net; 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" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1706109603; a=rsa-sha256; cv=none; b=BnC7rqzNfmcwtswuhM7Wr2vMvC2BWtcg1KVjGRm7DyoZwioqsVJgmuw34aMOKNsLwJkNJU mQZIXBzrjLIGGN41qjuG4kAWh+CPswNJLumtsaiaTSwO3XNJxR8ZLNhm56BJv882Q1Sdih xuuXyEqi7LlwZIQvJZuXKfLv7gjsvbAiqpkZVDbb4HAzgHa5FzO3cdPcqmP6klSgedQQTt d5tDoDsCjrRBgEZmgW/VRrq4SIqQRC+uJ0dmh+Kdnw+V2Lsz++9xl5Dw0eEjLsUuuVSz9R NNdOaXke1w/QxXyhqKyhTUuSiuotnub6G3SOT1vOuLw8X34M4Dk7T2DFjPRZ9Q== 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 3139E12CED for ; Wed, 24 Jan 2024 16:20:03 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rSf2D-0006Vk-GR; Wed, 24 Jan 2024 10:19:25 -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 1rSf2B-0006VX-CR for emacs-orgmode@gnu.org; Wed, 24 Jan 2024 10:19:23 -0500 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rSf28-0004rR-Ul for emacs-orgmode@gnu.org; Wed, 24 Jan 2024 10:19:23 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 0FD8B240101 for ; Wed, 24 Jan 2024 16:19:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1706109559; bh=UWS4QahdfTS1jtyu5RGtKqTk+hRJnqqLPvzcOfTgd0w=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=Rd2Yh1M/LSSYcORa1MWASwEwgoJsoNclvxMRQAHCpXsUaMdXpamuy/gBP8totN09d KSRrDm8J2RIrjRNS8L0G5EjOBajLMpouC1OU08xT8Oe/5Td+CVG53V3Aykn65nuEZH XLMmngsyU8/saCTIMCZ8roXFrk76KBs3EeEM+9xISWwozg3ID0A05a/1BSCdfqpglp e0tK+RapFuF+ygg4YES0CSbjoRVZGPHTkSzyGhEB56BZ0IcNdobDVAJjw/CLvKZ1sc d/TyyD347w5PbKzL0ZiZ3vFVcwpj8A+FyJPSH1LwZyOt8d2iX32Y0fKehFOaCKjyBc +Kfx/yk+Q6aeg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TKng95CKdz9rxD; Wed, 24 Jan 2024 16:19:17 +0100 (CET) From: Ihor Radchenko To: Jack Kamm Cc: Matt , emacs-orgmode Subject: Re: [BUG] conda doesn't work in ob-shell sessions In-Reply-To: <87le8ga8e3.fsf@gmail.com> References: <186283d230a.129f5feb61660123.3289004102603503414@excalamus.com> <87a61j3orj.fsf@gmail.com> <1864701b4b8.e37160d6373275.4308190093579612690@excalamus.com> <87357a2r27.fsf@gmail.com> <1864c676b9f.e1bae673679825.2955884247216895930@excalamus.com> <87ttzn1mai.fsf@gmail.com> <87h6jaj1pk.fsf@localhost> <87sf2q9ubd.fsf@gmail.com> <87o7de9gq5.fsf@gmail.com> <877ck1vass.fsf@localhost> <87le8ga8e3.fsf@gmail.com> Date: Wed, 24 Jan 2024 15:22:47 +0000 Message-ID: <87v87ig3i0.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: -9.89 X-Spam-Score: -9.89 X-Migadu-Queue-Id: 3139E12CED X-Migadu-Scanner: mx12.migadu.com X-TUID: R6HaBIFDU43r --=-=-= Content-Type: text/plain Jack Kamm writes: > Ihor Radchenko writes: > >> What about the attached patch? > > I applied the patch to main, but the behavior was the same as before. What about the attached second version of the patch? --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=v2-0001-lisp-ob-comint.el-Introduce-a-fallback-prompt-reg.patch Content-Transfer-Encoding: quoted-printable >From 0d1331c75ad7a09d88bc5bf38d00488980b6a510 Mon Sep 17 00:00:00 2001 Message-ID: <0d1331c75ad7a09d88bc5bf38d00488980b6a510.1706109720.git.yantar= 92@posteo.net> From: Ihor Radchenko Date: Mon, 22 Jan 2024 12:55:09 +0100 Subject: [PATCH v2] lisp/ob-comint.el: Introduce a fallback prompt regexp * lisp/ob-comint.el (org-babel-comint-prompt-regexp-old): New variable storing the default value of `comint-prompt-regexp' to be used when the prompt set by Org mode changes for some reason. (org-babel-comint-fallback-regexp-threshold): New customization to set the time Org babel waits for comint command to finish until trying fallback prompt regexp. (org-babel-comint--set-fallback-prompt): New internal function that sets the fallback prompt regexp, if there is any available. (org-babel-comint-with-output): (org-babel-comint-wait-for-output): Try fallback prompt regexp when we cannot find comint command end for too long. * lisp/ob-haskell.el (org-babel-interpret-haskell): * lisp/ob-ruby.el (org-babel-ruby-initiate-session): * lisp/ob-shell.el (org-babel-sh-initiate-session): * lisp/ob-clojure.el (ob-clojure-eval-with-inf-clojure): Set `org-babel-comint-prompt-regexp-old' when initializing the inferior shell. Reported-by: Jack Kamm Link: https://orgmode.org/list/87sf2q9ubd.fsf@gmail.com --- lisp/ob-clojure.el | 4 ++- lisp/ob-comint.el | 69 +++++++++++++++++++++++++++++++++++++--------- lisp/ob-haskell.el | 6 ++-- lisp/ob-ruby.el | 4 ++- lisp/ob-shell.el | 8 ++++-- 5 files changed, 71 insertions(+), 20 deletions(-) diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el index ddcfcd9fb..4a54acc51 100644 --- a/lisp/ob-clojure.el +++ b/lisp/ob-clojure.el @@ -237,7 +237,9 @@ (defun ob-clojure-eval-with-inf-clojure (expanded param= s) "clojure" (format "clojure -A%s" alias) cmd0) cmd0))) - (setq comint-prompt-regexp inf-clojure-comint-prompt-regexp) + (setq + org-babel-comint-prompt-regexp-old comint-prompt-regexp + comint-prompt-regexp inf-clojure-comint-prompt-regexp) (funcall-interactively #'inf-clojure cmd) (goto-char (point-max)))) (sit-for 1)) diff --git a/lisp/ob-comint.el b/lisp/ob-comint.el index 7d258ea0e..26f0c3bf7 100644 --- a/lisp/ob-comint.el +++ b/lisp/ob-comint.el @@ -58,6 +58,22 @@ (defmacro org-babel-comint-in-buffer (buffer &rest body) (let ((comint-input-filter (lambda (_input) nil))) ,@body)))))) =20 +(defvar-local org-babel-comint-prompt-regexp-old nil + "Fallback regexp used to detect prompt.") + +(defcustom org-babel-comint-fallback-regexp-threshold 5.0 + "Waiting time until trying to use fallback regexp to detect prompt. +This is useful when prompt unexpectedly changes." + :type 'float + :group 'org-babel) + +(defun org-babel-comint--set-fallback-prompt () + "Swap `comint-prompt-regexp' and `org-babel-comint-prompt-regexp-old'." + (when org-babel-comint-prompt-regexp-old + (let ((tmp comint-prompt-regexp)) + (setq comint-prompt-regexp org-babel-comint-prompt-regexp-old + org-babel-comint-prompt-regexp-old tmp)))) + (defmacro org-babel-comint-with-output (meta &rest body) "Evaluate BODY in BUFFER and return process output. Will wait until EOE-INDICATOR appears in the output, then return @@ -96,14 +112,29 @@ (defmacro org-babel-comint-with-output (meta &rest bod= y) ;; pass FULL-BODY to process ,@body ;; wait for end-of-evaluation indicator - (while (progn - (goto-char comint-last-input-end) - (not (save-excursion - (and (re-search-forward - (regexp-quote ,eoe-indicator) nil t) - (re-search-forward - comint-prompt-regexp nil t))))) - (accept-process-output (get-buffer-process (current-buffer)))) + (let ((start-time (current-time))) + (while (progn + (goto-char comint-last-input-end) + (not (save-excursion + (and (re-search-forward + (regexp-quote ,eoe-indicator) nil t) + (re-search-forward + comint-prompt-regexp nil t))))) + (accept-process-output + (get-buffer-process (current-buffer)) + org-babel-comint-fallback-regexp-threshold) + (when (and org-babel-comint-prompt-regexp-old + (> (float-time (time-since start-time)) + org-babel-comint-fallback-regexp-threshold) + (progn + (goto-char comint-last-input-end) + (save-excursion + (and + (re-search-forward + (regexp-quote ,eoe-indicator) nil t) + (re-search-forward + org-babel-comint-prompt-regexp-old nil t))))) + (org-babel-comint--set-fallback-prompt)))) ;; replace cut dangling text (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert dangling-text) @@ -148,11 +179,23 @@ (defun org-babel-comint-wait-for-output (buffer) Note: this is only safe when waiting for the result of a single statement (not large blocks of code)." (org-babel-comint-in-buffer buffer - (while (progn - (goto-char comint-last-input-end) - (not (and (re-search-forward comint-prompt-regexp nil t) - (goto-char (match-beginning 0))))) - (accept-process-output (get-buffer-process buffer))))) + (let ((start-time (current-time))) + (while (progn + (goto-char comint-last-input-end) + (not (and (re-search-forward comint-prompt-regexp nil t) + (goto-char (match-beginning 0))))) + (accept-process-output + (get-buffer-process buffer) + org-babel-comint-fallback-regexp-threshold) + (when (and org-babel-comint-prompt-regexp-old + (> (float-time (time-since start-time)) + org-babel-comint-fallback-regexp-threshold) + (progn + (goto-char comint-last-input-end) + (save-excursion + (re-search-forward + org-babel-comint-prompt-regexp-old nil t)))) + (org-babel-comint--set-fallback-prompt)))))) =20 (defun org-babel-comint-eval-invisibly-and-wait-for-file (buffer file string &optional period) diff --git a/lisp/ob-haskell.el b/lisp/ob-haskell.el index a9ed772dd..00be6d52c 100644 --- a/lisp/ob-haskell.el +++ b/lisp/ob-haskell.el @@ -152,8 +152,10 @@ (defun org-babel-interpret-haskell (body params) (org-require-package 'inf-haskell "haskell-mode") (add-hook 'inferior-haskell-hook (lambda () - (setq-local comint-prompt-regexp - (concat haskell-prompt-regexp "\\|^=CE=BB?> ")))) + (setq-local + org-babel-comint-prompt-regexp-old comint-prompt-regexp + comint-prompt-regexp + (concat haskell-prompt-regexp "\\|^=CE=BB?> ")))) (org-babel-haskell-with-session session params (cl-labels ((send-txt-to-ghci (txt) diff --git a/lisp/ob-ruby.el b/lisp/ob-ruby.el index 79b33940d..d920fb585 100644 --- a/lisp/ob-ruby.el +++ b/lisp/ob-ruby.el @@ -191,7 +191,9 @@ (defun org-babel-ruby-initiate-session (&optional sessi= on params) ;; uniquely by regexp. (when new-session? (with-current-buffer session-buffer - (setq-local comint-prompt-regexp (concat "^" org-babel-rub= y-prompt)) + (setq-local + org-babel-comint-prompt-regexp-old comint-prompt-regexp + comint-prompt-regexp (concat "^" org-babel-ruby-prompt)) (insert org-babel-ruby-define-prompt ";") (insert "_org_prompt_mode=3Dconf.prompt_mode;conf.prompt_m= ode=3D:CUSTOM;") (insert "conf.echo=3Dfalse\n") diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el index 31135b5fb..20d1d5e33 100644 --- a/lisp/ob-shell.el +++ b/lisp/ob-shell.el @@ -265,9 +265,11 @@ (defun org-babel-sh-initiate-session (&optional sessio= n _params) org-babel-shell-set-prompt-commands)) (alist-get t org-babel-shell-set-prompt-commands)) org-babel-sh-prompt)) - (setq-local comint-prompt-regexp - (concat "^" (regexp-quote org-babel-sh-prompt) - " *")) + (setq-local + org-babel-comint-prompt-regexp-old comint-prompt-regexp + comint-prompt-regexp + (concat "^" (regexp-quote org-babel-sh-prompt) + " *")) ;; Needed for Emacs 23 since the marker is initially ;; undefined and the filter functions try to use it without ;; checking. --=20 2.43.0 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--