From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: Org mode and "shunt" exporters? Date: Thu, 12 Dec 2013 12:24:01 -0700 Message-ID: <87txedna9a.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VrBt1-0001c7-AT for emacs-orgmode@gnu.org; Thu, 12 Dec 2013 14:25:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VrBsw-0005X6-Ny for emacs-orgmode@gnu.org; Thu, 12 Dec 2013 14:25:27 -0500 Received: from mail-pb0-x231.google.com ([2607:f8b0:400e:c01::231]:45154) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VrBsw-0005Wi-BY for emacs-orgmode@gnu.org; Thu, 12 Dec 2013 14:25:22 -0500 Received: by mail-pb0-f49.google.com with SMTP id jt11so1075135pbb.36 for ; Thu, 12 Dec 2013 11:25:21 -0800 (PST) In-Reply-To: (John Kitchin's message of "Thu, 12 Dec 2013 12:22:38 -0500") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: John Kitchin Cc: Brett Viren , "emacs-orgmode@gnu.org" --=-=-= Content-Type: text/plain Here's a quick shot at using Common Lisp's cl-json package as a bridge between Emacs-lisp and JSON. The Org-mode file with necessary the code is attached (it requires a running lisp process w/cl-json loaded), as well as it's json conversion. --=-=-= Content-Type: text/x-org Content-Disposition: inline; filename=org-to-json.org #+Title: Org to JSON Use Common Lisp as a bridge between Org-mode and JSON. A three step process. 1. First we'll define an Emacs Lisp function to write an Org-mode buffer to a file as Emacs Lisp. #+begin_src emacs-lisp (defun write-org-to-emacs-lisp-file (&optional path) (interactive "Foutput file: ") (cl-flet ((obj-to-path (obj path) (with-temp-file path (prin1 obj (current-buffer))))) (obj-to-path (org-element-parse-buffer) path))) #+end_src 2. Small hack to fix the circular =:parent= issue. #+begin_src sh :var path="/tmp/org-to-json.el" :results none sed 's/#[0-9]\+/:not-the-parent/g' -i $path #+end_src 3. Finally use Common Lisp to read the hacked up Emacs Lisp and use [[http://common-lisp.net/projects/cl-json][cl-json]] to print that as JSON. #+name: emacs-lisp-to-json #+headers: :var in-path="/tmp/org-to-json.el" #+headers: :var out-path="/tmp/org-to-json.json" #+begin_src lisp :results none (with-open-file (in in-path) (with-open-file (out out-path :direction :output) (cl-json:encode-json (read in) out))) #+end_src --=-=-= Content-Type: application/json Content-Disposition: attachment; filename=org-to-json.json Content-Transfer-Encoding: base64 WyJvcmdEYXRhIixudWxsLFsic2VjdGlvbiIsWyJiZWdpbiIsMSwiZW5kIiwxMTkzLCJjb250ZW50 c0JlZ2luIiwxLCJjb250ZW50c0VuZCIsMTE5MywicG9zdEJsYW5rIiwwLCJwYXJlbnQiLCJub3RU aGVQYXJlbnQiXSxbImtleXdvcmQiLFsia2V5IiwiVElUTEUiLCJ2YWx1ZSIsIk9yZyB0byBKU09O IiwiYmVnaW4iLDEsImVuZCIsMjMsInBvc3RCbGFuayIsMSwicG9zdEFmZmlsaWF0ZWQiLDEsInBh cmVudCIsIm5vdFRoZVBhcmVudCJdXSxbInBhcmFncmFwaCIsWyJiZWdpbiIsMjMsImVuZCIsNzks ImNvbnRlbnRzQmVnaW4iLDIzLCJjb250ZW50c0VuZCIsNzgsInBvc3RCbGFuayIsMSwicG9zdEFm ZmlsaWF0ZWQiLDIzLCJwYXJlbnQiLCJub3RUaGVQYXJlbnQiXSxbIlVzZSBDb21tb24gTGlzcCBh cyBhIGJyaWRnZSBiZXR3ZWVuIE9yZy1tb2RlIGFuZCBKU09OLlxuIiwwLDU1LFsicGFyZW50Iiwi bm90VGhlUGFyZW50Il1dXSx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lZ2luIiw4NDQsImNvbnRlbnRzRW5kIiw4NTEsInBvc3RCbGFu ayIsMSwicGFyZW50Iiwibm90VGhlUGFyZW50Il0sWyJjbC1qc29uIiwwLDcsWyJwYXJlbnQiLCJu b3RUaGVQYXJlbnQiXV1dLFsidG8gcHJpbnQgdGhhdCBhcyBKU09OLlxuIiwwLDIzLFsicGFyZW50 Iiwibm90VGhlUGFyZW50Il1dXSxbInNyY0Jsb2NrIixbImxhbmd1YWdlIiwibGlzcCIsInN3aXRj aGVzIixudWxsLCJwYXJhbWV0ZXJzIiwiOnJlc3VsdHMgbm9uZSIsImJlZ2luIiw4NzcsImVuZCIs MTE5MywibnVtYmVyTGluZXMiLG51bGwsInByZXNlcnZlSW5kZW50IixudWxsLCJyZXRhaW5MYWJl bHMiLHRydWUsInVzZUxhYmVscyIsdHJ1ZSwibGFiZWxGbXQiLG51bGwsInZhbHVlIiwiICAod2l0 aC1vcGVuLWZpbGUgKGluIGluLXBhdGgpXG4gICAgKHdpdGgtb3Blbi1maWxlIChvdXQgb3V0LXBh dGggOmRpcmVjdGlvbiA6b3V0cHV0KVxuICAgICAgKGNsLWpzb246ZW5jb2RlLWpzb24gKHJlYWQg aW4pIG91dCkpKVxuIiwicG9zdEJsYW5rIiwwLCJwb3N0QWZmaWxpYXRlZCIsMTAwOCwibmFtZSIs ImVtYWNzLWxpc3AtdG8tanNvbiIsImhlYWRlciIsWyI6dmFyIG91dC1wYXRoPVwiXC90bXBcL29y Zy10by1qc29uLmpzb25cIiIsIjp2YXIgaW4tcGF0aD1cIlwvdG1wXC9vcmctdG8tanNvbi5lbFwi Il0sInBhcmVudCIsIm5vdFRoZVBhcmVudCJdXV1dXV0= --=-=-= Content-Type: text/plain -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D --=-=-=--