Hungry backspace suggestion

When I have: "text - multiple whitespace - text", when backspacing it's very
rare that I want to join the text before and after the whitespace.

Could the plugin leave one space before the caret if the character after the
caret isn't whitespace?


4 comments
Comment actions Permalink

Heh.. I think we're starting to approach diminishing returns here. You got the 99% solution, and you want that extra 1% !

I agree that it is more likely you would want to leave an extra space in that case, although someone else might find it strange if it did that for only that case. It would probably have to be an option.

Based on the code style->spaces settings, you can determine whether there should be a space left before the caret or not. But there are some ambiguous cases.

Following cases are unambiguous: keywords(if, while, for, catch, switch, synchronized,etc.), a method name, operators, within parentheses. For example:

if (                  
if ( statement )      
expression +          
]]>

Hitting backspace would leave a space before the caret based on the appropriate code style setting "before if parentheses", "inside parentheses", "before if left brace", "around assigment operators", etc.

But there seems to be lots of ambiguous cases.

For example, when you have a variable(int) n at the end of the line
... n ]]>
there could be multiple things added after n
n ==
n +
n;
n)
and each of those have their own space setting, e.g. "space before semicolon", "space around assigment operators", etc.

It seems too complicated, and the fact that the behavior doesn't follow a simple rule makes it less attractive.

I'm working on something similar, but more limited and simple, for AutoNewline plugin. When you press semi-colon, it automatically formats the space between the semi-colon based on the "space before semi-colon".
For example, if the caret was positioned here:
int n = 0 |
and your "space before semi-colon" setting was false, then pressing semi-colon would produce:
int n = 0;


I'm doing the same thing for period (.) operator, to cleanup cases where the completion leaves an unnecessary space,e.g.
Coll<CTRL+SPACE>

Collections

Typing period (.) here would cleanup the extra space.
Collections.sort(

-Alex

0
Comment actions Permalink

Based on the code style->spaces settings, you can determine whether there

should be a space left before the caret or not.


I'm not really caring about the codestyle space settings.

I care for example:

final |String

Pressing (hungry)backspace results in:

final|String

My suggestion: when the plugin is deleting multiple whitespace, and both
the caracter before and after the caret is part of an identifier
leave one space separating the identifiers.


0
Comment actions Permalink

Carlos wrote:
======================================================
My suggestion: when the plugin is deleting multiple whitespace, and both the caracter before and after the caret is part of an identifier leave one space separating the identifiers.
======================================================

This sounds simple enough and understandable enough. I would just look at the first character before and after. If they are non-whitespace and an identifier char ( then it will preserve a space. I think it should work even when there are multiple lines, e.g.


I will probably add an option in other.xml called 'Preserve Space between Identifiers' default On since I don't see any downside.

-Alex

0
Comment actions Permalink

And another:

....x.someThing();
....
....
................|y.doAnotherThing();

What about hungry backspace in this case only moving the text to the tabstop
on this line.

....x.someThing();
....
....
....|y.doAnotherThing();

I find that for one reason or another I find myself in this situation
(mostly when using the LineUpAndDownMover to move things outside if's and
loops) and I really don't want to delete lines.


And what about the next hungry backspace eating only one line

....x.someThing();
....
....|y.doAnotherThing();


This last came to me because I'm really finding that hungry bacspace is
really a little too hungry :)

My pros:

-> When text is unaligned it's more probable that I want to align it than I
want to join two lines.
-> When there are two empty lines, it's very possible that I want to leave a
one line interval between the lines.
-> Pressing backspace twice instead of once doesn't seem that much more
work.
-> It's more intuitive this way.
-> This is the way I would like it to work :)

Possible cons:

-> This is not the way emacs hungry backspace works (don't know, never used
emacs).
-> Others (very tickheaded users :) don't work like this.

Carlos



0

Please sign in to leave a comment.