Save file at path without changing path


#1

Is there a way to save a file under a given path and not changing the buffer to point to that path? The code I have currently looks like

editor = atom.workspace.getActiveTextEditor()
editorPath = editor.getPath()
editor.saveAs(fullPath)
editor.buffer.setPath(editorPath)

However this seems a bit hacky for such a trivial thing - and if the file has been modified, after saving, Atom doesn’t recognize it as modified anymore.


#2

I would use something like this:

fs = require 'fs'

editor = atom.workspace.getActiveTextEditor()
fs.writeFileSync(fullPath, editor.getText())

This way you don’t have to change the state of the editor at all.