How do you (correctly) watch for file open events?


In my on going efforts to create a ‘jump to recent file’ shortcut (aka function-E in pycharm; opens a sorted list of recently open files by last-open-file time), I’m trying to access either a trigger that occurs every time a file is opened.

My bet efforts so far have only got me as far as the lastOpened property on Editor:

var editors = atom.workspace.getEditors();

  for (var i = 0; i < editors.length; ++i) {
        var buffer = editors[i].getBuffer();
        if (buffer && buffer.file) {
          console.log(editors[i].lastOpened + ":: " + buffer.file.path);

…the question is, what’s the right way of accessing the same data?

(obviously writing a package that just happens to work at the moment due to undocumented apis isn’t a great decision).


What about atom.workspaceView.eachEditorView? Like in the init script sample?


It looks like the “pane:active-item-changed” event might fire when tabs are switched.
“pane:item-added” might fire whenever a file is opened.


Ah, eachEditorView is exactly what I needed! Thanks~