Any event when a file is opened?


#1

I want to detect character encoding of a file automatically when I open the file.
The onDidOpen event is helpful for it but is not perfect because this event is only triggered when you open a file manually.
When you invoke Atom with some files, onDidOpen event is not triggered.
Are there any good alternatives for onDidOpen?


#2

The atom.workspace.observeTextEditors method is the canonical way to set up a callback for when files are opened. It will also notify you of any editors that are already open when you first set up the observer.


#3

leedohm-san,

Thank you for your comment.

Is a callback registered by observeTextEditors invoked only when the editor is created?

I could not understand when the callback is invoked from its method name and documentation.

Usually ‘observe’ means invoking when the state of the editors, I think…

Anyway I will experiment observeTextEditors.

Thank you!


#4

Yes, it triggers only when a text editor is created.