all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [babel] ob-octave does not catch EOE from matlabShell on MS Windows
@ 2012-05-24 21:02 Mikhail Titov
  2012-05-24 21:30 ` Mikhail Titov
  0 siblings, 1 reply; 10+ messages in thread
From: Mikhail Titov @ 2012-05-24 21:02 UTC (permalink / raw)
  To: emacs-orgmode

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-----

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [babel] ob-octave does not catch EOE from matlabShell on MS Windows
  2012-05-24 21:02 [babel] ob-octave does not catch EOE from matlabShell on MS Windows Mikhail Titov
@ 2012-05-24 21:30 ` Mikhail Titov
  2012-05-25 16:31   ` Mikhail Titov
  0 siblings, 1 reply; 10+ messages in thread
From: Mikhail Titov @ 2012-05-24 21:30 UTC (permalink / raw)
  To: emacs-orgmode

> -----Original Message-----
> From: emacs-orgmode-bounces+mlt=gmx.us@gnu.org [mailto:emacs-orgmode-
> bounces+mlt=gmx.us@gnu.org] On Behalf Of Mikhail Titov
> Sent: Thursday, May 24, 2012 4:02 PM
> To: emacs-orgmode@gnu.org
> Subject: [O] [babel] ob-octave does not catch EOE from matlabShell on MS
> Windows
> 
> ...
>
> 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.
>
> ...
> 
> 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-----

I feel like it is about

(defvar org-babel-octave-eoe-output "ans = org_babel_eoe")

as Matlab's return has newlines. I'm not sure so far how to make universal regex for re-search-forward in org-babel-comint-with-output .

Mikhail
 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [babel] ob-octave does not catch EOE from matlabShell on MS Windows
  2012-05-24 21:30 ` Mikhail Titov
@ 2012-05-25 16:31   ` Mikhail Titov
  2012-05-25 16:52     ` [babel, patch] " Mikhail Titov
  0 siblings, 1 reply; 10+ messages in thread
From: Mikhail Titov @ 2012-05-25 16:31 UTC (permalink / raw)
  To: emacs-orgmode

> -----Original Message-----
> From: emacs-orgmode-bounces+mlt=gmx.us@gnu.org [mailto:emacs-orgmode-
> bounces+mlt=gmx.us@gnu.org] On Behalf Of Mikhail Titov
> Sent: Thursday, May 24, 2012 4:31 PM
> To: emacs-orgmode@gnu.org
> Subject: Re: [O] [babel] ob-octave does not catch EOE from matlabShell on MS
> Windows
> 
> > ...
> >
> > 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.

It looks like org-babel-octave-eoe-output and org-babel-octave-eoe-indicator were swapped around in org-babel-octave-evaluate-session .

I have the following in dot emacs

