5
$\begingroup$

Background

I am currently working on a large software development project written in the Wolfram Language and I would like to organize my code in Wolfram Language Packages and Scripts (.wl files. See reference pages for scripts and packages) because

  1. it can then be run from a machine without GUI / a cluster
  2. it is easy to profile / debug .wl files in Wolfram Workbench
  3. in contrast to Mathematica notebooks (.nb files), package and script files can easily be put under version control.

Problem

My problem is now, that I can't find a way to easily edit .wl files. For me, an editor should have two important features:

  1. Automatic code indentation (I like the automaitc code indentation that Mathematica applies to .nb files)
  2. Easy way to import / paste code from a .nb file to a .wl file.

I have already tried two ways to edit .wl files: Wolfram Mathematica and the Wolfram Workbench. In neither editor, the automatic code indentation works properly. When I enter an example function in a Mathematica notebook, it looks as follows:

solveAProblem[] := Module[{},
  hello = 7;
  If[Global`a == 7,
   Print["I'm a function from a package"]
  ];
 ];

This is what I want (it does not have to be exactly the same indentation depth, but a qualitatively similar result would be nice). The same function entered in exactly the same way in a .wl file edited in Mathematica looks as follows:

solveAProblem[]:=Module[{},
hello=7;
If[Global`a==7,
Print["I'm a function from a package"]
];
];

If I would only want to enter code manually, this would be no problem (I could just add tabs where I would like to have them). However, when I copy code from a notebook, the indentation is lost and there is too much code I have to copy to add the identation manually. Therefore, I need an auto indent tool.

Wolfram Workbench features an auto indent tool, however it does not work properly for For and If commands. When I apply the auto indent tool to the example function from above (the one without any indentation), the result looks as follows:

solveAProblem[]:=
    Module[{},
        hello=7;
        If[Global`a==7,
            Print["I'm a function from a package"]
];
    ];

As you can see, the closing bracket of the If statement is in the wrong position. For small functions, this is not a problem and can be corrected manually. However, for large functions with more than 100 lines of code, I would prefer an automatic indentation tool that I can rely on.

Question

Does anyone have an idea on how to set Mathematica or the Workbench up to automatically indent code properly? Or is there another editor that is suitable for my purpose?

Thank you a lot in advance for your replies!

$\endgroup$
3
$\begingroup$

I found this plugin which works for several JetBrains IDEs. After using it for a while, I think that it suits my needs.

$\endgroup$
1
$\begingroup$

I am using Eclipse Neon.1a with Workbench 3.

It produces:

solveAProblem[] :=
    Module[ {},
        hello = 7;
        If[ Global`a==7,
            Print["I'm a function from a package"]
        ];
    ];
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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