Просмотр исходного кода

cleanup and small misc re-organizations

Eric Schulte 17 лет назад
Родитель
Сommit
01401748e4
3 измененных файлов с 24 добавлено и 23 удалено
  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
 ;;; 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
 ;; Keywords: literate programming, reproducible research
 ;; Homepage: http://orgmode.org
 ;; Homepage: http://orgmode.org
 ;; Version: 0.01
 ;; Version: 0.01
@@ -36,10 +36,10 @@
 (defun litorgy-execute:emacs-lisp (body params)
 (defun litorgy-execute:emacs-lisp (body params)
   "Execute a block of emacs-lisp code with litorgy.  This
   "Execute a block of emacs-lisp code with litorgy.  This
 function is called by `litorgy-execute-src-block'."
 function is called by `litorgy-execute-src-block'."
+  (message "executing emacs-lisp code block...")
   (save-window-excursion
   (save-window-excursion
     (let ((vars (litorgy-reference-variables params))
     (let ((vars (litorgy-reference-variables params))
           (print-level nil) (print-length nil) results)
           (print-level nil) (print-length nil) results)
-      (message "executing emacs-lisp code block...")
       (setq results
       (setq results
             (eval `(let ,(mapcar (lambda (var) `(,(car var) ',(cdr var))) vars)
             (eval `(let ,(mapcar (lambda (var) `(,(car var) ',(cdr var))) vars)
                      ,(read body))))
                      ,(read body))))

+ 4 - 5
litorgy/litorgy-script.el

@@ -1,8 +1,8 @@
 ;;; litorgy-script.el --- litorgy functions for script execution
 ;;; 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
 ;; Keywords: literate programming, reproducible research
 ;; Homepage: http://orgmode.org
 ;; Homepage: http://orgmode.org
 ;; Version: 0.01
 ;; Version: 0.01
@@ -50,8 +50,7 @@ executed through litorgy."
   :set 'litorgy-script-add-interpreter)
   :set 'litorgy-script-add-interpreter)
 
 
 (defun litorgy-script-execute (cmd body params)
 (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))
   (message (format "executing %s code block..." cmd))
   (let ((vars (litorgy-reference-variables params)))
   (let ((vars (litorgy-reference-variables params)))
     (save-window-excursion
     (save-window-excursion
@@ -90,7 +89,7 @@ source code specifying a table (nested arrays)."
 
 
 (defun litorgy-script-table-or-results (results)
 (defun litorgy-script-table-or-results (results)
   "If the results look like a table, then convert them into an
   "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)
   (when (string-match "^\\[.+\\]$" results)
     (setq results
     (setq results
           ;; somewhat hacky, but thanks to similarities between
           ;; 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
 current source block.  With optional argument REPLACE replace any
 existing results currently located after the source block."
 existing results currently located after the source block."
   (if replace (litorgy-remove-result (listp result)))
   (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)
 (defun litorgy-remove-result (&optional table)
   "Remove the result following the current source block.  If
   "Remove the result following the current source block.  If