(setq org-babel-octave-eoe-output "
ans =

org_babel_eoe

")

M.

> >
> > ...
> >
> > 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-----
> 
> I feel like it is about
> 
> (defvar org-babel-octave-eoe-output "ans = org_babel_eoe")
> 
> as Matlab's return has newlines. I'm not sure so far how to make universal
> regex for re-search-forward in org-babel-comint-with-output .
> 
> Mikhail
> 
> 
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [babel, patch] ob-octave does not catch EOE from matlabShell on MS Windows
  2012-05-25 16:31   ` Mikhail Titov
@ 2012-05-25 16:52     ` Mikhail Titov
  2012-05-28 15:56       ` Eric Schulte
  0 siblings, 1 reply; 10+ messages in thread
From: Mikhail Titov @ 2012-05-25 16:52 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1287 bytes --]

> -----Original Message-----
> From: emacs-orgmode-bounces+mlt=gmx.us@gnu.org [mailto:emacs-orgmode-
> bounces+mlt=gmx.us@gnu.org] On Behalf Of Mikhail Titov
> Sent: Friday, May 25, 2012 11:31 AM
> To: emacs-orgmode@gnu.org
> Subject: Re: [O] [babel] ob-octave does not catch EOE from matlabShell on MS
> Windows
> 
> > > ...
> > >
> > > 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.
> 
> It looks like org-babel-octave-eoe-output and org-babel-octave-eoe-indicator
> were swapped around in org-babel-octave-evaluate-session .
> 
> I have the following in dot emacs
> 
> (setq org-babel-octave-eoe-output "
> ans =
> 
> org_babel_eoe
> 
> ")

For the sake of completeness I'm attaching the patch. Also one should override

(setq org-babel-matlab-emacs-link-wrapper-method
   "%s
if ischar(ans), fid = fopen('%s', 'w'); fprintf(fid, '%%s\\n', ans); fclose(fid); else, save -ascii %s ans ; end
delete('%s')
")

as matlabShell does not like commands split across multiple lines.

M.


[-- Attachment #2: ob-octave_matlab.patch --]
[-- Type: application/octet-stream, Size: 537 bytes --]

diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el
index 9e85757..8bc48bc 100644
--- a/lisp/ob-octave.el
+++ b/lisp/ob-octave.el
@@ -231,8 +231,8 @@ value of the last statement in BODY, as elisp."
 		(org-babel-comint-with-output
 		    (session
 		     (if matlabp
-			 org-babel-octave-eoe-indicator
-		       org-babel-octave-eoe-output)
+			 org-babel-octave-eoe-output
+		       org-babel-octave-eoe-indicator)
 		     t full-body)
 		  (insert full-body) (comint-send-input nil t)))) results)
     (case result-type

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [babel, patch] ob-octave does not catch EOE from matlabShell on MS Windows
  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-29 17:00         ` Mikhail Titov
  0 siblings, 2 replies; 10+ messages in thread
From: Eric Schulte @ 2012-05-28 15:56 UTC (permalink / raw)
  To: Mikhail Titov; +Cc: emacs-orgmode

"Mikhail Titov" <mlt@gmx.us> writes:

>> -----Original Message-----
>> From: emacs-orgmode-bounces+mlt=gmx.us@gnu.org [mailto:emacs-orgmode-
>> bounces+mlt=gmx.us@gnu.org] On Behalf Of Mikhail Titov
>> Sent: Friday, May 25, 2012 11:31 AM
>> To: emacs-orgmode@gnu.org
>> Subject: Re: [O] [babel] ob-octave does not catch EOE from matlabShell on MS
>> Windows
>> 
>> > > ...
>> > >
>> > > 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.
>> 
>> It looks like org-babel-octave-eoe-output and org-babel-octave-eoe-indicator
>> were swapped around in org-babel-octave-evaluate-session .
>> 
>> I have the following in dot emacs
>> 
>> (setq org-babel-octave-eoe-output "
>> ans =
>> 
>> org_babel_eoe
>> 
>> ")
>
> For the sake of completeness I'm attaching the patch. Also one should override
>
> (setq org-babel-matlab-emacs-link-wrapper-method
>    "%s
> if ischar(ans), fid = fopen('%s', 'w'); fprintf(fid, '%%s\\n', ans); fclose(fid); else, save -ascii %s ans ; end
> delete('%s')
> ")
>
> as matlabShell does not like commands split across multiple lines.
>
> M.
>
>

Hi Mikhail,

Thanks for sending along the patch and the variable re-definition.  If I
understand correctly then the patch should be applied for any system,
but the variable definition need only be applied on windows systems.  Is
that correct?

Can anyone confirm that matlab/octave code blocks are still functional
on a GNU/Linux machine after the above patch and redefinition have been
applied?  I do not use octave/matlab myself and can't verify this.

If they don't break anything I'm happy to apply these patches.

Thanks,

-- 
Eric Schulte
http://cs.unm.edu/~eschulte

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [babel, patch] ob-octave does not catch EOE from matlabShell on MS Windows
  2012-05-28 15:56       ` Eric Schulte
@ 2012-05-28 18:23         ` Achim Gratz
  2012-05-30 15:58           ` Mikhail Titov
  2012-05-29 17:00         ` Mikhail Titov
  1 sibling, 1 reply; 10+ messages in thread
From: Achim Gratz @ 2012-05-28 18:23 UTC (permalink / raw)
  To: emacs-orgmode

Eric Schulte writes:
> Thanks for sending along the patch and the variable re-definition.  If I
> understand correctly then the patch should be applied for any system,
> but the variable definition need only be applied on windows systems.  Is
> that correct?

The variable re-definition seems to be be needed for matlab-shell, I
don't know if that would be restricted to Windows.

> Can anyone confirm that matlab/octave code blocks are still functional
> on a GNU/Linux machine after the above patch and redefinition have been
> applied?  I do not use octave/matlab myself and can't verify this.

The octave tests still pass on openSUSE with the patch applied along
with all the other tests (except R, since I'm missing ESS).


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Wavetables for the Waldorf Blofeld:
http://Synth.Stromeko.net/Downloads.html#BlofeldUserWavetables

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [babel, patch] ob-octave does not catch EOE from matlabShell on MS Windows
  2012-05-28 15:56       ` Eric Schulte
  2012-05-28 18:23         ` Achim Gratz
@ 2012-05-29 17:00         ` Mikhail Titov
  1 sibling, 0 replies; 10+ messages in thread
From: Mikhail Titov @ 2012-05-29 17:00 UTC (permalink / raw)
  To: 'Eric Schulte'; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2983 bytes --]

> -----Original Message-----
> From: Eric Schulte [mailto:eric.schulte@gmx.com]
> Sent: Monday, May 28, 2012 10:57 AM
> To: Mikhail Titov
> Cc: emacs-orgmode@gnu.org
> Subject: Re: [O] [babel, patch] ob-octave does not catch EOE from
matlabShell
> on MS Windows
> 
> ...
> >>
> >> It looks like org-babel-octave-eoe-output and org-babel-octave-eoe-
> indicator
> >> were swapped around in org-babel-octave-evaluate-session .
> >>
> >> I have the following in dot emacs
> >>
> >> (setq org-babel-octave-eoe-output "
> >> ans =
> >>
> >> org_babel_eoe
> >>
> >> ")
> >
> > For the sake of completeness I'm attaching the patch. Also one should
> override
> >
> > (setq org-babel-matlab-emacs-link-wrapper-method
> >    "%s
> > if ischar(ans), fid = fopen('%s', 'w'); fprintf(fid, '%%s\\n', ans);
> fclose(fid); else, save -ascii %s ans ; end
> > delete('%s')
> > ")
> >
> > as matlabShell does not like commands split across multiple lines.
> >
> 
> Thanks for sending along the patch and the variable re-definition.

I was in the hurry and the second variable should have been 

(setq org-babel-octave-wrapper-method
  "%s
if ischar(ans), fid = fopen('%s', 'w'); fprintf(fid, '%%s\\n', ans);
fclose(fid); else, dlmwrite('%s', ans, '\\t'); end")

and not org-babel-matlab-emacs-link-wrapper-method . The only difference
from what is already in there, is that it should be a single line (with ;
delimiters). It might be a limitation of matlabShell.

From what I understand EmacsLink is something outdated and not supported
anymore as there is matlab-emacs mode.

Also the patch was missing yet another change to use single quotes instead
of double quotes when making default figures invisible. I'm attaching the
patch I ended up using.

>  If I
> understand correctly then the patch should be applied for any system,
> but the variable definition need only be applied on windows systems.  Is
> that correct?

Unfortunately I don't have Matlab installed on my home GNU/Linux computer,
I'll see if I'm eligible and can get one.

What bugs me though is that I can't use both octave and matlab as they use
same variable (org-babel-octave-eoe-output) which should be set to different
values. In org-babel-comint-with-output macro (ob-comint.el) it is used to
check if shell/REPL is done with evaluation and ready for input. I wonder if
it is possible to generalize org-babel-octave-eoe-output for both matlab and
octave as the only difference is the bunch of newlines in Matlab output. One
may write a regexp that matches both, however "(regexp-quote
,eoe-indicator)" in aforementioned macro confuses me. So it got to be a
plain string.

M.

> Can anyone confirm that matlab/octave code blocks are still functional
> on a GNU/Linux machine after the above patch and redefinition have been
> applied?  I do not use octave/matlab myself and can't verify this.
> 
> If they don't break anything I'm happy to apply these patches.
> 
> Thanks,
> 
> --
> Eric Schulte
> http://cs.unm.edu/~eschulte

[-- Attachment #2: ob-octave_matlab_updated.patch --]
[-- Type: application/octet-stream, Size: 882 bytes --]

diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el
index 9e85757..6428c8c 100644
--- a/lisp/ob-octave.el
+++ b/lisp/ob-octave.el
@@ -90,7 +90,7 @@ end")
 		  (if (org-babel-octave-graphical-output-file params)
 		      (mapconcat 'identity
 				 (list
-				  "set (0, \"defaultfigurevisible\", \"off\");"
+				  "set (0, 'defaultfigurevisible', 'off');"
 				  full-body
 				  (format "print -dpng %s" (org-babel-octave-graphical-output-file params)))
 				 "\n")
@@ -231,8 +231,8 @@ value of the last statement in BODY, as elisp."
 		(org-babel-comint-with-output
 		    (session
 		     (if matlabp
-			 org-babel-octave-eoe-indicator
-		       org-babel-octave-eoe-output)
+			 org-babel-octave-eoe-output
+		       org-babel-octave-eoe-indicator)
 		     t full-body)
 		  (insert full-body) (comint-send-input nil t)))) results)
     (case result-type

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [babel, patch] ob-octave does not catch EOE from matlabShell on MS Windows
  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
  0 siblings, 2 replies; 10+ messages in thread
From: Mikhail Titov @ 2012-05-30 15:58 UTC (permalink / raw)
  To: 'Eric Schulte', 'Achim Gratz'; +Cc: emacs-orgmode

> -----Original Message-----
> From: emacs-orgmode-bounces+mlt=gmx.us@gnu.org [mailto:emacs-orgmode-
> bounces+mlt=gmx.us@gnu.org] On Behalf Of Achim Gratz
> Sent: Monday, May 28, 2012 1:24 PM
> To: emacs-orgmode@gnu.org
> Subject: Re: [O] [babel, patch] ob-octave does not catch EOE from
matlabShell
> on MS Windows
> 
> Eric Schulte writes:
> > Thanks for sending along the patch and the variable re-definition.  If I
> > understand correctly then the patch should be applied for any system,
> > but the variable definition need only be applied on windows systems.  Is
> > that correct?
> 
> The variable re-definition seems to be be needed for matlab-shell, I
> don't know if that would be restricted to Windows.
> 
> > Can anyone confirm that matlab/octave code blocks are still functional
> > on a GNU/Linux machine after the above patch and redefinition have been
> > applied?  I do not use octave/matlab myself and can't verify this.
> 
> The octave tests still pass on openSUSE with the patch applied along
> with all the other tests (except R, since I'm missing ESS).

I wonder how it still passes the test...

I think my patch unintentionally breaks octave. It probably should have been
just

			 org-babel-octave-eoe-output

instead of

		     (if matlabp
			 org-babel-octave-eoe-output
		       org-babel-octave-eoe-indicator) 

or other way around.

I apologize for bringing it all over to the list as I'm not proficient in
elisp yet.

I feel like ob-octave needs an overhaul in general as it does not respect
many header arguments like :width, :height, and graphics format (always
png). Also it would be nice if it removed extra prompts left in results as
does ob-R.el .

I'll post improved patch once I feel it is ready.

Eric, so for now, just hold on with the application of what I've sent.

Mikhail

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [babel, patch] ob-octave does not catch EOE from matlabShell on MS Windows
  2012-05-30 15:58           ` Mikhail Titov
@ 2012-05-30 16:05             ` Eric Schulte
  2012-05-30 16:58             ` Achim Gratz
  1 sibling, 0 replies; 10+ messages in thread
From: Eric Schulte @ 2012-05-30 16:05 UTC (permalink / raw)
  To: Mikhail Titov
  Cc: 'Achim Gratz', emacs-orgmode, 'Eric Schulte'

"Mikhail Titov" <mlt@gmx.us> writes:

>> -----Original Message-----
>> From: emacs-orgmode-bounces+mlt=gmx.us@gnu.org [mailto:emacs-orgmode-
>> bounces+mlt=gmx.us@gnu.org] On Behalf Of Achim Gratz
>> Sent: Monday, May 28, 2012 1:24 PM
>> To: emacs-orgmode@gnu.org
>> Subject: Re: [O] [babel, patch] ob-octave does not catch EOE from
> matlabShell
>> on MS Windows
>> 
>> Eric Schulte writes:
>> > Thanks for sending along the patch and the variable re-definition.  If I
>> > understand correctly then the patch should be applied for any system,
>> > but the variable definition need only be applied on windows systems.  Is
>> > that correct?
>> 
>> The variable re-definition seems to be be needed for matlab-shell, I
>> don't know if that would be restricted to Windows.
>> 
>> > Can anyone confirm that matlab/octave code blocks are still functional
>> > on a GNU/Linux machine after the above patch and redefinition have been
>> > applied?  I do not use octave/matlab myself and can't verify this.
>> 
>> The octave tests still pass on openSUSE with the patch applied along
>> with all the other tests (except R, since I'm missing ESS).
>
> I wonder how it still passes the test...
>
> I think my patch unintentionally breaks octave. It probably should have been
> just
>
> 			 org-babel-octave-eoe-output
>
> instead of
>
> 		     (if matlabp
> 			 org-babel-octave-eoe-output
> 		       org-babel-octave-eoe-indicator) 
>
> or other way around.
>
> I apologize for bringing it all over to the list as I'm not proficient in
> elisp yet.
>
> I feel like ob-octave needs an overhaul in general as it does not respect
> many header arguments like :width, :height, and graphics format (always
> png). Also it would be nice if it removed extra prompts left in results as
> does ob-R.el .
>
> I'll post improved patch once I feel it is ready.
>
> Eric, so for now, just hold on with the application of what I've sent.
>

Will do,

Thanks for following up on this.  The original author of the Octave and
Matlab support for Org-mode code blocks (Dan Davison) is no longer
following the Org-mode mailing list, so it would be good to have a new
pair of eyes on this.  If you run into elisp questions I'm sure there
are many experts on this list who would be happy to help provide
answers.

Best,

>
> Mikhail
>
>
>

-- 
Eric Schulte
http://cs.unm.edu/~eschulte

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [babel, patch] ob-octave does not catch EOE from matlabShell on MS Windows
  2012-05-30 15:58           ` Mikhail Titov
  2012-05-30 16:05             ` Eric Schulte
@ 2012-05-30 16:58             ` Achim Gratz
  1 sibling, 0 replies; 10+ messages in thread
From: Achim Gratz @ 2012-05-30 16:58 UTC (permalink / raw)
  To: emacs-orgmode

Mikhail Titov writes:
>> The octave tests still pass on openSUSE with the patch applied along
>> with all the other tests (except R, since I'm missing ESS).
>
> I wonder how it still passes the test...

If you know how it breaks and why the tests don't catch it, please add a
test that does...


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

SD adaptations for Waldorf Q V3.00R3 and Q+ V3.54R2:
http://Synth.Stromeko.net/Downloads.html#WaldorfSDada

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-05-30 16:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-24 21:02 [babel] ob-octave does not catch EOE from matlabShell on MS Windows Mikhail Titov
2012-05-24 21:30 ` 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

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.