{"id":401,"date":"2010-10-04T15:08:14","date_gmt":"2010-10-04T15:08:14","guid":{"rendered":"https:\/\/blogs.mathworks.com\/desktop\/2010\/10\/04\/r2010b-comment-wrapping-improvements\/"},"modified":"2010-10-25T14:49:26","modified_gmt":"2010-10-25T14:49:26","slug":"r2010b-comment-wrapping-improvements","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/community\/2010\/10\/04\/r2010b-comment-wrapping-improvements\/","title":{"rendered":"R2010b Comment Wrapping Improvements"},"content":{"rendered":"<p>In R2010b we made a series of improvements to the \u201ccomment wrapping\u201d feature in the MATLAB Editor. In this two-part series, we&#8217;ll take a detailed dive into those improvements. <\/p>\n<p>In this first part, we&#8217;ll introduce comment wrapping and talk about how it&#8217;s now easier to use. In the second part, we&#8217;ll cover more advanced maneuvers for the serious comment writer.<\/p>\n<p><b>Wait, what\u2019s comment wrapping?<\/b><br \/>\nIn short, comment wrapping is a feature of the MATLAB Editor (accessible via the &#8220;Text&#8221; > &#8220;Wrap Comments&#8221; menu item) that allows you to go from ragged, messy comments:<\/p>\n<p><img src='https:\/\/blogs.mathworks.com\/images\/desktop\/jared_comment_wrapping\/comment_wrapping_before_an.png' alt='comment-wrapping-before' \/><\/p>\n<p>to neatly formatted ones:<\/p>\n<p><img src='https:\/\/blogs.mathworks.com\/images\/desktop\/jared_comment_wrapping\/comment-wrapping-after_an.png' alt='comment wrapping after' \/><\/p>\n<p>The feature also includes <em>automatic<\/em> comment wrapping, which occurs as you type beyond the end of a line. In R2010b, we\u2019ve made this feature easier and more powerful.<\/p>\n<p><b>No selection required<\/b><\/p>\n<p>Previous to R2010b, if you wanted to reformat a section of comments as you edited, you first had to select the region that needed reformatting and then press Ctrl-J (or Shift-Fan-W on the Mac).<\/p>\n<p><img src='https:\/\/blogs.mathworks.com\/images\/desktop\/jared_comment_wrapping\/comment-wrapping-selection.png' alt='comment-wrapping-selection.png' \/><\/p>\n<p>In R2010b, you can still do it this way. But much more conveniently, you can skip making a selection and just let the Editor infer the current section of comments for you. For example, suppose your caret were at the end of line 5 below:<\/p>\n<p><img src='https:\/\/blogs.mathworks.com\/images\/desktop\/jared_comment_wrapping\/comment-wrapping-noselection.png' alt='comment-wrapping-noselection.png' \/><\/p>\n<p>Now you can simply press Ctrl-J to reformat this section of comments, and your caret remains at the same location in the text that it had before. Your caret could in fact be anywhere on lines one through five. This allows you to tidy up what you\u2019ve written without taking you out of the flow of typing.  <\/p>\n<p>Note that the Editor wraps only the current \u201csection\u201d of comments. So what defines a section? Hopefully, exactly what you\u2019d think: a series of contiguous, identically-indented comment lines. So a non-comment line, a blank line, or a comment indented differently each represents the end of a section. This allows independent \u201cparagraphs\u201d of comments to remain intact and prevents them from being strung together, even if you do a &#8220;Select All&#8221; > &#8220;Wrap Comments&#8221; to reformat your whole file.<\/p>\n<p><b>No more broken strings<\/b><\/p>\n<p>One frustrating behavior of comment wrapping prior to R2010b was that if your comments contained text that shouldn\u2019t be broken, such as a URL in publishing hyperlink markup, comment wrapping would go ahead and break it:<\/p>\n<p><img src='https:\/\/blogs.mathworks.com\/images\/desktop\/jared_comment_wrapping\/comment-wrapping-brokenstring_an.png' alt='comment-wrapping-brokenstring.png' \/><\/p>\n<p>This was true with automatic comment wrapping as well \u2013 if you were typing a long string and reached the right-hand margin, it would break. That\u2019s no good for reading and was particularly pernicious for publishing:<\/p>\n<p><img src='https:\/\/blogs.mathworks.com\/images\/desktop\/jared_comment_wrapping\/comment-wrapping-published-brokenstring_an.png' alt='comment-wrapping-published-brokenstring.png' \/><\/p>\n<p>In R2010b, comment wrapping abides by this simple rule: if there\u2019s no whitespace, don\u2019t break! This means that URLs, or any long strings, are preserved:<\/p>\n<p><img src='https:\/\/blogs.mathworks.com\/images\/desktop\/jared_comment_wrapping\/comment-wrapping-published.png' alt='comment-wrapping-published.png' \/><\/p>\n<p><b>Wrapping up (groan)<\/b><br \/>\nThat&#8217;s all for now. In the next part, we&#8217;ll discuss a few more enhancements to this feature. In the meantime, try it out and let me know what you think!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In R2010b we made a series of improvements to the \u201ccomment wrapping\u201d feature in the MATLAB Editor. In this two-part series, we&#8217;ll take a detailed dive into those improvements.<br \/>\nIn this first&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/community\/2010\/10\/04\/r2010b-comment-wrapping-improvements\/\">read more >><\/a><\/p>\n","protected":false},"author":51,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,9],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/401"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/users\/51"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/comments?post=401"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/401\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/media?parent=401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/categories?post=401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/tags?post=401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}