Description 
The Matlab editor provides an integrated code completion through the tab key. However the scope of this completion is the entire Matlab path, so the number of matches is usually large when matching a few characters. On the other hand the native Matlab code completion is sometimes too restrictive since it only matches sequential characters. I have found the more flexible matching of TextMate very convenient to use, where e.g. the string 'fcn' can be completed to 'function'. The purpose of this macro is to provide such a more flexible matching algorithm, but with scope restricted to the current document.
To use this macro you must install EditorMacro by Yair Altman, put this file (Matlab_Code_Completion_Macro.m) on your Matlab path and add the following lines to your startup.m file:
macros = EditorMacro('ctrlspace',@Matlab_Code_Completion_Macro, 'run');
macros = EditorMacro('ctrlaltspace',@Matlab_Code_Completion_Macro, 'run');
macros = EditorMacro('shiftctrlspace',@Matlab_Code_Completion_Macro, 'run');
To use the macro, type in the Matlab editor a string to be completed, e.g.,
fo
To find possible completions, press ctrlspace.
Then you get the suggested code completion
fo<<{for}
Pressing ctrlspace once again you get the next best completion
fo<<{function}
and pressing ctrlspace again
fo<<{parfor}
Pressing ctrlshiftspace we step back to the previous suggestion
fo<<{function}
and this completion is chosen by pressing ctrlaltspace, so we get
function
Now with the caret positioned at the end of the function keyword, we press ctrlaltspace again and get
function [
Now we can type a variable list
function [y,z
and type ctrlaltspace again to get
function [y,z] =
Type the function name
function [z,w] = f
and press ctrlaltspace again
function [z,w] = f(
Type a variable list
function [z,w] = f(x,y
and press ctrlaltspace again
function [z,w] = f(x,y)
Next, you can type the function body, for example
function [z,w] = f(x,y)
z=x+y; w=zy;
(to get correct indentation you may need to apply the smart indent, e.g., by the shortcut ctrli). Finally, you can use ctrlaltspace again to get the end statement
function [z,w] = f(x,y)
z=x+y; w=zy;
end
Similar completions work for if, elseif, for and while.
In conclusion, I have found this macro a valuable complement to the native Matlab code completion, and it has saved me a lot of typing and searching for variable and function names.
I hope you find it useful. Enjoy!
