emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [RFC] [PATCH] [babel] read description lists as lists of lists


From: Aaron Ecay
Subject: [O] [RFC] [PATCH] [babel] read description lists as lists of lists
Date: Fri, 19 Sep 2014 15:17:54 -0400
User-agent: Notmuch/0.18.1+51~gbbbdf04 (http://notmuchmail.org) Emacs/24.4.50.2 (x86_64-unknown-linux-gnu)

Hello all,

The attached patch makes babel read description lists as lists of the
following format: (("term" "description") ...).  The present default is
to simply read in the text of each list item, yielding:
("term :: description" ...).

Of course, it’s possible to interconvert between the two formats, but I
think the greater structure of this proposal makes things easier for
babel authors.  (Another way of thinking of the proposal is that it
treats description lists like two-column tables.)

What do people think?

Thanks,

-- 
Aaron Ecay
>From a7e01675f2c89fb648e528c3efe535ed0b2389f1 Mon Sep 17 00:00:00 2001
From: Aaron Ecay <address@hidden>
Date: Fri, 19 Sep 2014 14:39:26 -0400
Subject: [PATCH] ob-core.el: Read description lists as lisp lists.

* lisp/ob-core.el (org-babel-read-list): Read description lists as
lisp lists.

This allows description lists to be used as structured input to a
babel block.
---
 lisp/ob-core.el | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index e01c4d2..f1661cb 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2035,9 +2035,21 @@ following the source block."
           (org-table-to-lisp)))
 
 (defun org-babel-read-list ()
-  "Read the list at `point' into emacs-lisp."
-  (mapcar (lambda (el) (org-babel-read el 'inhibit-lisp-eval))
-         (mapcar #'cadr (cdr (org-list-parse-list)))))
+  "Read the list at `point' into emacs-lisp.
+
+The result is a list of strings \(the list items), unless the
+input list is a description list.  In that case, the result will
+be a list of lists; each of the latter lists will have two
+elements: the term and the description."
+  (let* ((parsed (org-list-parse-list))
+        (elements (mapcar #'cadr (cdr parsed))))
+    (if (eq (car parsed) 'descriptive)
+       (mapcar (lambda (el)
+                 (let ((s (split-string el " :: ")))
+                   (list (nth 0 s) (mapconcat #'identity (cdr s) " :: "))))
+               elements)
+      (mapcar (lambda (el) (org-babel-read el 'inhibit-lisp-eval))
+             elements))))
 
 (defvar org-link-types-re)
 (defun org-babel-read-link ()
-- 
2.1.0


reply via email to

[Prev in Thread] Current Thread [Next in Thread]