# 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 at 18:37

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 –  Rojo Aug 10 at 1:00