litorgy-lisp.el 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ;;; litorgy-lisp.el --- litorgy functions for lisp code evaluation
  2. ;; Copyright (C) 2009 Eric Schulte, Dan Davison, Austin F. Frank
  3. ;; Author: Eric Schulte, Dan Davison, Austin F. Frank
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 0.01
  7. ;;; License:
  8. ;; This program is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 3, or (at your option)
  11. ;; any later version.
  12. ;;
  13. ;; This program is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;;
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. ;; Boston, MA 02110-1301, USA.
  22. ;;; Commentary:
  23. ;; Litorgy support for evaluating lisp code
  24. ;;; Code:
  25. (require 'litorgy)
  26. (litorgy-add-interpreter "emacs-lisp")
  27. (defun litorgy-execute:emacs-lisp (body params)
  28. "Execute a block of emacs-lisp code with litorgy. This
  29. function is called by `litorgy-execute-src-block'."
  30. (save-window-excursion
  31. (let ((vars (litorgy-reference-variables params))
  32. (print-level nil) (print-length nil) results)
  33. (message "prefix")
  34. (message (format "-%S-" body))
  35. (message (format "%S" (stringp body)))
  36. (message (format "vars = %S" vars))
  37. (setq vars (mapcar (lambda (pair)
  38. (list (intern (car pair))
  39. (mapcar (lambda (row)
  40. (mapcar #'litorgy-read-cell row))
  41. (cdr pair))))
  42. vars))
  43. (message (format "let = %S" vars))
  44. ;; need to find a way of assigning the variables in vars for the
  45. ;; context in which body is executed
  46. (message "executing emacs-lisp code block...")
  47. (format "%S"
  48. (eval `(let ,(mapcar (lambda (var)
  49. `(,(car var) ',(cdr var)))
  50. vars)
  51. (message "inside")
  52. (message (format "- %S -" table))
  53. (message (format "- %S -" body))
  54. ,(read body)))))))
  55. (defun litorgy-read-cell (cell)
  56. "Convert the string value of CELL to a number if appropriate.
  57. Otherwise if cell looks like a list (meaning it starts with a
  58. '(') then read it as lisp, otherwise return it unmodified as a
  59. string.
  60. This is taken almost directly from `org-read-prop'."
  61. (if (and (stringp cell) (not (equal cell "")))
  62. (let ((out (string-to-number cell)))
  63. (if (equal out 0)
  64. (if (or (equal "(" (substring cell 0 1))
  65. (equal "'" (substring cell 0 1)))
  66. (read cell)
  67. (if (string-match "^\\(+0\\|-0\\|0\\)$" cell)
  68. 0
  69. (progn (set-text-properties 0 (length cell) nil cell)
  70. cell)))
  71. out))
  72. cell))
  73. (provide 'litorgy-lisp)
  74. ;;; litorgy-lisp.el ends here