ob-smiles.el 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ;;; ob-smiles.el --- Org-mode Babel support for SMILES.
  2. ;;; -*- coding: utf-8 -*-
  3. ;; Keywords: org babel SMILES
  4. ;; Version: 0.0.1
  5. ;; Package-Requires: ((smiles-mode "0.0.1") (org "8"))
  6. ;;; Commentary:
  7. ;;; I copy code from:
  8. ;;; http://kitchingroup.cheme.cmu.edu/blog/2016/03/26/A-molecule-link-for-org-mode
  9. ;; Author: John Kitchin [jkitchin@andrew.cmu.edu]
  10. ;; Maintainer: stardiviner [numbchild@gmail.com]
  11. ;;; Code:
  12. ;; Org-mode Babel
  13. (defun org-babel-execute:smiles (body params)
  14. "Execute SMILES babel `BODY' with `PARAMS'."
  15. (shell-command-to-string
  16. (format "obabel -:\"%s\" -osvg 2> /dev/null" body)))
  17. ;; Org-mode link
  18. (defun molecule-jump (name)
  19. "Jump to molecule `NAME' definition."
  20. (org-mark-ring-push)
  21. (org-link-open-from-string (format "[[%s]]" path)))
  22. (defun molecule-export (path desc backend)
  23. "Export molecule to HTML format on `PATH' with `DESC' and `BACKEND'."
  24. (let ((name (save-window-excursion
  25. (molecule-jump path)
  26. (org-element-property :name (org-element-context)))))
  27. (cond
  28. ((eq 'html backend)
  29. (format "<a href=\"#%s\">%s</a>" name name)))))
  30. (org-add-link-type
  31. "molecule"
  32. 'molecule-jump
  33. 'molecule-export)
  34. ;; org-mode element
  35. (org-element-map (org-element-parse-buffer)
  36. 'src-block
  37. (lambda (src)
  38. (when (string= "smiles" (org-element-property :language src))
  39. (org-element-property :name src))))
  40. (provide 'ob-smiles)
  41. ;;; ob-smiles.el ends here