Atom is unusable with PHP, ASP, etc


#1

With every save, a blank new line is added to the end of every file. This breaks PHP projects with multiple files that require setting the header. This would also break ASP, and any language that combines markup with scripting.

The problem is, a new line after the ?> actually outputs this blank line as content. Now header data can’t be set, as content has already been output. Since I can’t set the header, this breaks complex scripts which must return images, CSS, files, etc.

Don’t add a new line to my file if I didn’t type it myself!


#2

All that’s necessary to change this behavior is to:

  1. Open Settings
  2. Go to the Whitespace package
  3. Uncheck “Ensure Single Trailing Newline”


Deleting empty lines at end of text files
#3

@leedohm You were too quick, I didn’t had the time to post my answer :grinning:.

As for why ensuring a newline char at the end of the file is the default, it seems it takes root in Unix handling of text file and best practices when dealing with unix tools and diffs:



#4

You could omit the closing “?>” in php files containing only php code.


#5

This is precisely why most people leave off the closing tag.


#6

Thanks for the feedback all! Seems I was hasty in my criticisms of Atom. Two things I learned:

  1. It’s okay to not close ?> php tags in PHP only files
  2. You can disable the added whitespace in settings.

Hope this helps someone else. Cheers!


#7

With the EditorConfig package you can have settings down to a file type specificity that even works across editors. Open a php file? It leaves your newlines alone. Switch to a C file? It automatically adds newlines without having to mess with editor settings all the time. You can even have different settings for different projects or subfolders.

http://editorconfig.org/