Skip to content

Instantly share code, notes, and snippets.

@lieutar
Created October 14, 2011 06:29
Show Gist options
  • Save lieutar/1286397 to your computer and use it in GitHub Desktop.
Save lieutar/1286397 to your computer and use it in GitHub Desktop.
elisp で YAML を読むために
(defun yaml2json (yaml)
"Converts a YAML string to a JSON string.
This function is not 100% pure elisp.
This function depends to perl , YAML::Syck and JSON::Syck."
(with-temp-buffer
(let ((proc (start-process
" *yaml2json*"
(current-buffer)
"perl"
"-MYAML::Syck"
"-MJSON::Syck"
"-e"
"print JSON::Syck::Dump(YAML::Syck::Load(join '', <>))"))
(waiting t))
(set-process-sentinel
proc
(lambda (&rest args)
(let ((sig (and (cdr args)(cadr args))))
(when (equal sig "finished\n")
(setq waiting nil)))))
(process-send-string proc yaml)
(process-send-eof proc)
(while waiting (sleep-for 0.1))
(buffer-substring (point-min)(point-max)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment