tim
tim

Reputation: 10176

Matlab adapting comments to a certain length per line

I like MATLAB automatically linebreaking comments on a certain limit per line. Now let's assume I have added the following comment:

% a) this is a test comment. this is a test comment. this is a test comment
%    this is a test comment. this is a test comment. this is a test
%    comment! this is a test comment!

with a manual indentation at the beginning (to fit the a)). Now when I need to change a bit of the comment, e.g. inserting some words into the first line, the first line gets too long. How can I automatically get it newly formated to the correct max. line length but still with the manual indentation? Is there any automatical way to do this?

Upvotes: 4

Views: 2408

Answers (1)

Pursuit
Pursuit

Reputation: 12345

I think that the best you can do requires three steps on your part.

When you initially add some text, it looks like this:

% a) this is a test comment. this is a test comment. ADDED TEXT this is a test comment
%    this is a test comment. this is a test comment. this is a test
%    comment! this is a test comment!

First, select the text (or the whole file via CTRL+a) and then issue the "wrap comments" command using CTRL+J . Now your text looks like this:

% a) this is a test comment. this is a test comment. ADDED TEXT this is a
% test comment
%    this is a test comment. this is a test comment. this is a test
%    comment! this is a test comment!

Second, you have to manually indent that first line, so the text looks like this:

% a) this is a test comment. this is a test comment. ADDED TEXT this is a
%    test comment
%    this is a test comment. this is a test comment. this is a test
%    comment! this is a test comment!

Third, select text and use CTRL+J again. Your text will look like:

% a) this is a test comment. this is a test comment. ADDED TEXT this is a
%    test comment this is a test comment. this is a test comment. this is a
%    test comment! this is a test comment!

It's not perfect, but it is as good as I am aware of within the Matlab editor.

Upvotes: 2

Related Questions