|
|
@@ -105,7 +105,9 @@ prefix don't dump results into buffer."
|
|
|
(unless (member lang litorgy-interpreters)
|
|
|
(error "Language is not in `litorgy-interpreters': %s" lang))
|
|
|
(setq result (funcall cmd body params))
|
|
|
- (unless arg (litorgy-insert-result result (assoc :replace params)))))
|
|
|
+ (if arg
|
|
|
+ (message (format "%S" result))
|
|
|
+ (litorgy-insert-result result (assoc :replace params)))))
|
|
|
|
|
|
(defun litorgy-eval-buffer (&optional arg)
|
|
|
"Replace EVAL snippets in the entire buffer."
|
|
|
@@ -141,42 +143,61 @@ form. (language body header-arguments-alist)"
|
|
|
(delq nil
|
|
|
(mapcar
|
|
|
(lambda (arg) (if (string-match "\\([^ \f\t\n\r\v]+\\)[ \f\t\n\r\v]*\\([^ \f\t\n\r\v]*\\)" arg)
|
|
|
- (cons (intern (concat ":" (match-string 1 arg))) (match-string 2 arg))))
|
|
|
+ (cons (intern (concat ":" (match-string 1 arg))) (match-string 2 arg))))
|
|
|
(split-string (concat " " arg-string) "[ \f\t\n\r\v]+:"))))
|
|
|
|
|
|
(defun litorgy-insert-result (result &optional replace)
|
|
|
"Insert RESULT into the current buffer after the end of the
|
|
|
current source block. With optional argument REPLACE replace any
|
|
|
existing results currently located after the source block."
|
|
|
- (if replace (litorgy-remove-result))
|
|
|
- (unless (or (string-equal (substring result -1)
|
|
|
- "\n")
|
|
|
- (string-equal (substring result -1)
|
|
|
- "\r"))
|
|
|
+ (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)
|
|
|
- (let ((beg (point))
|
|
|
- (end (progn (insert result)
|
|
|
- (point))))
|
|
|
- (save-excursion
|
|
|
- (set-mark beg)
|
|
|
- (goto-char end)
|
|
|
- (org-toggle-fixed-width-section nil)))))
|
|
|
-
|
|
|
-(defun litorgy-remove-result ()
|
|
|
- "Remove the result following the current source block"
|
|
|
+ (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
|
|
|
+optional argument TABLE is supplied then remove the table
|
|
|
+following the block rather than the fixed width example."
|
|
|
(save-excursion
|
|
|
(re-search-forward "^#\\+end_src" nil t)
|
|
|
(forward-char 1)
|
|
|
(delete-region (point)
|
|
|
(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)
|
|
|
+ "Comment out region using the ': ' org example quote."
|
|
|
+ (interactive "*r")
|
|
|
+ (let ((size (abs (- (line-number-at-pos end)
|
|
|
+ (line-number-at-pos beg)))))
|
|
|
+ (if (= size 0)
|
|
|
+ (let ((result (buffer-substring beg end)))
|
|
|
+ (delete-region beg end)
|
|
|
+ (insert (concat ": " result)))
|
|
|
+ (save-excursion
|
|
|
+ (goto-char beg)
|
|
|
+ (dotimes (n size)
|
|
|
+ (move-beginning-of-line 1) (insert ": ") (forward-line 1))))))
|
|
|
|
|
|
(defun litorgy-clean-text-properties (text)
|
|
|
"Strip all properties from text return."
|