Browse Source

lists are now a data type recognized by code blocks

* lisp/ob-ref.el (org-babel-ref-resolve): Recognize `list' as a unique
  type of data
  (org-babel-ref-at-ref-p): Recognize `list' as a unique type of data

* lisp/ob.el (org-babel-read-result): Recognize `list' as a unique
  type of data
  (org-babel-read-list): A function to read a textual Org-mode list
  into an emacs-lisp list.
  (org-babel-insert-result): Recognizes the "list" result param to
  insert data as an Org-mode list.
  (org-babel-result-end): Find the end of an Org-mode list.
  (org-babel-merge-params): Add "list" as a result param.

* doc/org.texi (results): Documentation of the new "list" results
  header argument.
Eric Schulte 15 years ago
parent
commit
88947588bc
3 changed files with 28 additions and 7 deletions
  1. 5 2
      doc/org.texi
  2. 2 0
      lisp/ob-ref.el
  3. 21 5
      lisp/ob.el

+ 5 - 2
doc/org.texi

@@ -11758,8 +11758,8 @@ another by commas, as shown in the following example.
 @node results, file, var, Specific header arguments
 @node results, file, var, Specific header arguments
 @subsubsection @code{:results}
 @subsubsection @code{:results}
 
 
-There are three classes of @code{:results} header argument.  Only one option of
-each type may be supplied per code block.
+There are three classes of @code{:results} header argument.  Only one option
+per class may be supplied per code block.
 
 
 @itemize @bullet
 @itemize @bullet
 @item
 @item
@@ -11802,6 +11802,9 @@ table or scalar depending on their value.
 The results should be interpreted as an Org-mode table.  If a single value is
 The results should be interpreted as an Org-mode table.  If a single value is
 returned, it will be converted into a table with one row and one column.
 returned, it will be converted into a table with one row and one column.
 E.g., @code{:results value table}.
 E.g., @code{:results value table}.
+@item @code{list}
+The results should be interpreted as an Org-mode list.  If a single scalar
+value is returned it will be converted into a list with only one element.
 @item @code{scalar}, @code{verbatim}
 @item @code{scalar}, @code{verbatim}
 The results should be interpreted literally---they will not be
 The results should be interpreted literally---they will not be
 converted into a table.  The results will be inserted into the Org-mode
 converted into a table.  The results will be inserted into the Org-mode

+ 2 - 0
lisp/ob-ref.el

@@ -147,6 +147,7 @@ the variable."
 		(case type
 		(case type
 		  ('results-line (org-babel-read-result))
 		  ('results-line (org-babel-read-result))
 		  ('table (org-babel-read-table))
 		  ('table (org-babel-read-table))
+		  ('list (org-babel-read-list))
 		  ('file (org-babel-read-link))
 		  ('file (org-babel-read-link))
 		  ('source-block (org-babel-execute-src-block nil nil params))
 		  ('source-block (org-babel-execute-src-block nil nil params))
 		  ('lob (org-babel-execute-src-block nil lob-info params)))))
 		  ('lob (org-babel-execute-src-block nil lob-info params)))))
@@ -214,6 +215,7 @@ to \"0:-1\"."
 Return nil if none of the supported reference types are found.
 Return nil if none of the supported reference types are found.
 Supported reference types are tables and source blocks."
 Supported reference types are tables and source blocks."
   (cond ((org-at-table-p) 'table)
   (cond ((org-at-table-p) 'table)
+	((org-list-in-item-p-with-indent 0) 'list)
         ((looking-at "^[ \t]*#\\+BEGIN_SRC") 'source-block)
         ((looking-at "^[ \t]*#\\+BEGIN_SRC") 'source-block)
         ((looking-at org-bracket-link-regexp) 'file)
         ((looking-at org-bracket-link-regexp) 'file)
         ((looking-at org-babel-result-regexp) 'results-line)))
         ((looking-at org-babel-result-regexp) 'results-line)))

+ 21 - 5
lisp/ob.el

@@ -1307,6 +1307,7 @@ following the source block."
   (let ((case-fold-search t) result-string)
   (let ((case-fold-search t) result-string)
     (cond
     (cond
      ((org-at-table-p) (org-babel-read-table))
      ((org-at-table-p) (org-babel-read-table))
+     ((org-list-in-item-p-with-indent 0) (org-babel-read-list))
      ((looking-at org-bracket-link-regexp) (org-babel-read-link))
      ((looking-at org-bracket-link-regexp) (org-babel-read-link))
      ((looking-at org-block-regexp) (org-babel-trim (match-string 4)))
      ((looking-at org-block-regexp) (org-babel-trim (match-string 4)))
      ((looking-at "^[ \t]*: ")
      ((looking-at "^[ \t]*: ")
@@ -1332,6 +1333,10 @@ following the source block."
               (mapcar #'org-babel-read row)))
               (mapcar #'org-babel-read row)))
           (org-table-to-lisp)))
           (org-table-to-lisp)))
 
 
+(defun org-babel-read-list ()
+  "Read the list at `point' into emacs-lisp."
+  (mapcar #'org-babel-read (cdr (org-list-parse-list))))
+
 (defvar org-link-types-re)
 (defvar org-link-types-re)
 (defun org-babel-read-link ()
 (defun org-babel-read-link ()
   "Read the link at `point' into emacs-lisp.
   "Read the link at `point' into emacs-lisp.
@@ -1365,7 +1370,9 @@ silent -- no results are inserted
 file ---- the results are interpreted as a file path, and are
 file ---- the results are interpreted as a file path, and are
           inserted into the buffer using the Org-mode file syntax
           inserted into the buffer using the Org-mode file syntax
 
 
-raw ----- results are added directly to the org-mode file.  This
+list ---- the results are interpreted as an Org-mode list.
+
+raw ----- results are added directly to the Org-mode file.  This
           is a good option if you code block will output org-mode
           is a good option if you code block will output org-mode
           formatted text.
           formatted text.
 
 
@@ -1430,6 +1437,13 @@ code ---- the results are extracted in the syntax of the source
 	(cond
 	(cond
 	 ;; do nothing for an empty result
 	 ;; do nothing for an empty result
 	 ((= (length result) 0))
 	 ((= (length result) 0))
+	 ;; insert a list if preferred
+	 ((member "list" result-params)
+	  (insert
+	   (org-babel-trim
+	    (org-list-to-generic (cons 'unordered
+				       (if (listp result) result (list result)))
+				 '(:splicep nil :istart "- " :iend "\n")))))
 	 ;; assume the result is a table if it's not a string
 	 ;; assume the result is a table if it's not a string
 	 ((not (stringp result))
 	 ((not (stringp result))
 	  (insert (concat (orgtbl-to-orgtbl
 	  (insert (concat (orgtbl-to-orgtbl
@@ -1482,8 +1496,10 @@ code ---- the results are extracted in the syntax of the source
 (defun org-babel-result-end ()
 (defun org-babel-result-end ()
   "Return the point at the end of the current set of results"
   "Return the point at the end of the current set of results"
   (save-excursion
   (save-excursion
-    (if (org-at-table-p)
-        (progn (goto-char (org-table-end)) (point))
+    (cond
+     ((org-at-table-p) (progn (goto-char (org-table-end)) (point)))
+     ((org-list-in-item-p-with-indent 0) (- (org-list-bottom-point) 1))
+     (t
       (let ((case-fold-search t))
       (let ((case-fold-search t))
         (cond
         (cond
          ((looking-at "[ \t]*#\\+begin_latex")
          ((looking-at "[ \t]*#\\+begin_latex")
@@ -1500,7 +1516,7 @@ code ---- the results are extracted in the syntax of the source
           (forward-line 1))
           (forward-line 1))
          (t (progn (while (looking-at "[ \t]*\\(: \\|\\[\\[\\)")
          (t (progn (while (looking-at "[ \t]*\\(: \\|\\[\\[\\)")
                      (forward-line 1))))))
                      (forward-line 1))))))
-      (point))))
+      (point)))))
 
 
 (defun org-babel-result-to-file (result)
 (defun org-babel-result-to-file (result)
   "Convert RESULT into an `org-mode' link.
   "Convert RESULT into an `org-mode' link.
@@ -1550,7 +1566,7 @@ Later elements of PLISTS override the values of previous element.
 This takes into account some special considerations for certain
 This takes into account some special considerations for certain
 parameters when merging lists."
 parameters when merging lists."
   (let ((results-exclusive-groups
   (let ((results-exclusive-groups
-	 '(("file" "vector" "table" "scalar" "raw" "org"
+	 '(("file" "list" "vector" "table" "scalar" "raw" "org"
             "html" "latex" "code" "pp")
             "html" "latex" "code" "pp")
 	   ("replace" "silent" "append" "prepend")
 	   ("replace" "silent" "append" "prepend")
 	   ("output" "value")))
 	   ("output" "value")))