ob-matlab.el 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ;;; ob-matlab.el --- org-babel support for matlab evaluation
  2. ;; Copyright (C) Dan Davison
  3. ;; Author: Dan Davison
  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. ;; Functions that are common to org-babel support for matlab and
  24. ;; octave are in org-babel-octave.el
  25. ;;; Requirements:
  26. ;; Matlab
  27. ;; matlab.el required for interactive emacs sessions and matlab-mode
  28. ;; major mode for source code editing buffer
  29. ;; http://matlab-emacs.sourceforge.net/
  30. ;;; Code:
  31. (require 'matlab)
  32. (require 'ob-octave)
  33. (org-babel-add-interpreter "matlab")
  34. (add-to-list 'org-babel-tangle-langs '("matlab" "m" "#!/usr/bin/env matlab"))
  35. (defvar org-babel-matlab-shell-command "matlab -nosplash"
  36. "Shell command to use to run matlab as an external process.")
  37. (defun org-babel-expand-body:matlab (body params &optional processed-params)
  38. "Expand BODY according to PARAMS, return the expanded body." body)
  39. (defvar org-babel-matlab-with-emacs-link nil
  40. "If non-nil use matlab-shell-run-region for session
  41. evaluation. This will use EmacsLink if (matlab-with-emacs-link)
  42. evaluates to a non-nil value.")
  43. (defvar org-babel-matlab-emacs-link-wrapper-method
  44. "%s
  45. if ischar(ans), fid = fopen('%s', 'w'); fprintf(fid, '%%s\\n', ans); fclose(fid);
  46. else, save -ascii %s ans
  47. end
  48. delete('%s')
  49. ")
  50. (defun org-babel-execute:matlab (body params)
  51. "Execute a block of matlab code with org-babel."
  52. (org-babel-execute:octave body params 'matlab))
  53. (defun org-babel-prep-session:matlab (session params)
  54. "Prepare SESSION according to PARAMS."
  55. (org-babel-prep-session:octave session params 'matlab))
  56. (defun org-babel-matlab-initiate-session (&optional session params)
  57. "Create a matlab inferior process buffer. If there is not a
  58. current inferior-process-buffer in SESSION then create. Return
  59. the initialized session."
  60. (org-babel-octave-initiate-session session params 'matlab))
  61. (provide 'ob-matlab)
  62. ;;; ob-matlab.el ends here