summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2014-08-09 21:35:27 -0400
committerEric Schulte <schulte.eric@gmail.com>2014-08-09 21:35:27 -0400
commitf85aeea69f926869981aecf41aeb49945e997c12 (patch)
treed3712ee7c35980e1dae3a3603eb53c1899bc16ce
parent385746d69c7610ce377304cb1a15a1490e40e8c2 (diff)
downloadorg-mode-f85aeea69f926869981aecf41aeb49945e997c12.tar.gz
error behavior for forth code blocks
* lisp/ob-forth.el (org-babel-forth-session-execute): Add error handling for the forth interpreter using `org-babel-eval-error-notify'.
-rw-r--r--lisp/ob-forth.el20
1 files changed, 15 insertions, 5 deletions
diff --git a/lisp/ob-forth.el b/lisp/ob-forth.el
index c64d466..85be0de 100644
--- a/lisp/ob-forth.el
+++ b/lisp/ob-forth.el
@@ -50,7 +50,7 @@ This function is called by `org-babel-execute-src-block'"
(defun org-babel-forth-session-execute (body params)
(require 'forth-mode)
(let ((proc (forth-proc))
- (forth-rx (concat " " (regexp-opt (list "ok" "compiled")) "\n"))
+ (rx " \\(\n:\\|compiled\n\\\|ok\n\\)")
(result-start))
(with-current-buffer (process-buffer (forth-proc))
(mapcar (lambda (line)
@@ -59,11 +59,21 @@ This function is called by `org-babel-execute-src-block'"
(comint-send-string proc (concat line "\n"))
;; wait for forth to say "ok"
(while (not (progn (goto-char result-start)
- (re-search-forward forth-rx nil t)))
+ (re-search-forward rx nil t)))
(accept-process-output proc 0.01))
- (unless (string= "compiled" (match-string 1))
- (buffer-substring (+ result-start 1 (length line))
- (match-beginning 0))))
+ (let ((case (match-string 1)))
+ (cond
+ ((string= "ok\n" case)
+ ;; Collect intermediate output.
+ (buffer-substring (+ result-start 1 (length line))
+ (match-beginning 0)))
+ ((string= "compiled\n" case))
+ ;; Ignore partial compilation.
+ ((string= "\n:" case)
+ ;; Report errors.
+ (org-babel-eval-error-notify 1
+ (buffer-substring
+ (+ (match-beginning 0) 1) (point-max))) nil))))
(split-string (org-babel-trim
(org-babel-expand-body:generic
body params))