# File-name completion for custom functions

Mathematica 10 has introduces file name completion. It works only with certain built-in functions such as Import, SetDirectory, ReadList, etc.

Is it possible to add file name completion for user-defined functions?

For example,

readCSV[file_] := Import[file, "CSV"]


I would like file name completion to be triggered after typing readCSV["...

-
Link to W Community version – Szabolcs Aug 8 '14 at 18:37
In the case we have optional argument and there is a .m file with the options according to this answer on the Prompt a set of possible options, how would it be possible to achieve string autocompletion on my custom function ? – Athanassios Dec 14 '15 at 14:11
@Athanassios Sorry, I do not know the answer to that. I don't really like to customize Mathematica to such an extent by editing installation files. It seems that autocompletion can only be customized by editing installation files (though I might be wrong). – Szabolcs Dec 15 '15 at 11:30

There is an undocumented file in the installation directory named specialArgFunctions.tr:

NotebookOpen @ FileNameJoin @
{ \$InstallationDirectory, "SystemFiles", "FrontEnd", "SystemResources"
, "FunctionalFrequency", "specialArgFunctions.tr"
}


This file describes in detail how to attach completion actions to each parameter of listed functions. For example, it contains the entry:

"Import"->{2, "ImportFormats_Names.trie"},


and explains that 2 specifies absolute pathname completion for the first argument, and that the second argument should be completed from a compiled list found in the file ImportFormats_Names.trie in the same directory.

So, we can achieve the desired goal by adding the following entry for readCSV:

"readCSV"->{2},


The rules use symbol names unqualified by context. Thus, they apply equally well for symbols in any context. In fact, experimentation shows that the parameters of qualified symbols are not completed, even for the shipped rules (e.g. try completing SystemImport["c:\\).

As usual, the undocumented nature of this feature means that it could change at any time.

-
+1 Great! It would be nice if there was some kind of fileplaceholder that one could put in the usage message in the function template – Rojolalalalalalalalalalalalala Aug 10 '14 at 1:00
This is fine if you need file-completion, what about string auto-completion from a list of defined possible options for a custom function, see my question above ? – Athanassios Dec 14 '15 at 14:15
@Athanassios specialArgFunctions.tr shows an example for a function with a hard-coded list of acceptable values for the first argument: "MyPlanetInfo"->{{"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Uranus", "Neptune"}}` – WReach Dec 14 '15 at 15:29
@WReach I played a bit more with auto-completion feature and I noticed that when you define an enumerated list of options, in a .m file according to this (mathematica.stackexchange.com/questions/78935/…)How to Answer, then string auto-completion is not needed because the drop-down list is filtered automatically as you start typing the name of the option, e.g. com->getD.... and drop-down list displays only "getDatabase". – Athanassios Dec 15 '15 at 15:25
@Athanassios Yes, the method in (78935) enables autocompletion for option arguments, whereas the method here using specialArgFunctions.tr enables autocompletion for regular (non-option) arguments. – WReach Dec 15 '15 at 16:50