From mboxrd@z Thu Jan 1 00:00:00 1970 From: Julien Barnier Subject: [babel] [PATCH] Fix sh block execution in session Date: Fri, 3 Jun 2011 14:26:48 +0000 (UTC) Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([140.186.70.92]:36271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSVLD-0000tg-2w for emacs-orgmode@gnu.org; Fri, 03 Jun 2011 10:27:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QSVLA-0006JF-MV for emacs-orgmode@gnu.org; Fri, 03 Jun 2011 10:27:10 -0400 Received: from lo.gmane.org ([80.91.229.12]:37086) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSVLA-0006Iv-4X for emacs-orgmode@gnu.org; Fri, 03 Jun 2011 10:27:08 -0400 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QSVL3-0006mc-J6 for emacs-orgmode@gnu.org; Fri, 03 Jun 2011 16:27:03 +0200 Received: from z0.nozav.org ([88.191.117.176]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 03 Jun 2011 16:27:01 +0200 Received: from julien by z0.nozav.org with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 03 Jun 2011 16:27:01 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Hi, When evaluating shell code blocks in org-babel, the execution seems to hang indefinitely. The following patch is trying to fix this problem by modifying the way shell code is send to comint and the way the end-of-evaluation indicator is looking for. As I am far from an emacs lisp expert and as the patch modifies the widely use org-babel-comint-with-output function, it certainly needs some testing. I've made some tests with shell and R code blocks, but I'm not sure it's enough. Thanks ! Julien Fix sh block execution in a session * lisp/ob-sh.el (org-babel-sh-evaluate) : when sending input to comint, wait until previous line execution is finished * lisp/ob-comint.el (org-babel-comint-with-output) : when looking for end-of-evaluation indicator, search forward for the indicator before searching forward for the prompt --- lisp/ob-comint.el | 4 ++-- lisp/ob-sh.el | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lisp/ob-comint.el b/lisp/ob-comint.el index d12ed47..21ff0f6 100644 --- a/lisp/ob-comint.el +++ b/lisp/ob-comint.el @@ -93,9 +93,9 @@ or user `keyboard-quit' during execution of body." (goto-char comint-last-input-end) (not (save-excursion (and (re-search-forward - comint-prompt-regexp nil t) + (regexp-quote ,eoe-indicator) nil t) (re-search-forward - (regexp-quote ,eoe-indicator) nil t))))) + comint-prompt-regexp nil t))))) (accept-process-output (get-buffer-process (current-buffer))) ;; thought the following this would allow async ;; background running, but I was wrong... diff --git a/lisp/ob-sh.el b/lisp/ob-sh.el index 10c08d4..b2d1591 100644 --- a/lisp/ob-sh.el +++ b/lisp/ob-sh.el @@ -170,7 +170,13 @@ return the value of the last statement in BODY." (session org-babel-sh-eoe-output t body) (mapc (lambda (line) - (insert line) (comint-send-input nil t) (sleep-for 0.25)) + (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))))) (append (split-string (org-babel-trim body) "\n") (list org-babel-sh-eoe-indicator)))) -- 1.7.5.1