From: Karthik C. <kar...@gm...> - 2021-07-06 22:36:37
|
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 |
From: Uwe B. <ou...@ma...> - 2021-07-07 06:37:30
Attachments:
smime.p7s
|
>>> "KC" == Karthik Chikmagalur <kar...@gm...> writes: > 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. Thanks, I was not aware of that problem > 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. It looks fine to me, but I only deal with relatively small files. What do others think, especially Eric, who provided the original code? Regards Uwe |
From: Karthik C. <kar...@gm...> - 2021-07-07 17:10:29
|
An alternative to including all local functions in the temp file is something like this: 1. Find the local function names referred to in the region being evaluated. The current version of matlab-shell-region->script does this. Let's call this list included-functions. 2. Find function calls to other local functions for each function in this list. Add these function names to included-functions. 3. Repeat step 2 until included-functions doesn't change. We've now traversed the dependency chain of local functions beginning with the region to be evaluated. 4. Insert all functions in included-functions at the end of the temp file. I can probably code this up but I'd like to know what Eric thinks first. Karthik Uwe Brauer <ou...@ma...> writes: >>>> "KC" == Karthik Chikmagalur <kar...@gm...> writes: > >> 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. > > > Thanks, I was not aware of that problem > >> 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. > > It looks fine to me, but I only deal with relatively small files. What > do others think, especially Eric, who provided the original code? > > Regards > > Uwe |
From: Eric L. <eri...@gm...> - 2021-07-11 15:17:52
|
Hi Karthik and Uwe, Nice find. I think the first solution Karthik suggests of just copying over all local functions makes the most sense. Chasing down all the dependencies would be tricky. It might also make sense to check if there are any functions in the file, and improve the auto-selector for which region command to use. If local functions exist, it probably makes sense to always use the script generator. Doing that check will be much easier once we merge over the hairyblocks branch. I still owe that changelog, so I'll work on that today. Eric On Wed, Jul 7, 2021 at 1:10 PM Karthik Chikmagalur < kar...@gm...> wrote: > An alternative to including all local functions in the temp file is > something like this: > > 1. Find the local function names referred to in the region being > evaluated. The current version of matlab-shell-region->script does this. > Let's call this list included-functions. > 2. Find function calls to other local functions for each function in this > list. Add these function names to included-functions. > 3. Repeat step 2 until included-functions doesn't change. We've now > traversed the dependency chain of local functions beginning with the region > to be evaluated. > 4. Insert all functions in included-functions at the end of the temp file. > > I can probably code this up but I'd like to know what Eric thinks first. > > Karthik > > Uwe Brauer <ou...@ma...> writes: > > >>>> "KC" == Karthik Chikmagalur <kar...@gm...> writes: > > > >> 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. > > > > > > Thanks, I was not aware of that problem > > > >> 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. > > > > It looks fine to me, but I only deal with relatively small files. What > > do others think, especially Eric, who provided the original code? > > > > Regards > > > > Uwe > > > _______________________________________________ > Matlab-emacs-discuss mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss > |
From: Uwe B. <ou...@ma...> - 2021-07-20 17:08:14
Attachments:
smime.p7s
|
>>> "EL" == Eric Ludlam <eri...@gm...> writes: Hi Karthik and Eric > Hi Karthik and Uwe, > Nice find. I think the first solution Karthik suggests of just copying > over all local functions makes the most sense. Chasing down all the > dependencies would be tricky. > It might also make sense to check if there are any functions in the > file, and improve the auto-selector for which region command to use. > If local functions exist, it probably makes sense to always use the > script generator. Doing that check will be much easier once we merge > over the hairyblocks branch. I still owe that changelog, so I'll work > on that today. I did the merge some days ago, and it seems ok, no problems occurred so far. What do you think, shall we use Karthik first solution, or is it worth to generalise it a bit? If the first solution is fine (for me at least it is), Karthik, could you please pull the latest master and provide a patch? Thanks and regards Uwe |
From: Karthik C. <kar...@gm...> - 2021-07-26 05:48:01
Attachments:
copy-all-functions.patch
|
Attached: Patch to copy all local functions to script. - Karthik |
From: Uwe B. <ou...@ma...> - 2021-07-26 09:01:07
Attachments:
smime.p7s
|
>>> "KC" == Karthik Chikmagalur <kar...@gm...> writes: > Attached: Patch to copy all local functions to script. Thanks I applied your patch and will do some testing today before pushing, maybe you could provide a test case? Just a comment for the future, could you please provide the patch as a attachment in the future? That would make things a bit easier. Regards Uwe |