summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2010-07-06 10:30:58 -0700
committerEric Schulte <schulte.eric@gmail.com>2010-07-06 10:30:58 -0700
commitc32d77391989d7499ce093f874da0657bc35a15d (patch)
treedddc9588987ab170cccae314498081bf056c1a13
parentf34f0b9b39322d93d9eefa1f4375f67335bcacf9 (diff)
downloadorg-mode-c32d77391989d7499ce093f874da0657bc35a15d.tar.gz
babel: code cleaning -- `error' and `with-current-buffer' usage for Emacs inclusion
-rw-r--r--lisp/ob-C.el56
-rw-r--r--lisp/ob-clojure.el7
-rw-r--r--lisp/ob-comint.el2
-rw-r--r--lisp/ob-ditaa.el2
-rw-r--r--lisp/ob-eval.el3
-rw-r--r--lisp/ob-latex.el5
-rw-r--r--lisp/ob-mscgen.el5
-rw-r--r--lisp/ob-ref.el3
-rw-r--r--lisp/ob.el17
9 files changed, 43 insertions, 57 deletions
diff --git a/lisp/ob-C.el b/lisp/ob-C.el
index 50527c3..fed688e 100644
--- a/lisp/ob-C.el
+++ b/lisp/ob-C.el
@@ -87,45 +87,35 @@ or `org-babel-execute:c++'."
(let* ((processed-params (org-babel-process-params params))
(tmp-src-file (make-temp-file "org-babel-C-src" nil
(cond
- ((equal org-babel-c-variant 'c) ".c")
- ((equal org-babel-c-variant 'cpp) ".cpp"))))
+ ((equal org-babel-c-variant 'c) ".c")
+ ((equal org-babel-c-variant 'cpp) ".cpp"))))
(tmp-bin-file (make-temp-file "org-babel-C-bin"))
(tmp-out-file (make-temp-file "org-babel-C-out"))
(cmdline (cdr (assoc :cmdline params)))
(flags (cdr (assoc :flags params)))
(full-body (org-babel-C-expand body params))
- (error-buf (get-buffer-create "*Org-Babel Error Output*"))
(compile
- (progn
- (with-temp-file tmp-src-file (insert full-body))
- (with-temp-buffer
- (org-babel-shell-command-on-region
- (point-min) (point-max)
- (format "%s -o %s %s %s"
- (cond
- ((equal org-babel-c-variant 'c) org-babel-C-compiler)
- ((equal org-babel-c-variant 'cpp) org-babel-c++-compiler))
- tmp-bin-file
- (mapconcat 'identity
- (if (listp flags) flags (list flags)) " ")
- tmp-src-file)
- (current-buffer) 'replace error-buf)))))
- (if (= compile 0)
- (org-babel-reassemble-table
- (org-babel-read
- (org-babel-trim
- (org-babel-eval
- (concat tmp-bin-file (if cmdline (concat " " cmdline) "")) "")))
- (org-babel-pick-name
- (nth 4 processed-params) (cdr (assoc :colnames params)))
- (org-babel-pick-name
- (nth 5 processed-params) (cdr (assoc :rownames params))))
- (progn
- (with-current-buffer error-buf
- (goto-char (point-max))
- (insert (concat "\n\n--body--\n" full-body))
- (goto-char (point-min)))
- (display-buffer error-buf) nil))))
+ (progn
+ (with-temp-file tmp-src-file (insert full-body))
+ (org-babel-eval
+ (format "%s -o %s %s %s"
+ (cond
+ ((equal org-babel-c-variant 'c) org-babel-C-compiler)
+ ((equal org-babel-c-variant 'cpp) org-babel-c++-compiler))
+ tmp-bin-file
+ (mapconcat 'identity
+ (if (listp flags) flags (list flags)) " ")
+ tmp-src-file) ""))))
+ (org-babel-reassemble-table
+ (org-babel-read
+ (org-babel-trim
+ (org-babel-eval
+ (concat tmp-bin-file (if cmdline (concat " " cmdline) "")) "")))
+ (org-babel-pick-name
+ (nth 4 processed-params) (cdr (assoc :colnames params)))
+ (org-babel-pick-name
+ (nth 5 processed-params) (cdr (assoc :rownames params))))))
+
(defun org-babel-C-expand (body params &optional processed-params)
"Expand a block of C or C++ code with org-babel according to
diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el
index 814803a..58a1c2a 100644
--- a/lisp/ob-clojure.el
+++ b/lisp/ob-clojure.el
@@ -93,8 +93,8 @@
(defun org-babel-clojure-babel-clojure-cmd ()
"Create the command to start clojure according to current settings."
(if (and (not swank-clojure-binary) (not swank-clojure-classpath))
- (error (concat "You must specifiy either a `swank-clojure-binary' "
- "or a `swank-clojure-jar-path'"))
+ (error "%s" (concat "You must specifiy either a `swank-clojure-binary' "
+ "or a `swank-clojure-jar-path'"))
(if swank-clojure-binary
(if (listp swank-clojure-binary)
swank-clojure-binary
@@ -269,8 +269,7 @@ repl buffer."
(require 'slime) (require 'swank-clojure)
(let ((raw nil)
(results nil))
- (save-window-excursion
- (set-buffer buffer)
+ (with-current-buffer buffer
(setq raw (org-babel-clojure-slime-eval-sync body))
(setq results (reverse (mapcar #'org-babel-trim raw)))
(cond
diff --git a/lisp/ob-comint.el b/lisp/ob-comint.el
index 7b742d5..6c13bb6 100644
--- a/lisp/ob-comint.el
+++ b/lisp/ob-comint.el
@@ -48,7 +48,7 @@ body inside the protection of `save-window-excursion' and
`(save-excursion
(save-match-data
(unless (org-babel-comint-buffer-livep ,buffer)
- (error (format "buffer %s doesn't exist or has no process" ,buffer)))
+ (error "buffer %s doesn't exist or has no process" ,buffer))
(set-buffer ,buffer)
,@body)))
diff --git a/lisp/ob-ditaa.el b/lisp/ob-ditaa.el
index 1d70b5a..1f56d12 100644
--- a/lisp/ob-ditaa.el
+++ b/lisp/ob-ditaa.el
@@ -56,7 +56,7 @@ called by `org-babel-execute-src-block'."
(cmdline (cdr (assoc :cmdline params)))
(in-file (make-temp-file "org-babel-ditaa")))
(unless (file-exists-p org-ditaa-jar-path)
- (error (format "Could not find ditaa.jar at %s" org-ditaa-jar-path)))
+ (error "Could not find ditaa.jar at %s" org-ditaa-jar-path))
(with-temp-file in-file (insert body))
(message (concat "java -jar " org-ditaa-jar-path " " cmdline " " in-file " " out-file))
(shell-command (concat "java -jar " org-ditaa-jar-path " " cmdline " " in-file " " out-file))
diff --git a/lisp/ob-eval.el b/lisp/ob-eval.el
index 282baee..40731a1 100644
--- a/lisp/ob-eval.el
+++ b/lisp/ob-eval.el
@@ -187,8 +187,7 @@ specifies the value of ERROR-BUFFER."
;; Clear the output buffer, then run the command with
;; output there.
(let ((directory default-directory))
- (save-current-buffer
- (set-buffer buffer)
+ (with-current-buffer buffer
(setq buffer-read-only nil)
(if (not output-buffer)
(setq default-directory directory))
diff --git a/lisp/ob-latex.el b/lisp/ob-latex.el
index 7b54923..b08e3a4 100644
--- a/lisp/ob-latex.el
+++ b/lisp/ob-latex.el
@@ -80,9 +80,8 @@ called by `org-babel-execute-src-block'."
(when (file-exists-p out-file) (delete-file out-file))
(rename-file (org-babel-latex-tex-to-pdf tex-file) out-file))
((string-match "\\.\\([^\\.]+\\)$" out-file)
- (error
- (message "can not create %s files, please specify a .png or .pdf file"
- (match-string 1 out-file)))))
+ (error "can not create %s files, please specify a .png or .pdf file"
+ (match-string 1 out-file))))
out-file)
body))
diff --git a/lisp/ob-mscgen.el b/lisp/ob-mscgen.el
index 5c9f3e5..3c2b790 100644
--- a/lisp/ob-mscgen.el
+++ b/lisp/ob-mscgen.el
@@ -74,9 +74,8 @@ formats."
(let* ((out-file (or (cdr (assoc :file params)) "output.png" ))
(filetype (or (cdr (assoc :filetype params)) "png" )))
(unless (cdr (assoc :file params))
- (error (concat
- "\nERROR: no output file specified. "
- "Add \":file some_name.png\" to the src header")))
+ (error "
+ERROR: no output file specified. Add \":file name.png\" to the src header"))
(org-babel-eval (concat "mscgen -T " filetype " -o " out-file) body)
out-file))
diff --git a/lisp/ob-ref.el b/lisp/ob-ref.el
index 85a29a2..14679bb 100644
--- a/lisp/ob-ref.el
+++ b/lisp/ob-ref.el
@@ -150,8 +150,7 @@ return nil."
;; buffer (marker-buffer id-loc)
;; loc (marker-position id-loc))
;; (move-marker id-loc nil)
- (progn (message (format "reference '%s' not found in this buffer" ref))
- (error (format "reference '%s' not found in this buffer" ref))))
+ (error "reference '%s' not found in this buffer" ref))
(if lob-info
(setq type 'lob)
(while (not (setq type (org-babel-ref-at-ref-p)))
diff --git a/lisp/ob.el b/lisp/ob.el
index 7469876..5303f2d 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -1323,9 +1323,8 @@ block but are passed literally to the \"example-block\"."
(nb-add (buffer-substring index (point)))
(goto-char (match-end 0))
(setq index (point))
- (nb-add (save-current-buffer
- (set-buffer parent-buffer)
- (mapconcat ;; interpose `prefix' between every line
+ (nb-add (with-current-buffer parent-buffer
+ (mapconcat ;; interpose PREFIX between every line
#'identity
(split-string
(if evaluate
@@ -1334,7 +1333,8 @@ block but are passed literally to the \"example-block\"."
(if (stringp raw) raw (format "%S" raw)))
(save-restriction
(widen)
- (let ((point (org-babel-find-named-block source-name)))
+ (let ((point (org-babel-find-named-block
+ source-name)))
(if point
(save-excursion
(goto-char point)
@@ -1344,10 +1344,11 @@ block but are passed literally to the \"example-block\"."
;; optionally raise an error if named
;; source-block doesn't exist
(if (member lang org-babel-noweb-error-langs)
- (error
- (concat "<<%s>> could not be resolved "
- "(see `org-babel-noweb-error-langs')")
- source-name)
+ (error "%s"
+ (concat
+ "<<" source-name ">> "
+ "could not be resolved (see "
+ "`org-babel-noweb-error-langs')"))
"")))))
"[\n\r]") (concat "\n" prefix)))))
(nb-add (buffer-substring index (point-max)))))