diff options
author | Eric Schulte <schulte.eric@gmail.com> | 2010-11-17 16:42:52 -0700 |
---|---|---|
committer | Eric Schulte <schulte.eric@gmail.com> | 2010-11-17 16:47:55 -0700 |
commit | 88947588bc8436b5d36d76d6d24cc5d410ad9962 (patch) | |
tree | d6279f9d260bf10fb674f2388ce40cac79722037 | |
parent | 4fca6b54b518724fab7466f891aa2525699d3ce5 (diff) | |
download | org-mode-88947588bc8436b5d36d76d6d24cc5d410ad9962.tar.gz |
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.
-rw-r--r-- | doc/org.texi | 7 | ||||
-rw-r--r-- | lisp/ob-ref.el | 2 | ||||
-rw-r--r-- | lisp/ob.el | 26 |
3 files changed, 28 insertions, 7 deletions
diff --git a/doc/org.texi b/doc/org.texi index bef8fa3..06583d7 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -11758,8 +11758,8 @@ another by commas, as shown in the following example. @node results, file, var, Specific header arguments @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 @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 returned, it will be converted into a table with one row and one column. 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} The results should be interpreted literally---they will not be converted into a table. The results will be inserted into the Org-mode diff --git a/lisp/ob-ref.el b/lisp/ob-ref.el index 3dee798..dd59b39 100644 --- a/lisp/ob-ref.el +++ b/lisp/ob-ref.el @@ -147,6 +147,7 @@ the variable." (case type ('results-line (org-babel-read-result)) ('table (org-babel-read-table)) + ('list (org-babel-read-list)) ('file (org-babel-read-link)) ('source-block (org-babel-execute-src-block nil nil 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. Supported reference types are tables and source blocks." (cond ((org-at-table-p) 'table) + ((org-list-in-item-p-with-indent 0) 'list) ((looking-at "^[ \t]*#\\+BEGIN_SRC") 'source-block) ((looking-at org-bracket-link-regexp) 'file) ((looking-at org-babel-result-regexp) 'results-line))) @@ -1307,6 +1307,7 @@ following the source block." (let ((case-fold-search t) result-string) (cond ((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-block-regexp) (org-babel-trim (match-string 4))) ((looking-at "^[ \t]*: ") @@ -1332,6 +1333,10 @@ following the source block." (mapcar #'org-babel-read row))) (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) (defun org-babel-read-link () "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 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 formatted text. @@ -1430,6 +1437,13 @@ code ---- the results are extracted in the syntax of the source (cond ;; do nothing for an empty result ((= (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 ((not (stringp result)) (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 () "Return the point at the end of the current set of results" (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)) (cond ((looking-at "[ \t]*#\\+begin_latex") @@ -1500,7 +1516,7 @@ code ---- the results are extracted in the syntax of the source (forward-line 1)) (t (progn (while (looking-at "[ \t]*\\(: \\|\\[\\[\\)") (forward-line 1)))))) - (point)))) + (point))))) (defun org-babel-result-to-file (result) "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 parameters when merging lists." (let ((results-exclusive-groups - '(("file" "vector" "table" "scalar" "raw" "org" + '(("file" "list" "vector" "table" "scalar" "raw" "org" "html" "latex" "code" "pp") ("replace" "silent" "append" "prepend") ("output" "value"))) |