In our last post, we talked about how you no longer have to select anything to tidy up your comments, and about how comment wrapping no longer splits long strings like URLs. In today’s post we’ll finish up with a few more improvements.
Wrap where you want
If you are writing MATLAB help associated with a class, you may have encountered the following scenario. You want to provide “help”-style comments for a method, which naturally is indented a bit because of the “classdef”, “methods” and “function” blocks. But comment wrapping occurs at the preferred column (which, for the sake of this example’s screenshots, I have set to 50) without regard for this initial indent:
In other words, instead of a comment block that is 50 characters wide, I only get 50 – 12 = 38 characters. As a result, when we ask for help on our method, the output is narrower than it would typically be:
In R2010b, we introduced a preference to control this behavior. If you want your comments to have the same character width regardless of the column at which they begin, then choose the “columns from start of comment” preference via File > Preferences > Editor/Debugger > Language:
Now, your comments will wrap at that many characters from the start of the comment (the “%” character) rather than from the very first column:
And the ”help” output will always be a consistent width:
Since most people want their code to wrap at a fixed location, this preference is set to “columns from start of line” by default.
Wrap block comments
Do you use block comments? Many users had wondered why they didn’t have the same wrapping capabilities as regular line comments. Now they do:
If you copy and paste large bodies of text into block comments, or simply write the occasional novella within your MATLAB code, you can now make them nice and neat with a keystroke.
That’s a wrap
That’s it for our deep dive into this feature. Thanks for reading, and let me know if you get a chance to try out these improvements, and what else you’d like to see!
要发表评论，请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。