Sublime Forum

How do I stop this from happeming *EVER*

#1
switch (foo)
{
      case 1:
         ... 
        break;
     <-- AUTO TAB BACK-- case 2: 
}

When I am entering each case of a switch statement I set the cursor EXACTLY where I want it and… the editor automatically undents to align the case with the switch statements braces.

This literally interrupts my workflow to a degree where I will get so damned annoyed with it constantly happening that I lose track of what I am doing because I keep having to FIX this. over and over and over and over and over and over and (is this annohying yet??? : )

lol; you get it.

0 Likes

#2

I think the indentation tab in view might have something to do with it don’t know if this helps your specific case though… You should try seeing if it helps out

0 Likes

#3

I dont want auto indent turned off i want auto screw up the switch statement UNDENTING automatically to STOP. This behavior is driving me absoilutely batshit crazy.

switch (foo)
{
----case 1:
--------code here; when I hit enter here the next case is indented further
------------case 2: <— the INSTANT I start typing this double indented edit UNDENTS to aliogn with ethe switch statement braces… NO NO NO NO NO

I have a case inside the switch… ALL case statemetns inside that switch should automatically indent to the SAME LEVEL!!!

I keep having to UNSCREW UP every single case every time i create a new one. This is frustrating me beyond measure.

}

0 Likes

#4

What language are you using here? Locally in C/C++/JavaScript, entering the word case inside of a switch statement automatically unindents the case exactly one level only.

0 Likes

#5

it is C. Thev following is exactly what is happening.

I create a function and start inputting a switch statement. I end up inside the braces of the switch statement with the cursor at the *. This works beautifully!!! no problems so far.

void main(void)
{
----int x;
----switch(x)
----{
--------*
----}
}

If I now type “case” the star automatically UNDENTS one indentation. WRONG this is what I want to not happen. It totally screws up my flow of though. I like auto INDENT but this auto undent is driving me abasolutely bat**** crazy.

void main(void)
{
----int x;
----switch(x)
----{
----case
----}
}

example of how i want my switch statements formatted

void main(void)
{
----int x;
----switch(x)
----{
--------case 1:
------------do_stuff();
------------break;
--------case 2:
------------do_other_stuff();
------------break;
----}
}

0 Likes

#6

Thats the WHOLE POINT!!!

*WHY does it automatically “unden” after the auto “indent” already placed the cursor in EXACTLY the right placet. How do I stop it from doing this? it is just outright WRONG.

This insanity does not happen till after the auto indent has taken place and i start typing. This totally jacks up the formatting, my train of thought and my inner peace.

This is litearally like somebody constantly poking you in the side. over… and over… and over… and over…

This really needs to be fixed : (

0 Likes

#7

Because case is subject of auto-indenting and auto-dedenting at the same time. Otherwise case 2 wouldn’t be unindented when typing it after break;, which would end up in each case branch being indented too much.

Indentation rules rely on both, scope and single-line regular expressions. They don’t know about the overall desired style of complex statements and how to format them depending on where changes are applied.

To achive what you want with built-in functionality, syntax definition would require to apply a special scope to the first case line in order to be able to exclude it from unindent rules. IIRC, Python is one of the few syntaxes, which does so currently.

The other option would be to write syntax-specific plugins which handle formating on certain keys being pressed or via event listeners.

0 Likes

#8

or a modification to the code to allow auto undent to be turned off for switch statements without removing auto indent. that part works perfectly.

or maybe disable auto undent for th einitial case in a switch statement. i.e. only auto undent after a break has been input?

I would really love to see a rule I can toggle on and off for auto undent.

0 Likes

#9

or a modification to the code to allow auto undent t

That’s not how it works. ST provides generic functionalities, which all rely on syntax definitions (scope names) or other rulesets (regular expressions) such as Indentation Rules. That’s how it is designed to be customizable for each syntax even if it is not directly supported by sublimehq iteslf. It’s one of the fundaments for its customizability and flexibility. The downside is each general purpose functionality and modularized ecosystem also comes with its constrains.

It doesn’t implement syntax or even expression/situation specific versions of such special functions like indentation, which could selectively be adjusted. That’s against the concept of a general purpose heavy customizable editor.

0 Likes

#10

I have no plugins installed, this behavior is the default behavior for switch statemtns in C and maybe other languages. I do not code plugins, i code C, Assembler and Forth and my brain rejected C for decades (I still do not like the language even though it is my primary source of income). I still mentally reject C++, java, python etc. I recognize that in the hands of someone proficient in them they are very good tools (the vast majority of the tools I use every day are developed with those languages) but I will never be proficien in them…

As I am not proficient in other languages I am not able to “fix” this. How do i remove this functionality from the built in behavior for the C programming language. I want the auto INDENT. I do not want the auto UNDENT. If this is not built in to ST then it is built in to a default plugin and that means this is still just SMOP, a simple matter of programming… that is beyond me.

i DO now see this as being a “feature” and not a bug but it is an incorrextly implemented feature. The auto UNDENT should not happen unless the previous line was a break. or it should be inhibited for the very first case of a switch statement.

0 Likes

#11

To customize C++ indentation rules, you’d want to override Packages/C++/Indentation Rules.tmPreferences

0 Likes