Color coding commented statements and comments following a statement

Hi,
I would like to know if there is a possibility of having a different color for a commented statement and a comment that follows a statement, e.g.,
% u=rand
u = rand % generate a random number from U[0,1]
shows both in green but I would like to differentiate. I could not find a lead from MATLAB preferences.

9 Commenti

I'm curious why you want to see those two comments colored differently. How would distinguishing those two cases be useful for your workflow?
I'm not just asking this of the original poster from back in 2015; anyone who's commented since then, I'd be curious about your answer to that question.
I came upon this thread hoping to change comment color. The project I am currently working involves interpreting and commenting on matlab code written by someone else. Commenting in multiple colors would come in handy for me because I would be able to flag lines of code that I need to work on at a later point by giving the comment a different color. This would allow me to quickly identify relevant lines of code when I return to my work.
Stephen makes a good point, of a case where it would be useful to explicitly set comment color differently on demand.
For example, when I am writing code that will require several days or more to write, I often insert a garbage line in the code where I stop for the day, just random characters on the keyboard.
245y2562y4uy6
This way, if I tried to excute the code, it will fail, and it is obvious where I left off. Better would be to have a comment in RED perhaps, that would be a strong visual flag to draw my eye to the spot. And since it is a comment, I can note exactly what needs to be done in that missing block of code.
I can even see multi-colored comments as useful when code is shared between multiple people who are co-authoring the code.
But personally, I can see essentially no purpose in having MATLAB automatically differentiate comment color based on where the comment lies, thus an inline comment versus a stand alone comment.
That seems like a reasonable use case for having comments in multiple colors. Right now all comments are a single color, though you can change that color in the Preferences. I recommend sending this to Technical Support as an enhancement request, so it gets captured in the enhancement database.
There is some functionality that may help you identify work that needs to be done (by who needs to do that work or for which step of your project the work needs to be completed.) The TODO/FIXME report available from the Current Folder browser will let you search for specific identifiers (TODO, FIXME, or "Fix:Stephen".)
If you're going to leave the file open in your MATLAB session but need a "pick up from here" marker (say if you're going home for the night) you can set bookmarks in the file (see the "Set Bookmarks" item under the "Go To Location in File" section on that page.)
Commenting to follow this thread.
Perhaps the # symbol could work as a clone of % but in a different color. That would be simple and mighty useful!
Commenting just because I would still love to see this feature and am also going to send a support email too.
the feature is interesting to differentiate my comments from other peoples comments
It would be great to differentiate comment colors with flags: for example
%todo: do this later
would appear in a different color.
A small workaround could be to write the "comments" (e.g. todo) as a system command with the bash colon operator ':', and temporarily change their color in the settings.
s = settings;
s.matlab.colors.SystemCommandColor.TemporaryValue = [255 75 0];
!: TODO: Lorem ipsum
Unfortunately it only works on new lines.

Accedi per commentare.

Risposte (5)

Also interested!
Maybe just implement different commenting function starting with '%!' or something..
I would also like more customizability for organizing code (like changing colors of comments)!
It would be nice to have a special color for ToDo items...This feature would be useful especially when you want to share them with your team

Categorie

Scopri di più su Programming in Centro assistenza e File Exchange

Richiesto:

il 18 Nov 2015

Risposto:

il 25 Ott 2022

Community Treasure Hunt

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

Start Hunting!

Translated by