How would I get a file's content on save?


I got the save part down
or at least I think so


There’s a fine but necessary distinction between the file (what’s stored on disk) and the buffer (what appears in the editor). Now, if you don’t specifically need to look at the file, there’s a getBuffer() method on the same TextEditor object you’re calling onDidSave() from.

If you need to look specifically at the file, you’d use Node’s fs module.


Should I use cachedText or cachedDiskContents


Neither of those methods appear in the Atom API or Node’s fs. What are you using?


It is from the response of getBuffer


Since the first comment, I discovered that there’s a getText() on the TextEditor as well as on the TextBuffer. So you’ve subscribed to onDidSave() as some variable (let’s call it editor) and you can grab the text with var contents = editor.getText(). That saves you a step.


That works thanks