autocomplete filenames paths function input
10 views (last 30 days)
Show older comments
J. Alex Lee
on 12 Jun 2025
Commented: J. Alex Lee
on 12 Jun 2025
I am trying to get custom function input autocompletion for a filename and can't get it to work how I want:
- I have a function like "dir", so I want it to have autocompletion for the target folder as "dir" does, but I also want to be able to pass optional arguments to extend its functionality
- I want to use the arguments block as much as possible, and functionSignatures.json if needed
The function itself would be something like
function mydir(target,opts)
arguments
target
opts.ShowHidden
opts.Blahblah
end
% do stuff
end
Some things that don't work:
- I tried to make a functionSignature for the "mydir" function itself, but only for the "target" variable. Then I do get the tab-autocomplete behavior I want, and wildcards work. However, I don't get tab-autocomplete on my optional arguments. I could not figure out how to do the structure-based name/value pair function signatures, as that does not seem to be covered in the documentation.
- Within the arguments block, I noticed that using the "mustBeFolder" validator makes it possible to tab-autocomplete the input target. However, I cannot then include wildcards because once wildcards are in, then the folder doesn't exist anymore.
- So I tried to create a custom "mustBeValidPathName" validator and created a functionSignatures.json entry for it, but then the tab-autocomplete doesn't work anymore. Calling "mustBeValidPathName" by itself, however, does give me the tab-autocomplete behavior I want.
How can I get both the file name autocompletion, that accepts wildcards, and be able to also auto-complete optional arguments using the arguments block framework?
There are 2 other Matlab Answers pages on the topic but first one doesn't seem to answer the question, and second one is reference by the first but is outdated/incomplete
0 Comments
Accepted Answer
Benjamin Kraus
on 12 Jun 2025
Edited: Benjamin Kraus
on 12 Jun 2025
I don't think it is possible to do what you are requesting using an arguments block alone without also using functionSignatures.json. I'm also pretty sure that any use of functionSignatures.json will replace auto-complete from the arguments block. I don't think the two will "merge".
I don't think creating functionSignatures.json for your custom validator will do what you were hoping, but that is an interesting enhancement. I will forward that feedback to the relevant team.
It sounds like you were able to get functionSignatures.json working for your target input, so all that is lacking is adding entries for your two name/value pairs (ShowHidden and Blahblah).
I believe what you are looking for is the "namevalue" kind of input, which is mentiond on the "Customize Code Suggestions and Completions" documentation page.
The JSON would look something like this (this is largely copied from the documation page above):
{
"_schemaVersion": "1.0.0",
"mydir":
{
"inputs":
[
{"name":"target", "kind":"ordered", "type":["char"]},
{"name":"ShowHidden", "kind":"namevalue", "type":["logical","scalar"]},
{"name":"Blahblah", "kind":"namevalue", "type":["char", "choices={'Default','Choice1','Choice2'}"]}
]
}
}
More Answers (0)
See Also
Categories
Find more on Install Products in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!