ob-matlab.el 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. (defvar org-babel-matlab-shell-command "matlab -nosplash"
  34. "Shell command to use to run matlab as an external process.")
  35. (defun org-babel-expand-body:matlab (body params &optional processed-params)
  36. "Expand BODY according to PARAMS, return the expanded body." body)
  37. (defvar org-babel-matlab-with-emacs-link nil
  38. "If non-nil use matlab-shell-run-region for session
  39. evaluation. This will use EmacsLink if (matlab-with-emacs-link)
  40. evaluates to a non-nil value.")
  41. (defvar org-babel-matlab-emacs-link-wrapper-method
  42. "%s
  43. if ischar(ans), fid = fopen('%s', 'w'); fprintf(fid, '%%s\\n', ans); fclose(fid);
  44. else, save -ascii %s ans
  45. end
  46. delete('%s')
  47. ")
  48. (defun org-babel-execute:matlab (body params)
  49. "Execute a block of matlab code with org-babel."
  50. (org-babel-execute:octave body params 'matlab))
  51. (defun org-babel-prep-session:matlab (session params)
  52. "Prepare SESSION according to PARAMS."
  53. (org-babel-prep-session:octave session params 'matlab))
  54. (defun org-babel-matlab-initiate-session (&optional session params)
  55. "Create a matlab inferior process buffer. If there is not a
  56. current inferior-process-buffer in SESSION then create. Return
  57. the initialized session."
  58. (org-babel-octave-initiate-session session params 'matlab))
  59. (provide 'ob-matlab)
  60. ;;; ob-matlab.el ends here