Code Styling Preferences For Autofill Features


#1

I just started using Atom for web coding (php/…). I was amazed by the autofill features but is there any way to change the code styling. I don’t want the curly brackets to be in the next line, but at the end of the previous line for example.


#2

First it’s important to know whether you’re activating a snippet or using the autocomplete feature. Describe what actions you take that cause the curly brackets to appear.


#3

autocomplete

I’m basically typing in class and pressing enter. I think that’s the Autocomplete feature…


#4

That’s a snippet, and specifically it’s this snippet. In order to override it, you just need to create a new snippet in the same location in your own snippets.cson file, like so:

'.source.php':
  'class …':
    'prefix': 'class'
    'body': '/**\n * $1\n */\nclass ${2:ClassName} ${3:extends ${4:AnotherClass}} {\n\t$5\n\tfunction ${6:__construct}(${7:argument})\n\t{\n\t\t${0:// code...}\n\t}\n}\n'

In particular, take note of the fact that the snippet name is class …, not class ....


#5

It’s legitimate to pick your own coding style, especially when you’re a beginner!

At the same time I feel it’s probably best to get used to the PHP Standards Recommendation (PSR) from early on. One day you might want to contribute code to other projects (co-workers or open source) and it’s more likely they enforce PSR. Atom packages like php-cs-fixer or php-fmt make it easy to apply these recommendations on your code.