Can you fold a highlighted selection of code?

2 Ansichten (letzte 30 Tage)
Andrew Reibold
Andrew Reibold am 1 Dez. 2014
Bearbeitet: Matt J am 2 Okt. 2015
I have enabled cell folding with the double percent signs, %%.
I can click each individual +/- on the left hand side of my script window to expand or fold cells now. I can also right click the window and click 'Fold' or 'Fold all'
I want to fold all cells in a section of a few thousand lines of code in the middle and leave open the rest. There are many cells in this section making the manual process annoying. I was hoping I could highlight a large amount of code with the cursor, and fold any cells in it.
If I try to highlight that large section and click Fold , it only folds one (The last one)
If I highlight the section and click Fold All, everything in the file folds, including things I haven't highlighted.
Is there a way to only fold the cells I have highlighted?
  1 Kommentar
Matt J
Matt J am 2 Okt. 2015
Bearbeitet: Matt J am 2 Okt. 2015
I agree that this is very much needed. I'd also like to be able to fold all the functions in a methods block of a classdef file by clicking on the block in some way. Currently, when you fold a methods block, you see this,
classdef myclass
methods ... %folded
end
In addition to that, I'd also like to have a button that folds as follows, where I can see a synopsis of what functions are present in the methods block, and their signatures:
classdef myclass
methods
function obj=F1(arg1,arg2) ...
function obj=F2(arg1,arg2) ...
function obj=F3(arg1,arg2) ...
function obj=F4(arg1,arg2) ...
end
end

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sean de Wolski
Sean de Wolski am 1 Dez. 2014
Bearbeitet: Sean de Wolski am 1 Dez. 2014
I think the bigger question is why do you have more than 1000 lines in a file?
Consider breaking it out into smaller manageable functions (which could be folded as a whole function) and which can be in a separate file once they're working..
  2 Kommentare
Andrew Reibold
Andrew Reibold am 1 Dez. 2014
Bearbeitet: Andrew Reibold am 1 Dez. 2014
I frequently inherit poorly formatted code and what I'm asking about would help manage it a lot.
I just want to know if there is a way to fold all cells in a cursor highlighted section of code. It seems like a potentially basic function but it may not be possible.
per isakson
per isakson am 1 Dez. 2014
Bearbeitet: per isakson am 1 Dez. 2014
"why do you have more than 1000 lines in a file" [...] "smaller manageable functions" &nbsp I'm not convinced that's always true. I have huge classdef-files and huge files with unit tests. I use folding systematically and I would benefit from better control over the folding. Now it requires far too many mouse-clicks.
Available tools matters. Search and Search&Replace for one works better with one huge file.
My code evolves through experiments and refactoring and during that process huge files present advantages.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Software Development Tools finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by