how to tell Matlab smart indent not to move my comments around?

5 ビュー (過去 30 日間)
Nasser M. Abbasi
Nasser M. Abbasi 2016 年 1 月 18 日
コメント済み: KJ N 2018 年 11 月 5 日
using Matlab 2015a, is there an option to tell Matlab editor not to mess with my comments when doing smart indent? For example, if I write this
x = 1; %this is comment
%this is follow up
Now when I do smart indent, the above is reformatted as
x = 1; %this is comment
%this is follow up
Which I do not want. I looked at preferences->editor->Language->comment formatting and no matter what option I choose, it does not make a difference, it still does the same with the comments.
This very annoying, it means I have to go fix all the comments each time.
  1 件のコメント
Star Strider
Star Strider 2016 年 1 月 18 日
I would submit that to MathWorks as an Enhancement Request. Use the same page you would use to report a bug. Include the URL to this thread in your message so you don’t have to repeat it all.

サインインしてコメントする。

回答 (2 件)

Stephen23
Stephen23 2016 年 1 月 18 日
編集済み: Stephen23 2016 年 1 月 20 日
This is the simplest solution, guaranteed to work always, no custom settings required:
x = 1; % this is comment
% % this is follow up

Image Analyst
Image Analyst 2016 年 1 月 18 日
I think you'd have to write your own routine to indent it the way you want. I don't think there's anyway to know, for an arbitrary line of code that that it's working on, whether or not to slam the comment to the left. Even if it did recognize that there was a percent symbol right above it on the prior line, how would it know that that line you wanted to leave alone, but some other line you might want to shift left because they're unrelated? I don't think it could know that with certainty, and the answer might change from one pair of lines to another.
  2 件のコメント
Nasser M. Abbasi
Nasser M. Abbasi 2016 年 1 月 18 日
I simply want Matlab to leave a line with only a comment in it alone. It does not have to know anything really about the earlier line. If a line has only a comment on it, just do not touch the this line and skip it, that is all.
KJ N
KJ N 2018 年 11 月 5 日
I agree that this is a feature that MATLAB really ought to have (at least with a customizable setting) that it currently does not have. Here's hoping it will someday be improved that way.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by