MATLAB Community

MATLAB, community & more

Tab Completion in the MATLAB R2010a Editor

In continuing our coverage of the new MATLAB R2010a desktop features, this week I’m highlighting the updates to Tab Completion. For those new to this feature, anytime I refer to “Tab” I mean the TAB key on a keyboard, and not the open file tabs in the Editor. Using Tab Completion in the Command Window or Editor is easy: type the first few letters of a word and press the Tab key to bring up a list of all stuff MATLAB recognizes that starts with the typed letters. If only one match is found, the rest of the word is automatically completed, if more than 1 match is found, a window is shown to make a selection. If no matches are found, the window will display a message to that effect.

Go ahead and try it out; you may have to turn it on in the preferences: File -> Preferences -> Keyboard

Tab Completion Preference

Before R2010a, Tab Completion listed the same set of words in both the Editor and Command Window: functions on the path, variables in the workspace, fields/methods/properties of objects in the workspace, and inputs for a small subset of functions such as file names and figure properties. Because the Editor’s completion mechanism was based off the workspace, a common workflow was: run a file or part of a file with “eval selection”, cell mode, or using a breakpoint to put local variables into the workspace in order to get Tab completion of those variables. Another common workflow to insert variable names was to use copy & paste within the Editor, or type out the variable names, both of which can introduce bugs.

Well…. not anymore! In this release, the Editor has added smarts to recognize variable names and subfunctions within the scope of where you’re editing. The editor analyzes the syntax and structure of your file to figure out what might be a variable or subfunction and where it can be used.

Tab Completion example

There are a few limitations to this feature. Because the completion list comes from analyzing the file’s syntax, the code must by reasonably syntactically correct. It doesn’t have to be perfect, but there are forms of bad files that can’t be analyzed. Another limitation comes from MATLAB’s dynamic data-types. Because tab completion uses static analysis, it doesn’t try to guess at the data type for a variable, so things after a “.” such as properties and fields won’t be completed unless that variable is also defined in the workspace. For similar reasons, variables created through eval, assignin, load, etc. won’t be added to the list of completions.

I know longtime reader Daniel was fired up about this new feature. What do you think? Will you now be more likely to use Tab Completion in your workflow?

|

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.