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


#1

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


#2

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.


#3

Should I use cachedText or cachedDiskContents


#4

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


#5

It is from the response of getBuffer


#6

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.


#7

That works thanks