ob-matlab.el 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. ;;; ob-matlab.el --- org-babel support for matlab evaluation
  2. ;; Copyright (C) 2010 Free Software Foundation, Inc.
  3. ;; Author: Dan Davison
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 0.01
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs 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 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;; Functions that are common to org-babel support for matlab and
  20. ;; octave are in org-babel-octave.el
  21. ;;; Requirements:
  22. ;; Matlab
  23. ;; matlab.el required for interactive emacs sessions and matlab-mode
  24. ;; major mode for source code editing buffer
  25. ;; http://matlab-emacs.sourceforge.net/
  26. ;;; Code:
  27. (require 'matlab)
  28. (require 'ob-octave)
  29. (defvar org-babel-default-header-args:matlab '())
  30. (defvar org-babel-matlab-shell-command "matlab -nosplash"
  31. "Shell command to use to run matlab as an external process.")
  32. (defun org-babel-expand-body:matlab (body params &optional processed-params)
  33. "Expand BODY according to PARAMS, return the expanded body." body)
  34. (defvar org-babel-matlab-with-emacs-link nil
  35. "If non-nil use matlab-shell-run-region for session
  36. evaluation. This will use EmacsLink if (matlab-with-emacs-link)
  37. evaluates to a non-nil value.")
  38. (defvar org-babel-matlab-emacs-link-wrapper-method
  39. "%s
  40. if ischar(ans), fid = fopen('%s', 'w'); fprintf(fid, '%%s\\n', ans); fclose(fid);
  41. else, save -ascii %s ans
  42. end
  43. delete('%s')
  44. ")
  45. (defun org-babel-execute:matlab (body params)
  46. "Execute a block of matlab code with org-babel."
  47. (org-babel-execute:octave body params 'matlab))
  48. (defun org-babel-prep-session:matlab (session params)
  49. "Prepare SESSION according to PARAMS."
  50. (org-babel-prep-session:octave session params 'matlab))
  51. (defun org-babel-matlab-initiate-session (&optional session params)
  52. "Create a matlab inferior process buffer. If there is not a
  53. current inferior-process-buffer in SESSION then create. Return
  54. the initialized session."
  55. (org-babel-octave-initiate-session session params 'matlab))
  56. (provide 'ob-matlab)
  57. ;; arch-tag: 6b234299-c1f7-4eb1-ace8-7b93344065ac
  58. ;;; ob-matlab.el ends here