emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Mikhail Titov" <mlt@gmx.us>
To: emacs-orgmode@gnu.org
Subject: [babel] ob-octave does not catch EOE from matlabShell on MS Windows
Date: Thu, 24 May 2012 16:02:11 -0500	[thread overview]
Message-ID: <00f901cd39f0$7da5bb00$78f13100$@us> (raw)

Hello!

I was trying hard to set up Matlab R2011a to work with my Emacs 24.1.50.1 (org version is release_7.8.09-532-gb797c8.dirty) and finally I was able to use it from M-shell but not from orgmode yet. I've edited emacs wiki [1] to reflect somewhat working matlab-mode setup on win32. Namely I use [2] as matlab shell.

I have a simple test block like

#+begin_src matlab :session *MATLAB*
a=2
#+end_src

When I try to execute it with C-c C-c , emacs never returns unless I hit C-g. If I do M-x toggle-debug-on-quit RET I see that for some reason it keeps waiting for EOE.

I'd appreciate any suggestion as what to try (other than Octave which has its own tricks on Win32). I'm lost.

[1] http://www.emacswiki.org/emacs/MatlabMode#toc3
[2] http://www.cs.umb.edu/~ram/matlabShell/index.html

--
Mikhail


Here is what I see in *MATLAB* buffer:

----8<-----------------*MATLAB*------------------>8-----
>> a=2
if ischar(ans), fid = fopen('c:/DOCUME~1/user/LOCALS~1/Temp/babel-7560HUp/matlab-7560PPd', 'w'); fprintf(fid, '%s\n', ans); fclose(fid); else, dlmwrite('c:/DOCUME~1/user/LOCALS~1/Temp/babel-7560HUp/matlab-7560PPd', ans, '\t'); end
'org_babel_eoe'

a =

     2

>> >> 
ans =

org_babel_eoe

>>
----8<-----------------*MATLAB*------------------>8-----


