Quellcode durchsuchen

truncating multi-line output before inserting into org-mode tables

Eric Schulte vor 16 Jahren
Ursprung
Commit
a7b04ffe12
2 geänderte Dateien mit 66 neuen und 12 gelöschten Zeilen
  1. 17 11
      litorgy/litorgy-table.el
  2. 49 1
      rorg.org

+ 17 - 11
litorgy/litorgy-table.el

@@ -55,6 +55,11 @@
 ;;; Code:
 (require 'litorgy)
 
+(defun org-table-truncate-at-newline (string)
+  (if (and (stringp string) (string-match "[\n\r]" string))
+      (concat (substring string 0 (match-beginning 0)) "...")
+    string))
+
 (defmacro sbe (source-block &rest variables)
   "Return the results of calling SOURCE-BLOCK with all assigning
 every variable in VARIABLES.  Each element of VARIABLES should be
@@ -69,17 +74,18 @@ source code block.
 results
 #+end_src"
   (unless (stringp source-block) (setq source-block (symbol-name source-block)))
-  (if (and source-block (> (length source-block) 0))
-      (let ((params (eval `(litorgy-parse-header-arguments
-                            (concat ":var results="
-                                    ,source-block
-                                    "("
-                                    (mapconcat (lambda (var-spec)
-                                                 (format "%S=%s" (first var-spec) (second var-spec)))
-                                               ',variables ", ")
-                                    ")")))))
-        (litorgy-execute-src-block t (list "emacs-lisp" "results" params)))
-    ""))
+  (org-table-truncate-at-newline ;; org-table cells can't be multi-line
+   (if (and source-block (> (length source-block) 0))
+       (let ((params (eval `(litorgy-parse-header-arguments
+                             (concat ":var results="
+                                     ,source-block
+                                     "("
+                                     (mapconcat (lambda (var-spec)
+                                                  (format "%S=%s" (first var-spec) (second var-spec)))
+                                                ',variables ", ")
+                                     ")")))))
+         (litorgy-execute-src-block t (list "emacs-lisp" "results" params)))
+     "")))
 
 (provide 'litorgy-table)
 ;;; litorgy-table.el ends here

+ 49 - 1
rorg.org

@@ -423,7 +423,24 @@ example in the [[* emacs lisp source reference][emacs lisp source reference]].
 
 
 
-* Bugs [9/10]
+* Bugs [9/11]
+
+** TODO collapsing consecutive newlines in string output
+
+#+srcname: multi-line-string-output
+#+begin_src ruby :results replace
+"the first line ends here
+
+
+     and this is the second one
+
+even a third"
+#+end_src
+
+#+resname:
+: the first line ends here
+: 	     and this is the second one
+: 	return even a third
 
 ** TODO cursor movement when evaluating source blocks
    E.g. the pie chart example. Despite the save-window-excursion in
@@ -775,6 +792,37 @@ table.class.name
 (fibbd n)
 #+end_src
 
+** sbe tests
+Testing the insertion of results into org-mode tables.
+
+#+srcname: multi-line-output
+#+begin_src ruby :results replace
+"the first line ends here
+
+
+     and this is the second one
+
+even a third"
+#+end_src
+
+#+resname:
+: the first line ends here
+: 	     and this is the second one
+: 	return even a third
+
+#+srcname: multi-line-error
+#+begin_src ruby :results replace
+raise "oh nooooooooooo"
+#+end_src
+
+#+resname:
+: -:5: warning: parenthesize argument(s) for future version
+: -:5:in `main': oh nooooooooooo (RuntimeError)
+: 	from -:8
+
+| the first line ends here... | -:5: warning: parenthesize argument(s) for future version... |
+#+TBLFM: $1='(sbe "multi-line-output")::$2='(sbe "multi-line-error")
+
 
 * Sandbox
   :PROPERTIES: