How to modify the buffer just before saving, and just after loading


#1

Hello,

I would like to modify the buffer just before the save, and just after the loading.

i have seen people listening to buffer event like the following. Is that the proper way ? i am not sure it respect the order

editor.getBuffer().on 'saved' , =>
  # your code goes here

how can i get the list of all signals dispatched to buffer ? maybe there are others signals more suitable than "saved"


#2

i replaced it by the following and it seems to works

    # hook .onDidSave - reformat for view once saved
    editor.getBuffer().onDidSave =>
      console.log('did save event')

#3

and i found the list of all signals here https://github.com/atom/text-buffer/blob/master/src/text-buffer.coffee#L202


#4

If you want to modify the buffer before the save event, you might want to use TextBuffer::onWillSave instead. While the docs are not yet complete, often they contain most of the functionality already. You can find them at https://atom.io/docs/api/latest/Atom.

Discrete events are named onDid[Verb][Noun] or onWill[Verb][Noun], for events that already happend or are about to happen, respectively. For more information take a look at the API Conventions section of this pull request.