Add EventListener on whole editor for Save event, not just current view


I have a problem with adding a callback on the Save event.
I want to add it to the editor, to be able to catch the Save event in all views including those not already opened, without having to add it manually for each.

I have this code, I would like to do the same for everything.

  activeView = atom.workspaceView.getActiveView()
  activeView.preempt 'core:save', (e) =>


Something like this should work:

atom.workspace.eachEditor (editor) =>
  editor.on 'will-be-saved', =>

In CoffeeScript the @ is shorthand for this. and is the canonical way to write it.


Hello boys,

I am trying to handle the will-be-saved event…
But I want to do that directly in my index.js, not in the coffee file…

I don’t know the correct syntax to do that anyone can help me ? I have read your answer Leedohm but I am not comfortable with the Atom syntax for coffee and js :wink:


You can always go to the Try CoffeeScript tab at and paste in the CoffeeScript. It will translate it into JavaScript for you.


Hey men you do a mistake :wink:

atom.workspace.eachEditor (editor) =>
    editor.buffer.on 'will-be-saved', =>

You forgot to select the buffer of the editor to listen to an event :slight_smile:

I do this just for my neighbors :wink:

Ps: Thank you for