필터 지우기
필터 지우기

Any new possibilities on dynamic code folding possibilities for vs 2021a?

조회 수: 4 (최근 30일)
Q490
Q490 2021년 8월 16일
댓글: Q490 2021년 8월 17일
Hi All,
I was wondering if there have been any new capabilities added to Matlab in the recent versions to allow users to dynamically set code folding/unfolding within the Matlab Editor? This has been a question asked in the past (~2016-2017, e.g. Is it possible to control code folding with code? - MATLAB Answers - MATLAB Central (mathworks.com)) but haven't seen any inquires on the subject recently. I have looked at the Matlab Editor API to see if any new updates have been added to allow this functionality but it does not appear to me to have happened.
My goal is to take large scripts that have not been functionalized and allow user to specify at beginning of script which sections to unfold by using structure field names. This would greatly increase the efficiency of debugging these large scripts.
For example, if you would like to keep all code folded except section where a structure field "testField" is created, than can specify at beginning of script:
unfoldCodeSectionFieldList = {'testField'};
Then when that field is first initialized within the script, unfold the code that follows where the values assigned within the sub-fields of "testField" are defined within the script. As a simple way of illustrating what I am trying to say, an example might be:
unfoldCurrSectionFlag = false;
struct.testField = {};
if isfield(struct,'testField') && isempty(struct.testField)
unfoldCurrSectionFlag = true;
end
if unfoldCurrSectionFlag
%% Unfold here
struct.testField.data1 = [1 1 1 1];
struct.testField.data2 = [2 2 2 2];
end
unfoldCurrSectionFlag = false;
ideally I could functionalize this to run on all scripts, aka:
function unfoldScriptTest(struct,unfoldCodeSectionFieldList,scriptName)
if isfield(struct,'testField') && isempty(struct.testField)
% use Matlab Editor API to create code section ("%% Dynamically added code section") in "scriptName" at place of "testField" initialization
end
end
I would like to be able to do this without having to use a publishing workaround(such as asked about in this post:
and which references:
I understand there are likely easier ways to write the above code, I am simply using it as an easy way to explain, so please - rather than correcting the code above - please let me know if there is a better way to explain what I am after with the main subject of this inquiry.
I do realize that the more efficient way in the long-term would be just to functionalize the script and better organize it overall, however, as a workaround for very long scripts where I do not have the time to do so - this type of functionality would be extremely helpful.
I appreciate any responses!
Thank you,
Quentin
  댓글 수: 2
Rik
Rik 2021년 8월 17일
In my experience, debugging long scripts takes longer than you might expect. I would urge you to convert the code to functions. It will speed up debugging and give you folding options for free. Functions have they enormous benefit that they are a black box that you can debug without context after which you don't need to worry about its internal workings.
Q490
Q490 2021년 8월 17일
Thank you, yes as I mentioned I am aware that functionalizing the script is the best practice route to take. Extenuating circumstances are what led to my question.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by