Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automatically clean up lines that I type, but not others #8

Closed
glyph opened this issue Mar 1, 2012 · 9 comments
Closed

automatically clean up lines that I type, but not others #8

glyph opened this issue Mar 1, 2012 · 9 comments

Comments

@glyph
Copy link

glyph commented Mar 1, 2012

If I'm editing a file, I don't want to add new trailing whitespace, but I also don't want to be submitting massive diffs that clean up all the whitespace in a big file while I'm making an unrelated change.

So when I type "return return ", I want to automatically clean up the whitespace that's left behind, but I don't want to use the "nuclear option" of "delete trailing spaces", since that's going to affect lots of lines I didn't write.

A good start on this would be for "delete trailing spaces" to only work on selected lines, if there's an active selection.

@chikamichi
Copy link
Contributor

This is an interesting feature. I'm afraid I don't have the time to work on this right now but I'll consider it when I have the time.

@FichteFoll
Copy link
Member

I propose renaming the current command to like "delete trailing spaces in file" and adding a new command with the old name and said behaviour, only considering selected lines or those with selection in them.

@chikamichi
Copy link
Contributor

We can't blindly rename the command for users did set mappings to it.

I think the ultimate level of flexibility would be to allow users to specify which behavior they expect based on the file type (this would solve several issues/feature requests at once), with some sensible defaults.

@FichteFoll
Copy link
Member

Okay, that's actually an issue, didn't think about that. You could notify users using Package Control update messages but still, everyone would have to rename his possible key bindings or whatever. I just thought that it would be a nice default behaviour.

Well, analog to that, a "delete trailing spaces in selection" command should work wonders. For ultimate flexibility, add a setting which specifies a scope selector which then specifies when to use the selection command by default. This is probably the easiest way to code if it's actually needed and does not hurt if it remains untouched.

@webwurst
Copy link

I would really like to see this option for Sublime. It is available in RubyMine for example:
Strip trailing spaces on Save -> Modified lines - Strips trailing spaces only in the end of modified lines.

@chikamichi
Copy link
Contributor

@webwurst I don't know yet if ST provides a way to monitor "modified lines" only in easy way, apart from the "recent changes" buffer (in which case the trailing spaces deletion would probably occur on the fly, not upon saving). I'll look into that and try to figure out a way to do this, this is a really handy feature!

@FichteFoll
Copy link
Member

You can perform diffs like the default implementation in the Default package.

Edit: "diff_changes" command.

@chikamichi
Copy link
Contributor

@FichteFoll thanks for this hint. I guess I can use difflib to get back to the line numbers of the edited lines with respect to what diff_changes consider to be the diff (aka. since last save for dirty, already saved documents), so this should not be too much of a pain. Feature planned!

@chikamichi
Copy link
Contributor

@glyph @FichteFoll @webwurst #36 implements the Modified Lines Only feature. I think this is pretty close to this feature request, and the behavior of trimming left-over trailing spaces upon pressing Enter is handled by Sublime Text as well. I'm therefore closing this issue! Hope you'll enjoy the new features from v1.0.0.

@chikamichi chikamichi removed their assignment Oct 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants