Integrate Magit With JetBrains

I’m a huge fan of Magit. I honestly can’t imagine doing software development without it. However, I’ve recently moved from Emacs to JetBrains products like PyCharm, WebStorm, and IntelliJ to take advantage of some of their more advanced features. In my opinion, Magit is light years ahead of the JetBrains version control client.

I wanted a good way to integrate my existing Magit workflow into my new JetBrains workflow. I started off with some hints from JetBrains and some more from Atlassian’s Developer Blog and came up with something that works for me.

Screenshot of External Tool dialog

Program:            /usr/local/bin/emacsclient
Arguments:          -n -e "(progn (x-focus-frame nil) (magit-status))"
Working directory:  $FileDir$

Ensure Emacs is always running (it already is, right?) and that you have started a server. I make sure this happens by default by adding (server-start) to my Emacs config file.

Now, you can call emacsclient to pass commands to your running server.

In this External Tool configuration, we are calling (x-focus-frame nil) to bring your Emacs frame to the foreground. This works on macOS Catalina, but you might need to try (raise-frame) if you are on a different OS.

Finally, calling (magit-status) will bring up the Magit status page.

Make sure the “Open console for tool output” is unchecked to avoid cluttering your JetBrains workspace.

Finally, you can assign the External Tool to a keyboard shortcut or assign it an abbreviation in Preferences > Keymap.

For more ideas, see Invoking emacsclient and emacsclient Options