Creating a package that adds UI and commands for a certain file type


Hi, I’m looking to make a package that adds some UI and commands to the editor view for only certain file types. Could anyone point me to some good examples or documentation? Getting a little lost going through the APIs.



I guess something like that would do:

atom.workspaceView.eachEditorView (editorView) ->
  filePath = editorView.editor.getPath()
  if /\.rb$/.test filePath
    # do something only for ruby files


@abe You would think there would be a way to leverage language-mode per editor rather than relying on filename conventions. I haven’t looked too much in that part of the code yet to know.


Sure, you can rely on the selected grammar (with the risk that the user use some grammar you don’t know about). AFAIK grammar selection is already based on file extension so it make sense to use that here as well, but, yes, that solution is not perfect and may backfire.


Does anyone know if explicitly checking file type or grammar inside a function is the only way to limit availability of a command to only certain file types? thanks


You can also limit the keymap selector so that it targets a scope that’s only found in that type of file. The best way is to check in the command logic, though. That’s more explicit.