Hi,

I'm having trouble using matlab-shell-region->script when my script is 
structured as follows, and I call matlab-shell-run-region-or-line on the 
function call:

%---- 8< ----
%% Function call
func2(x)

%% Local functions
function y = func1(x)
  y = x * 2;
end  
  
function z = func2(x)
  y = func1(x);
  z = y + 1;
end
%---- 8< ----

When I call func2(x), matlab-shell-region->script copies over only func2 to the 
temporary file, even though func2 requires func1 to be defined.

The problem is that matlab-shell-region->script copies over only the functions 
that it finds in the region being evaluated. Since func1 is not part of this 
region, it's not copied over. From matlab-shell-region->script:

      (dolist (F functions)
        (save-excursion
          (when (re-search-forward (semantic-tag-name F) nil t)
            ;; Found, copy it in.
            (let ((ft (matlab-semantic-tag-text F orig)))
              (goto-char (point-max))
              (insert "% Copy of " (semantic-tag-name F) "\n\n")
              (insert ft)
              (insert "\n%%\n")))))

The re-search-forward, which is run on the text being evaluated, is doing the 
filtering to func2 only. I got around this by simply copying over all local 
functions to the temp file:

      (dolist (F functions)
        (save-excursion
          (let ((ft (matlab-semantic-tag-text F orig)))
              ;; Copy over ALL local functions to the temp file.
              (goto-char (point-max))
              (insert "% Copy of " (semantic-tag-name F) "\n\n")
              (insert ft)
              (insert "\n%%\n"))))

This probably makes the call to matlab-shell more expensive, but I think this 
should be the default behavior to avoid subtle failures like this.

Karthik


_______________________________________________
Matlab-emacs-discuss mailing list
Matlab-emacs-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss

Reply via email to