How can I access a package scope to run a function defined inside a package


#1

I’ve made a function in my package called getEditorFromPath() which, given a file path, returns the atom editor instance which has it open.

How can I access this function from outside of the package? For example, how would I run it in the dev tools console?


#2

Every package can access the global atom object and set things on it. You can assign a function to it with this syntax:

atom.myPackage.getEditorFromPath() = this.getEditorFromPath()

Then, from the dev tools, you can use atom.myPackage.getEditorFromPath() to run that function.


#3

Cool. I guess that’s a workaround. Strange there’s no way to access them directly. Thanks a lot anyway!


#4

You can also use the atom.packages.getActivePackage() method, as well. If you do, your function will be under pkg.mainModule.getEditorFromPath().