Search code examples
matlabeditorauto-indent

Can I make MATLAB ignore a section of code when auto-indenting?


I love MATLAB "smart indenting". Ctrl-A, Ctrl-I is hardwired with me. However, in my some-3000-lines script, I have one section of about 100 lines of code which I would like not to be touched by MATLAB.

(Why, you ask? That's why:

x = ...
        aaaaaaaaaaaaaaaaa ...
    - ...
        ( ...
                bbbbbbbbbbbbbb ...
            + ...
                cccccccccccccccccccccc ...
        );

That's my way of encoding that this is a difference of two things, one of which is aaaaaaaaaaaaaaaaa, the other being a set of parentheses, ... etc etc.

So, how can I teach MATLAB to not re-indent this part?


Solution

  • You can use the %{ and %} for comment block:

    a = 3;
    b = 5;
    %{
    some other code to be ignored
    %}
    

    and if you want to toggle this ON, all you need is one more % in the right place:

    a = 3;
    b = 5;
    %%{
    some other code to be ignored
    %}