Smart backspace indent


#1

Hi everyone.

I switched from phpstorm recently and well, i miss STRONGLY this feauture -> click me

I know that can be done in atom with a custom package so, do you know the name of the package? (i made a search but i didn’t find anything) if that doesn’t already exist how do you think can i achieve that?


#2

I want to clarify what you’re looking for. The visual demonstration shows two features:

  1. If the current line is indented deeper than surrounding lines, backspace moves it to be flush with surrounding lines.
  2. If the line above is blank or contains only whitespace characters, backspace deletes the blank line and preserves the indentation level of the current line.

There are a few things that someone trying to match that functionality would need to understand.

  • If both of the above conditions are true, which one takes priority?
  • For (1), does the line above or the line below the current line take priority?
  • If neither of the above conditions are true, backspace behaves normally?
  • Is there a keybinding in PHPStorm to force normal backspace behavior?

#3

I have to admit also, I completely dropped Atom for intellij because of this reason. A very important feature.


#4

In that case, please help me out by answering my questions about how the feature works.


#5

Sublime text has a plugin for this:
https://packagecontrol.io/packages/Hungry%20Backspace
Check the demo out or install it.


#6

I don’t have Sublime Text and the demo can’t answer my questions (because it’s a GIF, and not a human).


#7

Then install sublime and the plugin and see the behaviour yourself (it’ll take you just 5 minutes).

If you don’t want it doesn’t matter, I have switched to sublime so I don’t need this anymore.


#8

It is unreasonable to ask for assistance and then not be willing to spend any effort to help the person who offers to help you.


#9

Ok sorry.

There are a few things that someone trying to match that functionality would need to understand.

  1. Both.
  2. Above.
  3. No.
  4. Yes.

That does help?

pdt: If I suggested you to see the behaviour yourself is because that way you’d have gotten better what i was looking for.


#10

I believe what @aaron12394 is trying to say is that if you had visually saw and experienced what smart backspace indenting is doing, then you would have a more deep understanding on how to implement it for Atom. Which is a good point, However, if he really wanted this feature, he would try to explain it the best he can lol. Nonetheless, I will try my best to explain it by typing words out.

If the current line is indented deeper than surrounding lines, backspace moves it to be flush with surrounding lines.

If there are empty spaces on top then it will move the cursor up, while preserving the indention level. However if you keep backspacing until there are no longer empty lines above within a braces, then it will move up right next to the first line that initiated the surrounding block.

If the line above is blank or contains only whitespace characters, backspace deletes the blank line and preserves the indentation level of the current line.

Yes, this is correct. I tried my best answering that in the first question too.

If both of the above conditions are true, which one takes priority?

When we are using an IDE such as PhpStorm or IntelliJ. We initially set a code style which involves the tab spacing rules. It can either be 2 spaces, a tab, or whatever they had set it to be for their default tab space code style for that specific language. The IDE intelligently will know where to stop the cursor when backspacing because of the rule we set in the code style. Once it reaches the recommended tab space that is for that specific surrounding block, it will continue to move the cursor up if there are any empty lines.

For (1), does the line above or the line below the current line take priority?

Not sure what you meant by this question, however, I hope I had answered this already in my answers above, if not, then let me know!

If neither of the above conditions are true, backspace behaves normally?

It will move up next to the line that has initiated the surrounding block eventually. So backspacing would never bring take you anywhere before your recommended tab space that is for the surrounding block. The only way to go back is by holding SHIFT and TAB.

Is there a keybinding in PHPStorm to force normal backspace behavior?

I don’t believe there is a key binding for disabling or enabling (not to sure) the smart backspace behavior, BUT there is an option to turn it off or on in preferences by checking or unchecking a box.


#11

I just created a atom package because i missed the features as well.
It currently only supports the hungry backspace on indentation.

It’s my first package and i haven’t tested it all that much.
If you miss something or encounter some bugs, please create an issue or do a PR :wink:


#12

Wow, that’s a strong need!
The feature is nice, indeed, and useful. But personally, I rarely encounter such overly indented lines, and I have, in Atom, a shortcut key to delete a whole line, so I feel less the urge to get this feature… :slight_smile:
Of course, to each their own, we don’t have all the same needs, habits, tastes. I just wanted to point out there are alternatives / workarounds.