From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id wKsKEf1XrmUkWwAAe85BDQ:P1 (envelope-from ) for ; Mon, 22 Jan 2024 12:56:45 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id wKsKEf1XrmUkWwAAe85BDQ (envelope-from ) for ; Mon, 22 Jan 2024 12:56:45 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=aoxph6u5; 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=1705924605; a=rsa-sha256; cv=none; b=s17cNYhxveBtVzGJyJ4YU4ww9gt0fzp5ZBzsKcoLMBJiqugffMB3xqy71kPTsH5x2LSWYT 2NDYP46DlYi4jEeuMA+z6mk3H4Vtecjf2D/oFU9PjSRZYCl/A3DTg8AhhK5ZD8h/mpYBZe /85HZUYJ5IhgFlhZwmQvDhrEf7fGpJ/Tm6Ck54knw4fdT9gh/Lr0XwW/ZsBm4bNrc6Te9G DJniIvwJSE1lL/WopYRJnIgCC2s3g5qMJ4dWRULIen/nLbNDvhQY0TrGyiCGdv0XFkB6JR KygLXgIvEcBxtpK8MrjlCtIkoeibosWo3ElQee9bcgeBofWfn/qXyX+jm0CYFA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=aoxph6u5; 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=1705924605; 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=4M28E+rlC3pVEv+OhBX2261VzNwrPASxIlRCn1Zknrw=; b=OZH9MyJuSnFGSOnNaIyeoGYrjIFdT3fFzC4oIZ3IwSASSWr6cRIWpXh9ivQFVR2fpdnOpW xkblH2/glJ2xNjRDCvVwg6meoq2JumHGpclfeNtNNOaOXVbDyLY3N2ZBqGu7DNbGrS2O9y J+y1Ncu8g46v6aWQ5yC/pP+eQ7ht74/OkyBGouphj2TVUFXilRWgP+W34pfabDjDIq+CCp qfwjgidnGLELZAJgLBKgvGP4cGr3ObHu5pj5hbqsr+7QzTP5baY/mjDgQVSENaHvxtVArL +A1WR74MhlHMKDymbPe7b0uuZeEHKddr6eEmdXHQLDYiQbJawVYQG6ZQsSmdkg== 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 AC8F321250 for ; Mon, 22 Jan 2024 12:56:44 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rRsu9-0006m4-Pj; Mon, 22 Jan 2024 06:55:53 -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 1rRsu7-0006k1-BS for emacs-orgmode@gnu.org; Mon, 22 Jan 2024 06:55:51 -0500 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rRsu4-0008Kn-9K for emacs-orgmode@gnu.org; Mon, 22 Jan 2024 06:55:51 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 3C14E24002A for ; Mon, 22 Jan 2024 12:55:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1705924546; bh=dEElO+Zl/O6/JKbpcSnnern8pSfiMx12BWb5oK+98E0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=aoxph6u5E5EQG+sPtln3CLyqYjPKLu8ZmB+XfsLl+nvTlmDAhU24/hWVEA6XhMzea t1QvJZ4zCGg4A9Bs67qmX9dWBnl8l71dEDziAP7w2fCqZRIIYUcbOvhGke1FG3Wod1 bWTAtWbXqbN/HpCFu3BluxyUzI/3yRVDshMjgicbq5kjii0gPYn4e4rivC20cwJSya 6AR+t9cUSKOmWDaIQcNAQSganK4Z8pjJWXrN7yJgotlCj9dJB7JSnLOr3mShkQHu2p WYWHQvuNEeRqxL8ejLjldAZCHzEO4H7SnD//tu/bcSPLQbl+G5X+vRt2ccveiEk6Zk OhMLSOCcMmUYA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TJTFF06ymz6tmv; Mon, 22 Jan 2024 12:55:44 +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: <87o7de9gq5.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> Date: Mon, 22 Jan 2024 11:59:15 +0000 Message-ID: <877ck1vass.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.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-Scanner: mx10.migadu.com X-Spam-Score: -9.89 X-Migadu-Queue-Id: AC8F321250 X-Migadu-Spam-Score: -9.89 X-TUID: qpyC2e6v1kS5 --=-=-= Content-Type: text/plain Jack Kamm writes: > The reason conda doesn't work well when session is started via > `org-babel-execute-src-block' is because of the way the prompt is > set. However, when session is started by "M-x shell", ob-shell doesn't > mess with the prompt so much, and conda seems to work smoothly. Using > "M-x shell" to start the session seems like an acceptable workaround to > me, especially considering how conda never worked well with ob-shell > before. What about the attached patch? --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-lisp-ob-comint.el-Introduce-a-fallback-prompt-regexp.patch Content-Transfer-Encoding: quoted-printable >From 45ddb20665f6124a5b08a9fbfed02ee2961ac9e3 Mon Sep 17 00:00:00 2001 Message-ID: <45ddb20665f6124a5b08a9fbfed02ee2961ac9e3.1705924712.git.yantar= 92@posteo.net> From: Ihor Radchenko Date: Mon, 22 Jan 2024 12:55:09 +0100 Subject: [PATCH] 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 | 65 ++++++++++++++++++++++++++++++++++++---------- lisp/ob-haskell.el | 6 +++-- lisp/ob-ruby.el | 4 ++- lisp/ob-shell.el | 8 +++--- 5 files changed, 67 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..316848b6b 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,27 @@ (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))) + (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 +177,21 @@ (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)) + (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 --=-=-=--