Browse Source

cleanup and small misc re-organizations

Eric Schulte 16 years ago
parent
commit
01401748e4
3 changed files with 24 additions and 23 deletions
  1. 3 3
      litorgy/litorgy-lisp.el
  2. 4 5
      litorgy/litorgy-script.el
  3. 17 15
      litorgy/litorgy.el

+ 3 - 3
litorgy/litorgy-lisp.el

@@ -1,8 +1,8 @@
 ;;; litorgy-lisp.el --- litorgy functions for lisp code evaluation
 
-;; Copyright (C) 2009 Eric Schulte, Dan Davison, Austin F. Frank
+;; Copyright (C) 2009 Eric Schulte
 
-;; Author: Eric Schulte, Dan Davison, Austin F. Frank
+;; Author: Eric Schulte
 ;; Keywords: literate programming, reproducible research
 ;; Homepage: http://orgmode.org
 ;; Version: 0.01
@@ -36,10 +36,10 @@
 (defun litorgy-execute:emacs-lisp (body params)
   "Execute a block of emacs-lisp code with litorgy.  This
 function is called by `litorgy-execute-src-block'."
+  (message "executing emacs-lisp code block...")
   (save-window-excursion
     (let ((vars (litorgy-reference-variables params))
           (print-level nil) (print-length nil) results)
-      (message "executing emacs-lisp code block...")
       (setq results
             (eval `(let ,(mapcar (lambda (var) `(,(car var) ',(cdr var))) vars)
                      ,(read body))))

+ 4 - 5
litorgy/litorgy-script.el

@@ -1,8 +1,8 @@
 ;;; litorgy-script.el --- litorgy functions for script execution
 
-;; Copyright (C) 2009 Eric Schulte, Dan Davison, Austin F. Frank
+;; Copyright (C) 2009 Eric Schulte
 
-;; Author: Eric Schulte, Dan Davison, Austin F. Frank
+;; Author: Eric Schulte
 ;; Keywords: literate programming, reproducible research
 ;; Homepage: http://orgmode.org
 ;; Version: 0.01
@@ -50,8 +50,7 @@ executed through litorgy."
   :set 'litorgy-script-add-interpreter)
 
 (defun litorgy-script-execute (cmd body params)
-  "Run CMD on BODY obeying any options set with PARAMS.
-TODO: currently the params part is not implemented"
+  "Run CMD on BODY obeying any options set with PARAMS."
   (message (format "executing %s code block..." cmd))
   (let ((vars (litorgy-reference-variables params)))
     (save-window-excursion
@@ -90,7 +89,7 @@ source code specifying a table (nested arrays)."
 
 (defun litorgy-script-table-or-results (results)
   "If the results look like a table, then convert them into an
-  Emacs-lisp table, otherwise return the results as a string."
+Emacs-lisp table, otherwise return the results as a string."
   (when (string-match "^\\[.+\\]$" results)
     (setq results
           ;; somewhat hacky, but thanks to similarities between

+ 17 - 15
litorgy/litorgy.el

@@ -151,21 +151,23 @@ form.  (language body header-arguments-alist)"
 current source block.  With optional argument REPLACE replace any
 existing results currently located after the source block."
   (if replace (litorgy-remove-result (listp result)))
-  (when (and (stringp result)
-             (not (or (string-equal (substring result -1) "\n")
-                      (string-equal (substring result -1) "\r"))))
-    (setq result (concat result "\n")))
-  (save-excursion
-    (re-search-forward "^#\\+end_src" nil t) (open-line 1) (forward-char 2)
-    (if (stringp result)
-        (litorgy-examplize-region (point) (progn (insert result) (point)))
-      (progn
-        (insert ;; for now lets assume the result is a table if it's not a string
-         (concat (orgtbl-to-orgtbl
-                  (if (consp (car result)) result (list result))
-                  '(:fmt (lambda (cell) (format "%S" cell)))) "\n"))
-        (forward-line -1)
-        (org-cycle)))))
+  (if (= (length result) 0)
+      (message "no result returned by source block")
+    (when (and (stringp result)
+               (not (or (string-equal (substring result -1) "\n")
+                        (string-equal (substring result -1) "\r"))))
+      (setq result (concat result "\n")))
+    (save-excursion
+      (re-search-forward "^#\\+end_src" nil t) (open-line 1) (forward-char 2)
+      (if (stringp result)
+          (litorgy-examplize-region (point) (progn (insert result) (point)))
+        (progn
+          (insert ;; for now lets assume the result is a table if it's not a string
+           (concat (orgtbl-to-orgtbl
+                    (if (consp (car result)) result (list result))
+                    '(:fmt (lambda (cell) (format "%S" cell)))) "\n"))
+          (forward-line -1)
+          (org-cycle))))))
 
 (defun litorgy-remove-result (&optional table)
   "Remove the result following the current source block.  If