[Top][All Lists]

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

Re: [O] Org mode and "shunt" exporters?

From: Eric Schulte
Subject: Re: [O] Org mode and "shunt" exporters?
Date: Thu, 12 Dec 2013 12:24:01 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

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.

#+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)))

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

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)))

Attachment: org-to-json.json
Description: application/json

Eric Schulte
PGP: 0x614CA05D

reply via email to

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