From: Ian Kelling <ianowl@gmail.com>
To: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: stderr patch
Date: Fri, 21 Mar 2014 20:59:45 -0700 [thread overview]
Message-ID: <532D0AB1.6080708@gmail.com> (raw)
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
next reply other threads:[~2014-03-22 4:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-22 3:59 Ian Kelling [this message]
2014-03-22 8:45 ` stderr patch Bastien
2014-03-22 8:50 ` Ian Kelling
2014-03-22 9:07 ` Bastien
2014-03-22 9:10 ` Ian Kelling
2014-03-22 9:23 ` Bastien
2014-03-22 9:43 ` Michael Brand
2014-03-22 10:58 ` Ian Kelling
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=532D0AB1.6080708@gmail.com \
--to=ianowl@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).