Editor.append is not a function


I am trying to use the following code to append text to a file.

atom.workspace.open(filesArray[i].in).then((editor) => {
range  = editor.append("abcdef", {});
marker = editor.markBufferRange(range, {invalidate: 'never'});
editor.decorateMarker(marker, {type: 'highlight', class: 'changeColor'});

However I keep on getting the error ->

Uncaught (in promise) TypeError: editor.append is not a function

Link to append Documentation


I would console.log the editor first, to see if it’s what you’re expecting. That .in you have on the files array looks unfamiliar to me.


The .in is just the path to the file.

The console.log gives this:-


You linked to the TextBuffer docs.

I like to think of the buffer as the “raw text, no frills” layer, whereas the editor contains the buffer, plus all the decorations and meta data, etc. Many methods of the editor are just connections to the same methods in the underlying buffer, but apparently this method isn’t connected like that.

To fix, just use buffer = editor.buffer. Then you can use all the methods in the TextBuffer docs.