# Open-source IntelliJIDEA plugin to support Mathematica development

One of the most advanced IDE's especially for Java programming is IntelliJIDEA which is as well available as open-source community edition. Is it possible to use this highly advanced environment to develop Mathematica packages like in Wolfram Workbench?

## Details

The people using Mathematica and developing packages can be divided in two types. The first type uses the front end exclusively even to write packages. The second type uses for package writing either Wolfram Workbench or a normal editor. The Workbench has several advantages

• it has highlighting and advanced Mathematica editing capabilities
• it supports the creating of documentation for packages which can be opened in the Documentation Center
• it supports debugging, testing and profiling of packages
• it has the support of advanced features like other IDE's, e.g. VCS support, support of Java, ...

On the other hand, there are disadvantages and the biggest one is, that the Workbench is closed source but still has many missing features and bugs. Therefore, the developers (like me and you) can do nothing but accept the situation although there surely are people who would help to improve the program and fix bugs.

One viable solution is to start building an open-source alternative to Workbench. One might ask why not building a plugin for Eclipse because Workbench is basically just an Eclipse with extended functionality. The reason is simple: I have experience with both Eclipse and IDEA and I think IDEA outperforms Eclipse in usability and functionality. Furthermore, I'm already a bit familiar with the plugin structure. Therefore, for a fresh start I would go for IntelliJIDEA.

-
There's an "answer your own question" checkbox ;-) –  Szabolcs May 3 '13 at 1:03
@Szabolcs I need one or two days more to bring everything in shape but I wanted to throw out the question some time before. –  halirutan May 3 '13 at 1:06
So you're giving us one or two days to try to catch up with you? :) –  Szabolcs May 3 '13 at 1:07
@Szabolcs I give you some time to refresh your java knowledge and start the engines. –  halirutan May 3 '13 at 1:11
@halirutan If I had two days of free time, I'd perhaps join the fun :-) –  Leonid Shifrin May 3 '13 at 1:13

Most important thing first: There is an

and here is a quick howto install

• start it and go to Settings -> Plugins -> Browse Repositories
• Search for "Mathematica" and install the Mathematica Support plugin: Right click (on OSX Ctrl+MouseClick) on Mathematica Support and Install Plugin.
• After a restart everything is set up and you can create a File -> New Project where you find now a Mathematica section.

## Yes, we can...

...extend IntelliJIDEA and make it a smart IDE for Mathematica package development. I started to develop such a plugin for IDEA a while ago and before going into the details, let me show you how it looks.

What you see above is the IDE with an opened Mathematica package. The code is highlighted and fully parsed, therefore when you made any syntactical errors, the green point at the upper right corner wouldn't be green. The parser gives you helpful messages when you made an error and shows you the point where it recognises that something is wrong. Furthermore, you see the documentation popup showing you on-the-fly help for built-in functions and operators. Let's look at some specific things in detail.

## Autocompletion

Currently the plugin autocompletes built-in functions while you are typing. You can use of course the famous Camel hump completion, meaning you don't have to type all the sub-words to a function: to get a completion for AlgebraicIntegerQ you can just have to type the sub-word starts AlInQ. Here is an example

The first choice is always selected automatically, so you can accept it with Enter or (if you want to insert brackets for functions automatically) Shift+Enter. Usually, there is no need to trigger the completion manually, but you can always use Ctrl+Space to do so. Using the arrow keys you can navigate through the list of suggestions and note, that you can call the QuickDocumentation with Ctrl+Q even inside this completion list.

## Quick usage lookup of functions and operators

Pressing Ctrl+Q (OSX Ctrl+j) when you are over or beside a function or operator opens instantly a popup window showing you the usage, options and attributes of it. For instance in this example while being over Message

This even works for all (but the most trivial) operators. With this, you never have to remember whether to use @@ or @@@.

## Matching braces, brackets and parenthesis

IDEA always tries to keep your braces correct. This means, if required it inserts matching braces and even if you close already closed braces, it tries to make intelligent decisions. Furthermore, matching braces are highlighted when you navigate through the code.

# Further development

Everything related to the development of the plugin will be announced and documented in the Wiki of the GitHub repository. First of all, I have to test parser and fix some minor bugs before continuing. Although I have a detailed list of features which you find in the README.md, I invite everyone to edit the Wish List in the Wiki. If someone thinks he/she can contribute to the Java-code itself, feel free ping me in the chat room for the plugin dev.

## Update (5. October 2013)

A lot of bugfixes, mostly under the hood, were done but additionally, some fancy features were added too. Here are the most important

Smart completion of Options

Smart option completion gives you only the options which are valid in the function you are currently in. Therefore, if you are in a position where you want to add an option to a function, pressing Ctrl+Shift+Space shows (or completes) only options which are possible at this place:

Completion of function arguments or local Module/Block/Table/.. variables

IDEA is now fully aware of all the local variables you have defined. Therefore, it will suggest them for you while you are typing (or when you press Ctrl+Space explicitely). Note that, of course, Camel Humps are working there too. This lets you use verbose variable names and it pushes your programming speed off limits.

Renaming, resolving and showing usages of local variables

IDEA lets you now easily see where you defined and used a symbol. Additionally, renaming of all instances is done in one step:

## Update: Formatting engine working (14.11.2013)

Although not perfect, I want to make an unofficial release which includes the Formatting engine. If you want to try it, please deinstall your current plugin first, download the plugin zip file from here and install it with Preferences -> Plugins -> Install From Disk.

The core part is the reformat code functionality which can be triggered with Ctrl+Alt+L (Cmd+Alt+L on OSX) or the line-wise auto-indent code which can be triggered by using I instead of L.

In addition to this, I had to improve the smart enter which helps you to complete a statement and can be triggered by Ctrl+Shift+Enter.

Therefore, try writing

Module[{blub},|]


with the cursor at | and the press smart enter. You see that it automatically puts the braces down and indents your cursor. Or type

Module[{var},
var = 1;
var+=v|
]


end when the autocompletion for var pops up, press smart enter. You see that it not only completes the variable name, it additionally reformats the line, puts a semicolon at the end and goes one line below

And before I forget, we have now our own Code Style settings section when you go to Preferences -> Code Style

There you can adjust which operators should be surrounded by space and you can define the indent. Wrapping and Blank Lines is not working right now.

-
can you run mma code in it, or is it just an editor, at the moment? –  rcollyer May 8 '13 at 0:45
@rcollyer At the moment it is nothing more than an editor. But even now you can create Mathematica SDKs by giving the path of a M-installation. This finds beside all AddOn packages the JLink.jar which we will use to support communication/evaluation with M. I have to say, this is currently not top of the TODO list. –  halirutan May 8 '13 at 17:39
@b.gatessucks I guess one way would be to become an expert at java and pitch in, so that halirutan is not overwhelmed by the task at hand :) –  rm -rf May 11 '13 at 22:19
@AndreiKucharavy Currently, there is no need to do this because the SDK (although it extracts all the package paths etc) is not used. If you still want to do this, then you have to do it after you created a project. There is still a bug preventing that you can create the SDK in the new project dialog. Therefore, after you have your project you go to Project structure (Ctrl+Alt+Shift+S) -> SDKs and you create a new Mathematica SDK selecting the path to your installation. –  halirutan May 23 '14 at 5:17
@AndreiKucharavy Please look at the second and third comment :-) –  halirutan May 23 '14 at 6:03