Auto code completion for IJ macro

Hey @bramvdbroek,

welcome to the forum!

That’s indeed annoying. Thanks for the bug report!

I just added a timeout: It should stop searching for auto-completion entries after 250 milliseconds. Furthermore, I increased the minimum word length to 2.

Would you please test it again?

Who wants to test the new-new version, just download imagej-legacy.jar and put it in the jars directory of your Fiji installation. Please remove the other image-legacy.jar in the same folder. Restart Fiji afterwards.

Thanks a lot!

Cheers,
Robert

2 Likes

Thanks @haesleinhuepf,

The minimum word length of 2 characters works well (good idea), but the delay after typing ‘ru’ is still about 2 seconds, in my hands at least.

Best regards,
Bram

2 Likes

Hey @bramvdbroek,

could you please try again with a freshly downloaded imagej-legacy.jar ?

I just introduced a maximum number for search results hoping the the UI responds faster now. In case you can confirm that it’s working better now, @ctrueden might consider putting the update into the currently running wave of updates…

Thanks again!

Cheers,
Robert

2 Likes

Hi @haesleinhuepf,

I’m so sorry, I didn’t get a message that you responded and I forgot about it afterwards. (I guess it was not that annoying after all. :wink: ).
Anyway, I just tested your newest version on two different computers, and it’s blazing fast now. Thanks!
I’d say green light for @ctrueden to implement it.

Best regards,
Bram

1 Like

Thanks @bramvdbroek! Thanks for reporting and checking. That’s quality assurance as it’s supposed to be :slight_smile:

I just merged it. I guess it will be in the next release cycle.

4 Likes

Thanks for sharing it.

1 Like

Hey auto-complete fans, testers and early adopters,

I just started the next iteration; auto-complete V3. Several people asked for auto-completion of variable names


and functions

If you want to try it, please download imagej-legacy.jar, put it in the jars directory of your Fiji installation and delete the other version of imagej-legacy. Restart Fiji afterwards.

Feedback very welcome! I’d like to know especially if anybody experiences performance-loss due to this addition.

Cheers,
Robert

4 Likes

Hi, Robert!

As usual, this is great!

I’ve been playing with it for a while, tried it with some lengthy macros, and I haven’t noticed any hit on performance.

There are, however, a couple of issues that I noticed:

  1. Variable (but not function) names with underscores are currently ignored:

  2. Variables and functions that are capitalized need a case-sensitive cue (unlike built-in functions):

Finally, with these features up and running, I see an oportunity for a feature request:

Could it be possible to also list all the custom additional functions?
These can be loaded using

call("ij.macro.Interpreter.setAdditionalFunctions", block_of_code_with_functions);

Then, once added, you can inspect their code with

custom_functions = call(ij.macro.Interpreter.getAdditionalFunctions)

I use them quite often, and have them to automatically load at startup from a custom folder. As I keep adding new ones, it is not unfrequent to forget their actual name (or the order of the parameters), so I even made a custom function to list all the custom functions (and doc lines). Having them properly listed in autocomplete would come really handy. :grin:

Thanks again for all the good work and effort you’ve put into this amazing feature!

Cheers,
Nico

1 Like

Hey @NicoDF,

it’s a pleasure working with you - as always.

I just fixed

  • Underscores :white_check_mark:
  • Upper/lower case :white_check_mark:
  • I also put macro-dependent stuff first and sorted it alphabetically :white_check_mark:

Regarding the additional macro functions, I need to check things a bit deeper. But thanks for the great suggestion!

Again, if anybody wants to try it, please download the new version of imagej-legacy.jar, put it in the jars directory of your Fiji installation and delete the other version of imagej-legacy . Restart Fiji afterwards.

Cheers,
Robert

1 Like

That was fast!
I really like the new sorting of the list.

Thanks!
Nico

1 Like

Feature request? Could the dialog populate with any comments enclosed by /* */ directly after the function declaration to use as documentation?

It would certainly encourage me to comment my code more :slight_smile:

Congratulations on this though, loving your work.

3 Likes

Hey @DrLachie

welcome to the forum! As it’s your first post, I’m considering implementing this. That should also encourage more people to join an throw their ideas towards the developers. :wink: However, I’d say it’s pretty common that comments for functions live above them… :thinking:

Cheers,
Robert

Thanks!

I thought convention in python at least was docstrings following
def function():
‘’’ This is what the function does ‘’’

but happy to change my ways if it adds functionality (pun intended).

Hey @NicoDF ,

here comes your feature:

Auto-complete recognizes methods in the additionalFunctions memory. However, this can only work after the code was executed at least once.

And hey @DrLachie,

It reads your comments now - above the method

and below

The /**/ appears a bit more complicated, but I keep it in mind and you posted.

Again, if anybody wants to try it, please download the new version of imagej-legacy.jar, put it in the jars directory of your Fiji installation and delete the other version of imagej-legacy . Restart Fiji afterwards.

Cheers,
Robert

3 Likes

What can I say, @haesleinhuepf? You rock! :metal:

I launched FIJI, typed for one of my custom functions, and it works with both the new features right off the bat:

BTW, @DrLachie, thanks for your feature request. It was spot on.

This will change the way users approach writing macros.

Thanks again, Robert!

Nico

PS:
For anyone curious about custom functions, my small contribution: here’s the code snippet that I’m using to automatically load functions at startup from a folder. It should be placed as an .ijm file (e.g. “install custom functions folder.ijm” ) in /macros/AutoRun/ (and have the variable custom_folder modified as needed)

/***** Installs custom functions from folder *****
 * To load at startup, this macro file should reside inside /macros/AutoRun/
 * 
 * Nicolas De Francesco (image.sc @NicoDF), July 2019
 * Scanning folder trick taken from Fiji's AutorRun_Scripts.ijm 
 */

custom_folder="/function library/"; // modify to suit your needs. The folder should be inside the macros folder.

functionDirectory = getDirectory("macros") + custom_folder;
if (File.isDirectory(functionDirectory)) {
    list = getFileList(functionDirectory);
    for (i=0; i<list.length; i++) {
        path=functionDirectory + list[i];
        functions = File.openAsString(path);
        existing=call("ij.macro.Interpreter.getAdditionalFunctions");
        if(existing==0) existing="";
		call("ij.macro.Interpreter.setAdditionalFunctions", existing+functions);
    }
}

showStatus("Custom Functions Installed");
5 Likes

Awesome! Now watch me religiously add comments to all my custom functions (for about the next two weeks). Thanks for implementing it @haesleinhuepf!

And @NicoDF, I’ll be giving your tip a shot next week too! That’s going to save me a lot of time copying standard custom functions between macros.

2 Likes

Hey all,

I wrote a little tutorial on how to extend ImageJ macro auto-completion with custom entries. Basically a guide for plugin developers and a chance for advertising online resources and how to cite algorithms and tools :wink:

As always: Feedback is highly appreciated :slight_smile:

Cheers,
Robert

3 Likes

For the record, additional functions can also be kept in an unadvertised “Library.txt” file at the default macros location and those will be installed automatically.

Jerome.

1 Like

Hey @jerome,

wow, I didn’t know that. I’m a bit confused. What is expected in this Library.txt file? Macro code or paths to jar files? Do you have some example using this technique?

Thanks!

Cheers,
Robert

Hi @haesleinhuepf , this file can be used to store macro functions that will be available in any macro you write, basically the same thing that @NicoDF described in his method. The content of this file is added to the interpreter using setAdditionalFunctions:

Jerome

1 Like