mathworks / Emacs-MATLAB-Mode

Edit, lint, debug, and run MATLAB in Emacs
GNU General Public License v3.0
7 stars 0 forks source link

Unexpected face changes by matlab-sections #14

Open JohnC32 opened 1 week ago

JohnC32 commented 1 week ago

Given script

function b=sections(a)
% comments
% prior 
% to section 1 heading
%% section 1
    b = a * 2;

% comments
% prior 
% to section 2 heading
%% section 2
    b = b + 1;
end

sections

Putting point in various locations causes odd bolding. To see the difference in behavior, comment out (matlab-sections-mode-enable) in matlab.el.

I think the goal was to highlight the active section that will be run. Wouldn't it be sufficient to just change the face the "%% section heading" line to be highlighted?

Nidish96 commented 1 week ago

I'm not really sure I follow the issue.

Putting point on "r" only makes lines 5-10 bold. Line 11 is only following the matlab-sections-section-break-face. Line 12 and 13 are not bold in your screenshot.

The section highlight is controlled by matlab-sections-highlight-face. So if a user does not like this, he/she can always turn it off since the variable is customizable (M-x customize matlab-sections).

I personally like the section highlighting. This is quite helpful especially when I'm teaching with the code.

Or have I completely missed the issue?

JohnC32 commented 1 week ago

Hi

In my example, two code section blocks are bolded (the code on line 6 for section 1 and the code on line 12 for section 2) also the 'end' is bolded which isn't part of a section. That seems incorrect to me. Note, the issue is a little worse when you use "%% sections" in functions. In scripts without functions, things look a little better. My example should probably have had "x = sections(a);" at the start and the name of the file be sections_script.m or something.

When the cursor is on line 9, which section does that belong to? Is it a comment for the following section or a comment for the prior section? It could be either. I think it should be associated with the prior section and hence line 12 shouldn't be bolded (and likewise the 'end' shouldn't be bolded).

I agree that having the active session "highlighted" in some way is a very useful feature. Perhaps making the code an comments in that section block bold is best, but is bolded code and comments the best we can do? Maybe highlighting the section heading and adding a "fringe/bar" to the left of the active sections would be nicer?

Thanks, John

Nidish96 commented 1 week ago

Actually if you notice your screenshot carefully, you can see that the contents of section 2 are not really bold-faced. The "end" is not boldfaced. You can see that "function" and "end" are highlighted identically.

So only one section is bold-faced and this is the consistent behavior.

When the cursor is on line 9, it belongs to section 1 only. Line 12 is not boldened. Please compare line 12 (not bold) and line 6 (bold). There may be an issue with the screen you are viewing it on. Can you check on a different screen and confirm?

As of now, all font decorations are supported. Having a fringe/bar on the left sounds like an interesting idea. I'll try this out.