From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Kelling Subject: stderr patch Date: Fri, 21 Mar 2014 20:59:45 -0700 Message-ID: <532D0AB1.6080708@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43251) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WRD6E-0007kF-0a for emacs-orgmode@gnu.org; Sat, 22 Mar 2014 00:00:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WRD67-0001KM-RK for emacs-orgmode@gnu.org; Fri, 21 Mar 2014 23:59:57 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:35517) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WRD67-0001KI-N2 for emacs-orgmode@gnu.org; Fri, 21 Mar 2014 23:59:51 -0400 Received: from [192.168.1.2] (unknown [67.160.118.141]) by mail.messagingengine.com (Postfix) with ESMTPA id AC2266800EC for ; Fri, 21 Mar 2014 23:59:50 -0400 (EDT) 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" I use babel mostly for shell scripts. I wrote a patch to allow toggling the handling of errors & std err. I prefer standard error just get printed with everything else, the same as calling a script from a terminal. Doing this properly with header arguments etc. has been discussed before (google org-babel stderr), and just hasn't gotten done yet. Until then, this works great, so I'm putting it out there in case anyone wants to use it. --- lisp/ob-eval.el | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lisp/ob-eval.el b/lisp/ob-eval.el index 057590f..fdc6da5 100644 --- a/lisp/ob-eval.el +++ b/lisp/ob-eval.el @@ -31,6 +31,14 @@ (eval-when-compile (require 'cl)) (defvar org-babel-error-buffer-name "*Org-Babel Error Output*") +(defcustom org-babel-use-error-buffer t + "When evaluating a code block, if nil and an error is returned +,no error buffer is created and. Standard error +is redirected to standard out." +:group 'org-babel +:version "24.1" +:type 'boolean) + (declare-function org-babel-temp-file "ob-core" (prefix &optional suffix)) (defun org-babel-eval-error-notify (exit-code stderr) @@ -46,14 +54,16 @@ "Run CMD on BODY. If CMD succeeds then return its results, otherwise display STDERR with `org-babel-eval-error-notify'." - (let ((err-buff (get-buffer-create " *Org-Babel Error*")) exit-code) - (with-current-buffer err-buff (erase-buffer)) + (let ((err-buff (if org-babel-use-error-buffer + (get-buffer-create " *Org-Babel Error*"))) + exit-code) + (if err-buff (with-current-buffer err-buff (erase-buffer))) (with-temp-buffer (insert body) (setq exit-code (org-babel--shell-command-on-region (point-min) (point-max) cmd err-buff)) - (if (or (not (numberp exit-code)) (> exit-code 0)) + (if (and err-buff (or (not (numberp exit-code)) (> exit-code 0))) (progn (with-current-buffer err-buff (org-babel-eval-error-notify exit-code (buffer-string))) @@ -90,7 +100,7 @@ function in various versions of Emacs. ;; This is fixed in Emacs trunk as of 2012-12-21; let's use this ;; workaround for now. (unless (file-remote-p default-directory) - (delete-file error-file)) + (if error-file (delete-file error-file))) ;; we always call this with 'replace, remove conditional ;; Replace specified region with output from command. (let ((swap (< start end))) -- 1.7.10.4