dykstrom / basic-mode

Emacs major mode for editing BASIC code
GNU General Public License v3.0
7 stars 10 forks source link

Nested if statements do not indent correctly #11

Closed Spauldo closed 3 years ago

Spauldo commented 5 years ago

Starting with emacs -Q and then using load-file to load the 20180919.1752 version of basic-mode from Melpa, indentation of nested if statements does not seem to work correctly.

The first if statement will indent fine, but the second will not. I'll give an example - I typed this into an empty buffer without using any movement keys or backspacing:

if x < 3 then
    if y > 2 then
    x = 2
 y = 3
endif
endif

This it how it autoindented. Running indent-region with the text marked does not change it. Removing all indentation and then running indent-region on the marked text gives me the same thing, but without the y = 3 line indented.

I'll examine the code later (I'm going to have to modify it quite a bit for the BASIC dialect I'm working with anyway), but I figured I'd give you a heads up that something was up with it.

Spauldo commented 5 years ago

It seems as if having indent-tabs-mode set to t is what causes the bug - basic-calculate-indent returns a 1 instead of 8. Setting indent-tabs-mode to nil fixes the problem.

Granted, that's probably what I want to set it to anyway for the work I'm doing (where the code already in place is indented by 2 spaces), but it doesn't seem too hard to make this work even with tabs. I'll make a pull request for the changes I've made. I haven't tested things like line numbers (the particular version of BASIC I'm using doesn't use them), so let me know if it screws something else up.

dykstrom commented 5 years ago

Thank you for finding (and fixing!) this problem! I will look into your PR as soon as I have time. If you have any other ideas on how to improve basic-mode, feel free to suggest them, or make a pull request.

Spauldo commented 5 years ago

Just an update, I am still going to work on this. I have a heap of work-related Common LISP code I have to deal with first, and that's got me about LISPed out.

At least it's a lot more fun than the work-related BASIC I was working on earlier that prompted the original pull request. Hundreds of lines of nested IF THEN/ELSE stuff that was improperly indented, and the FactoryLink "IDE" (if you can call it that) had no automatic indentation feature - hence Emacs.

dykstrom commented 5 years ago

You can take your time. I'm not doing anything to basic-mode at the moment. Interesting stuff you do at work, LISP and BASIC. But I guess the tool support is not what you are used to, if you come from the Java or C# world.

dykstrom commented 3 years ago

Solved by #12