Strange behavior of editor.onDidSave


I use the following code in my plugin:

activate: (state) ->
    atom.config.observe 'php-cs-fixer.executeOnSave', =>
        @executeOnSave = atom.config.get 'php-cs-fixer.executeOnSave'


    @subscriptions.add atom.workspace.observeTextEditors (editor) =>
        @subscriptions.add editor.onDidSave =>
            if editor.getGrammar().name == "PHP" and @executeOnSave
                @fix() # if @executeOnSave

The onDidSave only works if I once run the code with the shortcut. Perhaps I am understanding something wrong… I hope someone has a tip for me.


here is the complete code


Your package.json contains activationCommands, which means that your code (and the subscription to onDidSave) only runs after you execute php-cs-fixer:fix.
Remove activationCommands if you want to execute your code and subscribe to events when atom starts.


After removing that command, it works like a charm! Thanks a lot, you saved my day!