Nit: the editor removes whitespace from the current line on save if it is blank


#1

Steps to reproduce:

Type some code, eg:

function foo() {|} // '|' is the cursor

When you hit return with autoindent on, the cursor adds soft tabs:

function foo() {
  |
}

If you then hit save, the editor removes all whitespace from the current line and puts the cursor at column 0:

function foo() {
|
}

Expected: you shouldn’t remove whitespace from the current line on save, the user almost always has to recover by re-indenting.


Atom changing random parts of file
#2

This is intentional to remove trailing whitespace at the end of lines. You can turn it off by disabling Preferences -> Whitespace -> Remove Trailing Whitespace.


#3

A few suggestions:

  1. IMO removing trailing white space on save should not be on by default, if your project uses source control and you use this feature your diffs will be terrible.
  2. I think the right thing to do is preserve whitespace on the current line even if the option of removing whitespace on save is enabled.
  3. being modular is great generally but whitespace settings feel like a core feature to me. I looked for something in settings, I just didn’t scroll far enough down in the preferences to see the separate package settings.

#4

What it is more terrible to me is people who let trailing spaces at the end of lines! :smile:


#5

I’m working on something that fixes some of the unexpected behavior this causes here. It doesn’t disable it by default (I’m kind of with @Pym on that one – but there will probably never be full consensus on this either way), but it does solve the issue you mentioned in your original post (which I had found annoying as well).


#6

Okay, this change is going to be included in the 0.65.0 release when it comes out. It’ll be on by default, but can be turned off to get the original whitespace behavior back if desired. :metal:


#7

I think the whitespace module is misguided. There are two scenarios:

  1. atom is the only editor editing the file, or
  2. there are several different editors editing the file.

In scenario 1) the whitespace module is fine, but in scenario 2) there is likely to be a fight. When using version control, this becomes very annoying.

I believe the correct thing to do is to make sure atom cleans a row from unnecessary whitespace when it is modified (i.e. when cursor leaves a row (or buffer is saved) where at least one character was inserted/deleted). In scenario 1), the result is the same. In scenario 2) only modified lines will be touched, which keeps version control happy.

In its current form, I cannot recommend atom to my students; requiring that everyone on a project disables a module is not workable.


#8

Or you could give your students an extra-credit assignment to add the feature to the whitespace package :wink:


#9

There is no problem if everyone has auto-trimming off or everyone has it on. The problem is you’ll never get everyone to agree.

I for example can’t stand auto-trimming. I line up spaces on the right all the time for future rectangular pasting. And rectangular cutting leaves them correct for me also.


#10

Using 1.0 and I don’t see a setting for “Preferences -> Whitespace -> Remove Trailing Whitespace”. How can I disable this?


#11
  1. Launch the Settings View using Cmd+, on OS X or Ctrl+, on other platforms

  2. Click the Packages tab

  3. Type whitespace into the search box and then click the Settings button

  4. Uncheck Remove Trailing Whitespace