How to correctly use addOpener (not registering function)


I’m trying to use addOpener to just open a particular filetype with a view I’ve written, and it doesn’t appear to be registering, either when I open a file manually with ctrl-o, or when I call

Here is the code:

atom.workspace.addOpener (uri) ->
  console.log "hey"
  atom.workspace.activePane.activateItem new MyView uri

As you’ll note, the opener is registered for every possible filetype. However, when is called, the view is not displaying, and the console.log is not showing up at all. I’ve tried limiting it by filetype, and when that didn’t work, I registered it for every possible uri. The console merely shows the result of an Why isn’t the opener registering?

Also, is opening with ctrl-o the same as an, or do the two call different functions?



You need to return an item opener object that has specific methods. Check out the example package html-tab.



I’ve actually created a package based off of html-tab already which does implement getTitle, getViewClass, etc, and opens a new tab as desired. The issue is that the activateItem call isn’t being fired, as evidenced by the lack of the console.log.

Calling atom.workspace.addOpener and giving it a function from the console seemed to work, but for some reason this part isn’t activating. It’s within the “activate” method of the package I’m developing, from where many other functions are being successfully called.

EDIT: the code is viewable at, if you’re interested.



Unfortunately I don’t remember details of how it works. I just always use html-tab as a template. I’m sorry I don’t have time to be more help right now. I’ll keep this bookmarked and try to help later today or tomorrow.



No worries, I appreciate the willingness to help.



So it was a result of the package not activating until an activation event was called. I found this thread explaining how no packages should activate until triggered by an activation event. Noticing this resolved the issue. I have, however, created a new thread asking about addOpeners and package activation.



Just so you know, you don’t have to activate the item yourself, just return your view and Atom will make it the active item automatically.



Huh! Good to know. I’ll fix that immediately.