How to Open Files From Emacs to Android Studio (IntelliJ IDEA)

Thanks to Steve Smith by its post about Quick Tip: Getting Emacs and IntelliJ to play together, because now I can open files loaded with Android Studio (IntelliJ IDEA) to Emacs. But I wanted the feature to load files in Android Studio (IntelliJ IDEA) from loaded files in Emacs. Here is how to do that.

Following steps work for both Android Studio and IntelliJ IDEA, I am going to refer to both just as Android Studio.

Create command line launcher

On Unix based systems we have the option in Android Studio to go to Tools > Create Command-line Launcher... it let us choose the name of our command, I just leave it as studio (in IntelliJ IDEA default is idea).

After that we can run studio -h in the command line and see the studio command help.

Open files in Android Studio (IntelliJ IDEA)

Add the following function to your Emacs configuration.

(defun open-in-intellij-idea ()
  "Open files in Intellij IDEA."
  (interactive)
  (shell-command
    (format "studio --line %d %s"
      (line-number-at-pos)
      (buffer-file-name))))

Now on, wherever we are in a file buffer in Emacs that belongs to an Android Studio project and have Android Studio with that project opened, we run the previous function and Emacs will open the current file on Android Studio.

Posted by Carlo Eduardo Rodríguez Espino