Code covered by the BSD License  

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

5.0 | 7 ratings Rate this file 17 Downloads (last 30 days) File Size: 6.01 KB File ID: #26830 Version: 1.2
image thumbnail



Yair Altman (view profile)


03 Mar 2010 (Updated )

Sets Command-Window tab completion for specified functions & arguments: types and custom strings

| Watch this File

File Information

Argument tab-completion occur when the user presses the <Tab> key following the function name in the Command Window. The list of available/possible arguments is then presented in a popup window.
TABCOMPLETE modifies the [matlabroot '/toolbox/local/TC.xml'] file to set/unset the tab-completion definition of the specified function. Note: changes take effect only after a Matlab restart.
TABCOMPLETE(funcName, argType1, argType2, ...) sets the tab-completion list for function arguments 1, 2, etc. argType can be one of these pre-defined keywords:
       - 'var' - list of current workspace variables
       - 'fun' - list of accessible functions
       - 'subfun' - list of accessible sub-functions
       - 'dir' - list of accessible folders (directories)
       - 'file' - list of accessible files (of any type)
       - 'mfile' - list of accessible *.m files (Matlab functions)
       - 'matfile' - list of accessible *.mat files (Matlab data)
       - 'figfile' - list of accessible *.fig files (figures)
       - 'mdlfile' - list of accessible *.mdl files (Simulink models)
       - 'mcospkg' - list of accessible MCOS class packages (R2010a+)
       - 'mcosclass' - list of accessible MCOS classes (R2010a+)
       - 'messageid' - list of accessible error/warning message IDs (R2011b+)
       - (if none of the above is specified, 'subfun' is set automatically)
     And in addition to the pre-defined kewords:
       - additional string value(s) that will be added to the pop-up list
Multiple types for the same argument can be specified:
       - as a cell array - example: {'var','file','on','off'}
       - as a space-separated string - example: 'var file on off'
The last argType specified will apply for all subsequent arguments. The last argType may be '' (empty string) to indicate the end of tab-completed args. The last argType does *NOT* accept additional string values like the rest of the arguments.
TABCOMPLETE(funcName,'') removes all arg tab-completions for funcName (this is an immediate corollary of the previous paragraph).
definitions=TABCOMPLETE (without any arguments) returns a structure array listing all the current tab-completion definitions.
definitions=TABCOMPLETE(funcName) returns a structure listing the tab-completion definition for the specified function (if existing).
definitions=TABCOMPLETE(...) returns a structure array listing all tab-completion definitions BEFORE their modification by TABCOMPLETE.
     tabcomplete('addpath','dir') % sets multiple folder completions
     tabcomplete('edit','file fun') % sets multiple file/func completions
     tabcomplete('cd','dir','') % sets a single-arg folder completion
        => *.mat followed by multiple variable-names or '-struct'/'-regexp'
     tabcomplete('myFunc','') % removes myFunc's arg tab-completions
     defs = tabcomplete('cd') % returns 'cd' function's tab-completions
     defs = tabcomplete % returns all currently-defined tab-completions

     This code heavily relies on undocumented and unsupported Matlab functionality. It works on Matlab 7+, but use at your own risk!

Technical explanation:
     A technical explanation of the code in this utility can be found on
Bugs and suggestions:
     Please send to Yair Altman (altmany at gmail dot com)

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (12)
11 Feb 2014 Will

Will (view profile)

This works great. It would be nice if it would work on methods of classes as well, but I am guessing that is not possible with the way tab completion is currently implemented in MATLAB.

Comment only
11 Feb 2014 Will

Will (view profile)

31 Jan 2014 Todd Karin  
10 Oct 2012 Vincent

Hi Yair,
this is really a great function. Currently I am searching for a solution to avoid a restart and reload TC.xml directly. Have you any hints or ideas to start from?

27 Feb 2012 Christopher  
07 Feb 2012 German Gomez-Herrero

Thanks! Just another tiny issue that I came accross when using the new version. It seems that, under Linux, copyfile() may return status=1 even if the .bak file could not be created due to the lack of write permission in the relevant folder. At least in my Debian squeeze system I get status=1 but msg='Operation not permitted' and the .bak file is not created. Is this a MATLAB bug? So there is the possibility that the owner of TC.xml can now rewrite TC.xml (by changing permissions automatically) but fails to create a backup copy, as the toolbox/local directory is read-only by default. For the sake of safety I would test that the msg returned by copyfile is empty as well as checking that status is not zero.

Comment only
06 Feb 2012 Yair Altman

Yair Altman (view profile)

@German - I've uploaded a new version of this utility - please use the latest version. See the update notes below for more info.

Comment only
03 Feb 2012 German Gomez-Herrero

Really helpful stuff. And the technical explanations at your blog are incredibly insightful. Thanks a lot for sharing this. I would suggest just two very minor modifications:

- Adding the MCOSPCG and MCOSCLASS options
- Under unix systems, automatically changing the permissions of the xml file before editing it. Usually you will be the owner of that file but by default its permissions are set to read-only. You could change the permissions back to read-only after the editing.

24 Jan 2012 Andreas

Thanks a lot, this is really helpful :)

25 Sep 2010 Yair Altman

Yair Altman (view profile)

Yogesh - the tex warning is harmless. To remove it, simply modify 'tex' to 'non' in line #110.

The error itself is due to the fact that you cannot save the TC.bak file in your system for some reason (perhaps it is read-only?)

Comment only
24 Sep 2010 Y Mehta

I get the following error in 2010a

Warning: Unable to interpret TeX string "Save C:\Program Files\MATLAB\R2010a\toolbox\local\TC.bak?"
> In questdlg at 277
In tabcomplete at 112
??? Error using ==> tabcomplete at 117
Failed to create C:\Program Files\MATLAB\R2010a\toolbox\local\TC.bak:
Access is denied.

117 error('YMA:TabComplete:CreateBakup','Failed to create %s:\n%s',bakFilename,msg);

Comment only
03 Mar 2010 David

David (view profile)

Thanks for posting this great utility! Seeing your question dialog and looking through the code, I saw your use of the function "setpref." I didn't know about this very useful function, so thanks for that too!

28 Sep 2010 1.1

Minor fix to msgbox in case of backup problem (per Yogesh's comment)

04 Feb 2012 1.2

Added MCOSPKG,MCOSCLASS (R2010a+), MESSAGEID (R2011b+) argTypes; warn when using extra vars in R2010a-R2011b; attempt to make TC.xml writeable before updating; fixed possible Matlab hang after answering the backup dialog window

Contact us