95
$\begingroup$

Although we already had a question asking for development alternatives to Wolfram Workbench, I want to ask a more specific question:

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.

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

2 Answers 2

91
$\begingroup$

This is a constantly growing answer. To make it easier to track the updates of this answer, I separate every added section and give appropriate headings. If you read this for the first time, please start directly below. Updates to this answer can be found at the end.

Most important thing first: There is an

and here is a quick howto install

  • Download the free Community Edition of IDEA
  • 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.

(Original answer)

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.

enter image description here

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

enter image description here

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

enter image description here

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

enter image description here

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.

Important links


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:

enter image description here

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.

enter image description here

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:

enter image description here

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.

Formatter

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

enter image description here

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

enter image description here

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.

$\endgroup$
26
  • 11
    $\begingroup$ can you run mma code in it, or is it just an editor, at the moment? $\endgroup$
    – rcollyer
    May 8, 2013 at 0:45
  • 2
    $\begingroup$ @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. $\endgroup$
    – halirutan
    May 8, 2013 at 17:39
  • 2
    $\begingroup$ @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 :) $\endgroup$
    – rm -rf
    May 11, 2013 at 22:19
  • 2
    $\begingroup$ @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. $\endgroup$
    – halirutan
    May 23, 2014 at 5:17
  • 3
    $\begingroup$ Noob alert: as there is no option to "run", what is the work flow process? Do you write code in intelliJ and then go to wolfram and manually compile each time to text your code? $\endgroup$ May 27, 2016 at 7:02
8
$\begingroup$

Actually IntelliJ IDEA can build and run Wolfram code.

Mathematica REPL on Github

I think it's a good start. Let me explain what happened in the GIF below.

After I change the code in IntelliJ IDEA, I press Command+R, then the REPL(Mathematica) will build and run the code. I don't have to leave IntelliJ IDEA, I can code In IntelliJ on the fly and see the results in the REPL.

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ +1 More details please :) See additionally here where I wrote a very long answer to your message in chat. $\endgroup$
    – halirutan
    May 13, 2017 at 1:32
  • $\begingroup$ What does it mean to "build" the code? $\endgroup$
    – Szabolcs
    Jul 9, 2018 at 10:54
  • $\begingroup$ @Szabolcs You are right, there is no actually build phase, it loads the code. $\endgroup$
    – webcpu
    Jul 9, 2018 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.