----8<-----------------*Bactrace*------------------>8-----
Debugger entered--Lisp error: (quit)
  accept-process-output(#<process MATLAB>)
  (while (progn (goto-char comint-last-input-end) (not (save-excursion (and (re-search-forward (regexp-quote (if matlabp org-babel-octave-eoe-indicator org-babel-octave-eoe-output)) nil t) (re-search-forward comint-prompt-regexp nil t))))) (accept-process-output (get-buffer-process (current-buffer))))
  (progn (goto-char (process-mark (get-buffer-process (current-buffer)))) (let ((start (point)) (end (point-max))) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (insert full-body) (comint-send-input nil t) (while (progn (goto-char comint-last-input-end) (not (save-excursion (and (re-search-forward (regexp-quote ...) nil t) (re-search-forward comint-prompt-regexp nil t))))) (accept-process-output (get-buffer-process (current-buffer)))) (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert dangling-text))
  (unwind-protect (progn (goto-char (process-mark (get-buffer-process (current-buffer)))) (let ((start (point)) (end (point-max))) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (insert full-body) (comint-send-input nil t) (while (progn (goto-char comint-last-input-end) (not (save-excursion (and (re-search-forward ... nil t) (re-search-forward comint-prompt-regexp nil t))))) (accept-process-output (get-buffer-process (current-buffer)))) (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))
  (progn (fset (quote my-filt) (function* (lambda (text) (block my-filt (setq string-buffer (concat string-buffer text)))))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process (current-buffer)))) (let ((start (point)) (end (point-max))) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (insert full-body) (comint-send-input nil t) (while (progn (goto-char comint-last-input-end) (not (save-excursion (and ... ...)))) (accept-process-output (get-buffer-process (current-buffer)))) (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt))))
  (unwind-protect (progn (fset (quote my-filt) (function* (lambda (text) (block my-filt (setq string-buffer (concat string-buffer text)))))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process (current-buffer)))) (let ((start (point)) (end (point-max))) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (insert full-body) (comint-send-input nil t) (while (progn (goto-char comint-last-input-end) (not (save-excursion ...))) (accept-process-output (get-buffer-process (current-buffer)))) (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if --cl-letf-bound-- (fset (quote my-filt) --cl-letf-save--) (fmakunbound (quote my-filt))))
  (let* ((--cl-letf-bound-- (fboundp (quote my-filt))) (--cl-letf-save-- (and --cl-letf-bound-- (symbol-function (quote my-filt))))) (unwind-protect (progn (fset (quote my-filt) (function* (lambda (text) (block my-filt (setq string-buffer ...))))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process ...))) (let ((start ...) (end ...)) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (insert full-body) (comint-send-input nil t) (while (progn (goto-char comint-last-input-end) (not ...)) (accept-process-output (get-buffer-process ...))) (goto-char (process-mark (get-buffer-process ...))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if --cl-letf-bound-- (fset (quote my-filt) --cl-letf-save--) (fmakunbound (quote my-filt)))))
  (letf (((symbol-function (quote my-filt)) (function* (lambda (text) (block my-filt (setq string-buffer (concat string-buffer text))))))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process (current-buffer)))) (let ((start (point)) (end (point-max))) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (insert full-body) (comint-send-input nil t) (while (progn (goto-char comint-last-input-end) (not (save-excursion (and ... ...)))) (accept-process-output (get-buffer-process (current-buffer)))) (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt))))
  (letf* (((symbol-function (quote my-filt)) (function* (lambda (text) (block my-filt (setq string-buffer (concat string-buffer text))))))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process (current-buffer)))) (let ((start (point)) (end (point-max))) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (insert full-body) (comint-send-input nil t) (while (progn (goto-char comint-last-input-end) (not (save-excursion (and ... ...)))) (accept-process-output (get-buffer-process (current-buffer)))) (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt))))
  (flet ((my-filt (text) (setq string-buffer (concat string-buffer text)))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process (current-buffer)))) (let ((start (point)) (end (point-max))) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (insert full-body) (comint-send-input nil t) (while (progn (goto-char comint-last-input-end) (not (save-excursion (and ... ...)))) (accept-process-output (get-buffer-process (current-buffer)))) (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt))))
  (let ((string-buffer "") dangling-text raw) (flet ((my-filt (text) (setq string-buffer (concat string-buffer text)))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process (current-buffer)))) (let ((start (point)) (end (point-max))) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (insert full-body) (comint-send-input nil t) (while (progn (goto-char comint-last-input-end) (not (save-excursion ...))) (accept-process-output (get-buffer-process (current-buffer)))) (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if (and t full-body (string-match (replace-regexp-in-string "\n" "[
\n]+" (regexp-quote (or full-body ""))) string-buffer)) (setq raw (substring string-buffer (match-end 0)))) (split-string string-buffer comint-prompt-regexp))
  (progn (unless (org-babel-comint-buffer-livep session) (error "buffer %s doesn't exist or has no process" session)) (set-buffer session) (let ((string-buffer "") dangling-text raw) (flet ((my-filt (text) (setq string-buffer (concat string-buffer text)))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process ...))) (let ((start ...) (end ...)) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (insert full-body) (comint-send-input nil t) (while (progn (goto-char comint-last-input-end) (not ...)) (accept-process-output (get-buffer-process ...))) (goto-char (process-mark (get-buffer-process ...))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if (and t full-body (string-match (replace-regexp-in-string "\n" "[
\n]+" (regexp-quote (or full-body ""))) string-buffer)) (setq raw (substring string-buffer (match-end 0)))) (split-string string-buffer comint-prompt-regexp)))
  (unwind-protect (progn (unless (org-babel-comint-buffer-livep session) (error "buffer %s doesn't exist or has no process" session)) (set-buffer session) (let ((string-buffer "") dangling-text raw) (flet ((my-filt (text) (setq string-buffer (concat string-buffer text)))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark ...)) (let (... ...) (setq dangling-text ...) (delete-region start end)) (insert full-body) (comint-send-input nil t) (while (progn ... ...) (accept-process-output ...)) (goto-char (process-mark ...)) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if (and t full-body (string-match (replace-regexp-in-string "\n" "[
\n]+" (regexp-quote ...)) string-buffer)) (setq raw (substring string-buffer (match-end 0)))) (split-string string-buffer comint-prompt-regexp))) (set-match-data save-match-data-internal (quote evaporate)))
  (let ((save-match-data-internal (match-data))) (unwind-protect (progn (unless (org-babel-comint-buffer-livep session) (error "buffer %s doesn't exist or has no process" session)) (set-buffer session) (let ((string-buffer "") dangling-text raw) (flet ((my-filt (text) (setq string-buffer ...))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char ...) (let ... ... ...) (insert full-body) (comint-send-input nil t) (while ... ...) (goto-char ...) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if (and t full-body (string-match (replace-regexp-in-string "\n" "[
\n]+" ...) string-buffer)) (setq raw (substring string-buffer (match-end 0)))) (split-string string-buffer comint-prompt-regexp))) (set-match-data save-match-data-internal (quote evaporate))))
  (save-match-data (unless (org-babel-comint-buffer-livep session) (error "buffer %s doesn't exist or has no process" session)) (set-buffer session) (let ((string-buffer "") dangling-text raw) (flet ((my-filt (text) (setq string-buffer (concat string-buffer text)))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process ...))) (let ((start ...) (end ...)) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (insert full-body) (comint-send-input nil t) (while (progn (goto-char comint-last-input-end) (not ...)) (accept-process-output (get-buffer-process ...))) (goto-char (process-mark (get-buffer-process ...))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if (and t full-body (string-match (replace-regexp-in-string "\n" "[
\n]+" (regexp-quote (or full-body ""))) string-buffer)) (setq raw (substring string-buffer (match-end 0)))) (split-string string-buffer comint-prompt-regexp)))
  (save-excursion (save-match-data (unless (org-babel-comint-buffer-livep session) (error "buffer %s doesn't exist or has no process" session)) (set-buffer session) (let ((string-buffer "") dangling-text raw) (flet ((my-filt (text) (setq string-buffer (concat string-buffer text)))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark ...)) (let (... ...) (setq dangling-text ...) (delete-region start end)) (insert full-body) (comint-send-input nil t) (while (progn ... ...) (accept-process-output ...)) (goto-char (process-mark ...)) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if (and t full-body (string-match (replace-regexp-in-string "\n" "[
\n]+" (regexp-quote ...)) string-buffer)) (setq raw (substring string-buffer (match-end 0)))) (split-string string-buffer comint-prompt-regexp))))
  (org-babel-comint-in-buffer session (let ((string-buffer "") dangling-text raw) (flet ((my-filt (text) (setq string-buffer (concat string-buffer text)))) (add-hook (quote comint-output-filter-functions) (quote my-filt)) (unwind-protect (progn (goto-char (process-mark (get-buffer-process ...))) (let ((start ...) (end ...)) (setq dangling-text (buffer-substring start end)) (delete-region start end)) (insert full-body) (comint-send-input nil t) (while (progn (goto-char comint-last-input-end) (not ...)) (accept-process-output (get-buffer-process ...))) (goto-char (process-mark (get-buffer-process ...))) (insert dangling-text)) (remove-hook (quote comint-output-filter-functions) (quote my-filt)))) (if (and t full-body (string-match (replace-regexp-in-string "\n" "[
\n]+" (regexp-quote (or full-body ""))) string-buffer)) (setq raw (substring string-buffer (match-end 0)))) (split-string string-buffer comint-prompt-regexp)))
  (org-babel-comint-with-output (session (if matlabp org-babel-octave-eoe-indicator org-babel-octave-eoe-output) t full-body) (insert full-body) (comint-send-input nil t))
  (if (and matlabp org-babel-matlab-with-emacs-link) (save-window-excursion (with-temp-buffer (insert full-body) (write-region "" (quote ignored) wait-file nil nil nil (quote excl)) (matlab-shell-run-region (point-min) (point-max)) (message "Waiting for Matlab Emacs Link") (while (file-exists-p wait-file) (sit-for 0.01)) "")) (org-babel-comint-with-output (session (if matlabp org-babel-octave-eoe-indicator org-babel-octave-eoe-output) t full-body) (insert full-body) (comint-send-input nil t)))
  (let* ((tmp-file (org-babel-temp-file (if matlabp "matlab-" "octave-"))) (wait-file (org-babel-temp-file "matlab-emacs-link-wait-signal-")) (full-body (case result-type (output (mapconcat (function org-babel-chomp) (list body org-babel-octave-eoe-indicator) "\n")) (value (if (and matlabp org-babel-matlab-with-emacs-link) (concat (format org-babel-matlab-emacs-link-wrapper-method body ... ... wait-file) "\n") (mapconcat (function org-babel-chomp) (list ... org-babel-octave-eoe-indicator) "\n"))))) (raw (if (and matlabp org-babel-matlab-with-emacs-link) (save-window-excursion (with-temp-buffer (insert full-body) (write-region "" (quote ignored) wait-file nil nil nil (quote excl)) (matlab-shell-run-region (point-min) (point-max)) (message "Waiting for Matlab Emacs Link") (while (file-exists-p wait-file) (sit-for 0.01)) "")) (org-babel-comint-with-output (session (if matlabp org-babel-octave-eoe-indicator org-babel-octave-eoe-output) t full-body) (insert full-body) (comint-send-input nil t)))) results) (case result-type (value (org-babel-octave-import-elisp-from-file tmp-file)) (output (progn (setq results (if matlabp (cdr (reverse ...)) (cdr (member org-babel-octave-eoe-output ...)))) (mapconcat (function identity) (reverse results) "\n")))))
  org-babel-octave-evaluate-session("*MATLAB*" "a=2" value matlab)
  (if session (org-babel-octave-evaluate-session session body result-type matlabp) (org-babel-octave-evaluate-external-process body result-type matlabp))
  org-babel-octave-evaluate("*MATLAB*" "a=2" value matlab)
  (let* ((session (funcall (intern (format "org-babel-%s-initiate-session" (if matlabp "matlab" "octave"))) (cdr (assoc :session params)) params)) (vars (mapcar (function cdr) (org-babel-get-header params :var))) (result-params (cdr (assoc :result-params params))) (result-type (cdr (assoc :result-type params))) (out-file (cdr (assoc :file params))) (full-body (org-babel-expand-body:generic body params (org-babel-variable-assignments:octave params))) (result (org-babel-octave-evaluate session (if (org-babel-octave-graphical-output-file params) (mapconcat (quote identity) (list "set (0, \"defaultfigurevisible\", \"off\");" full-body (format "print -dpng %s" ...)) "\n") full-body) result-type matlabp))) (if (org-babel-octave-graphical-output-file params) nil (org-babel-reassemble-table result (org-babel-pick-name (cdr (assoc :colname-names params)) (cdr (assoc :colnames params))) (org-babel-pick-name (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params))))))
  org-babel-execute:octave("a=2" ((:comments . "") (:shebang . "") (:cache . "no") (:padline . "") (:noweb . "no") (:tangle . "no") (:exports . "code") (:results . "replace") (:hlines . "no") (:padnewline . "yes") (:session . "*MATLAB*") (:result-type . value) (:result-params "replace") (:rowname-names) (:colname-names)) matlab)
  org-babel-execute:matlab("a=2" ((:comments . "") (:shebang . "") (:cache . "no") (:padline . "") (:noweb . "no") (:tangle . "no") (:exports . "code") (:results . "replace") (:hlines . "no") (:padnewline . "yes") (:session . "*MATLAB*") (:result-type . value) (:result-params "replace") (:rowname-names) (:colname-names)))
  org-babel-execute-src-block(nil ("matlab" "a=2" ((:comments . "") (:shebang . "") (:cache . "no") (:padline . "") (:noweb . "no") (:tangle . "no") (:exports . "code") (:results . "replace") (:hlines . "no") (:padnewline . "yes") (:session . "*MATLAB*") (:result-type . value) (:result-params "replace") (:rowname-names) (:colname-names)) "" nil 0))
  org-babel-execute-src-block-maybe()
  org-babel-execute-maybe()
  org-babel-execute-safely-maybe()
  run-hook-with-args-until-success(org-babel-execute-safely-maybe)
  org-ctrl-c-ctrl-c(nil)
  call-interactively(org-ctrl-c-ctrl-c nil nil)
----8<-----------------*Bactrace*------------------>8-----

             reply	other threads:[~2012-05-24 21:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-24 21:02 Mikhail Titov [this message]
2012-05-24 21:30 ` [babel] ob-octave does not catch EOE from matlabShell on MS Windows Mikhail Titov
2012-05-25 16:31   ` Mikhail Titov
2012-05-25 16:52     ` [babel, patch] " Mikhail Titov
2012-05-28 15:56       ` Eric Schulte
2012-05-28 18:23         ` Achim Gratz
2012-05-30 15:58           ` Mikhail Titov
2012-05-30 16:05             ` Eric Schulte
2012-05-30 16:58             ` Achim Gratz
2012-05-29 17:00         ` Mikhail Titov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='00f901cd39f0$7da5bb00$78f13100$@us' \
    --to=mlt@gmx.us \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).