Comments on: User-defined tab completions – take 2 https://undocumentedmatlab.com/blog_old/user-defined-tab-completions-take-2 Charting Matlab's unsupported hidden underbelly Mon, 25 Apr 2022 12:26:16 +0000 hourly 1 https://wordpress.org/?v=4.4.1 By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/user-defined-tab-completions-take-2#comment-462880 Mon, 18 Feb 2019 20:44:00 +0000 https://undocumentedmatlab.com/?p=6961#comment-462880 @Jim – you can implement a simple GUI that has an editbox, which searches for and displays the relevant file/folder completions whenever the user types anything in the editbox, as explained here: https://undocumentedmatlab.com/blog/editbox-data-input-validation

]]>
By: Jim Van Zandthttps://undocumentedmatlab.com/blog_old/user-defined-tab-completions-take-2#comment-462862 Mon, 18 Feb 2019 19:46:08 +0000 https://undocumentedmatlab.com/?p=6961#comment-462862 I have a significantly different use case (but one using many of the same keywords :-) – I have a function that asks the user to type in a path or file name, and I would like the function to tab-complete as the user types. The path might be anywhere in the directory tree, so adding JSON files everywhere is not practical. Do you know of a convenient way to implement that, using this function, or the GNU readline library, or something else?

]]>
By: Viktor Horvathhttps://undocumentedmatlab.com/blog_old/user-defined-tab-completions-take-2#comment-416520 Thu, 16 Nov 2017 18:52:25 +0000 https://undocumentedmatlab.com/?p=6961#comment-416520 Your comment was very helpful, thank you! I would like to add to it, because to me it was not obvious that in the case of Class methods the first argument must be declared in the functionSignatures.json with the proper type otherwise it will not work. For example:

classdef foo
    methods
        function out = bar(obj, arg)
            out = arg;
        end
    end
end

In order to have tab completion for the bar() method the corresponding functionSignatures.json file must contain the following.

{
    "foo.bar":
    {
        "inputs":
        [
            {"name":"obj","kind":"required","type":"foo"},
            {"name":"arg","kind":"required","type":"choices={'choice1','choice2'}"}
        ]
    }
}

Note the first entry in the input list is the object itself which can be used to generate options on the fly as shown in the article.

]]>
By: Sky Sartoriushttps://undocumentedmatlab.com/blog_old/user-defined-tab-completions-take-2#comment-410907 Thu, 27 Jul 2017 01:43:52 +0000 https://undocumentedmatlab.com/?p=6961#comment-410907 I have been encountering some interesting behavior in 2017b. Signatures that were working in 2017a now do not, though the error message does look like it is trying to be helpful: “Unable to load signatures for 'foo'. 'namevalue' and 'flag' arguments may not appear both inside and outside of groups.” So, it appears that this is a new “rule” for signatures (and violating the rule was giving me the desired behavior before).

TMW seems to get around this (see signatures for e.g. join) by putting a copy of each ‘outside’ arguments in every member of an existing MEG. Another workaround that seems to work is to put each ‘outside’ argument in its own (lonely) MEG, which has the benefit of avoiding duplicates.

]]>
By: Sky Sartoriushttps://undocumentedmatlab.com/blog_old/user-defined-tab-completions-take-2#comment-410354 Sun, 16 Jul 2017 22:00:11 +0000 https://undocumentedmatlab.com/?p=6961#comment-410354 This is a post I have been waiting for, Yair. Thank you. I was spending too much time digging through the Matlab functionSignatures.json files to find examples similar to what I was trying to do, so this summary is an excellent resource.

]]>
By: Greghttps://undocumentedmatlab.com/blog_old/user-defined-tab-completions-take-2#comment-410176 Thu, 13 Jul 2017 16:48:09 +0000 https://undocumentedmatlab.com/?p=6961#comment-410176 Thanks, Yair, this is awesome!

One added detail that I discovered when implementing this feature this morning is where MATLAB expects the .json file and the appropriate syntax for functions in package folders (i.e. +directories).

It looks like the appropriate thing is to place the .json file in the root of the package (the folder above the top-level +folder) and then reference the function names with their full package-specific function name. As an example, check out the functionSignatures.json file in %matlabroot/toolbox/shared/io/, which contains signatures for functions like matlab.io.TextVariableImportOptions.

By contrast, class methods seem to get referenced just by their method names, though class methods in @-folders are still described in the higher-level .json file. For example, in %matlabroot/toolbox/matlab/datatypes/functionSignatures.json, the method “histogram” of the categorical class is referenced simply as “histogram,” even though is a regular (non-static) method stored in the @categorical folder.

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/user-defined-tab-completions-take-2#comment-410172 Thu, 13 Jul 2017 16:33:56 +0000 https://undocumentedmatlab.com/?p=6961#comment-410172 @Heiko – nice catch about the comments! Apparently functionSignatures.json is not a strictly-compliant JSON file, and undergoes some pre-processing by the Matlab engine.

]]>
By: Heikohttps://undocumentedmatlab.com/blog_old/user-defined-tab-completions-take-2#comment-410166 Thu, 13 Jul 2017 14:50:35 +0000 https://undocumentedmatlab.com/?p=6961#comment-410166 Very nice! I’ve been waiting for a feature like this since we offered our toolbox. Especially the possibility to let MatLab determine the choices is gold. Even though it seems to depend on the type. I could not yet get it to accept other choices than a cell array. Looking forward to somebody taking the time to document a more or less complete list of options for each parameter…

About JSON comments: doing my first steps in ML R2016b I found that comments are possible. ML accidently opened the json file “R2016b\toolbox\matlab\graph2d\functionSignatures.json” which contained C-like inline comments starting with “//”. I also tried “/* */” comments successfully.

Thanks for the very useful help!!
Heiko

]]>