Browse Source

now replace works for table results as well as string results

Eric Schulte 17 years ago
parent
commit
c40217b5f0
1 changed files with 18 additions and 14 deletions
  1. 18 14
      litorgy/litorgy.el

+ 18 - 14
litorgy/litorgy.el

@@ -150,7 +150,7 @@ form.  (language body header-arguments-alist)"
   "Insert RESULT into the current buffer after the end of the
   "Insert RESULT into the current buffer after the end of the
 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))
+  (if replace (litorgy-remove-result (listp result)))
   (if (and (stringp result)
   (if (and (stringp result)
            (not (or (string-equal (substring result -1)
            (not (or (string-equal (substring result -1)
                                   "\n")
                                   "\n")
@@ -160,25 +160,29 @@ existing results currently located after the source block."
   (save-excursion
   (save-excursion
     (re-search-forward "^#\\+end_src" nil t) (open-line 1) (forward-char 2)
     (re-search-forward "^#\\+end_src" nil t) (open-line 1) (forward-char 2)
     (if (stringp result)
     (if (stringp result)
-        (litorgy-examplize-region (point) (progn (insert result) (point)))
-      (insert ;; for now lets assume the result is a table if it's not a string
-       (orgtbl-to-orgtbl result '(:fmt (lambda (cell) (format "%S" cell)))))
-      (forward-line -1)
-      (org-cycle))))
+        (litorgy-examplize-region (point) (progn (insert result) (point))))
+    (insert ;; for now lets assume the result is a table if it's not a string
+     (concat (orgtbl-to-orgtbl result '(:fmt (lambda (cell) (format "%S" cell)))) "\n"))
+    (forward-line -1)
+    (org-cycle)))
                                                
                                                
-(defun litorgy-remove-result ()
-  "Remove the result following the current source block"
+(defun litorgy-remove-result (&optional table)
+  "Remove the result following the current source block.  If
+optional argument TABLE is supplied then remove the table
+following the block rather than the fixed width example."
   (save-excursion
   (save-excursion
     (re-search-forward "^#\\+end_src" nil t)
     (re-search-forward "^#\\+end_src" nil t)
     (forward-char 1)
     (forward-char 1)
     (delete-region (point)
     (delete-region (point)
                    (save-excursion (forward-line 1)
                    (save-excursion (forward-line 1)
-                                   (while (if (looking-at ": ")
-                                              (progn (while (looking-at ": ")
-                                                       (forward-line 1)) t))
-                                     (forward-line 1))
-                                   (forward-line -1)
-                                   (point)))))
+                                   (if table
+                                       (org-table-end)
+                                     (while (if (looking-at ": ")
+                                                (progn (while (looking-at ": ")
+                                                         (forward-line 1)) t))
+                                       (forward-line 1))
+                                     (forward-line -1)
+                                     (point))))))
 
 
 (defun litorgy-examplize-region (beg end)
 (defun litorgy-examplize-region (beg end)
   "Comment out region using the ': ' org example quote."
   "Comment out region using the ': ' org example quote."