Be the first to rate this file! 12 Downloads (last 30 days) File Size: 45.9 KB File ID: #41099
image thumbnail

extend Matlab Editors callback


Andreas J.


03 Apr 2013 (Updated )

Extends the editor features. Closing brackets, Operator. Templates, Keyboard Shortcuts

| Watch this File

File Information

% Automatically Closing Brackets
% Note on large scripts 2000+ lines it's very slow.
% disable: delete cases in Matlab_extendEditorFunctionality:getPutIn which has an opening "(", "[", or "{"
% C++ type operator support
% notice that there should only be spaces before the variable otherise it replaces the whole line
% disable: delete case in Matlab_extendEditorFunctionality:getPutIn which has the "="
type: a +=
get: a = a +
type: a(ii).heif *=
get: a(ii).heif = a(ii).heif *

type: a(ii).heif -=
get: a(ii).heif = a(ii).heif -

% Startup
the startup file creates a edit.m file in your D:\ directory you can change this behavior in sturtup.m and edit myPath, it will overload the built in edit function.

% Script Template GUI
Using ALT+INSERT in the editor window will open a GUI with all the MESRC files you've created (+ some i've provided). You can search the commands, if they multiply, for easier access.

% Script Templates
change all paths in following files:
MESR_GUI:line 60
Matlab_extendEditorFunctionality_StringReplacements:line 8, 68

I added an example file for this. The String after the underscore (MEStringRep_) in is the name of your replacement.


will automaticly insert: (in my example)
  %% >|•| example
  % 2014-07-02, Andreas Justin, aj @ Unemployed
  [...] % out of characters

% Script Templates Variables
in the example file i created you should notice the line "% ${DATE}, ${AUTHORLONG}, ${AUTHORSHORT} @ ${COMPANY}"
${\w+} are Variables. The replacement tool will search for these and
inserts a string before the whole text gets pasted in your script.
You can add your own variables in

% Keyboard shortcuts
% since the shortcuts shouldn't interfere with the tabcompletion it is set that it'll fire after you released a key.
you can define new keyboard shortcuts (won't interfere with matlabs tab complete, but you shouldn't use shortcuts
which are already in use in matlab)
you can remove them in matlab tough to create your own.

to add your custom shortcut go to

For a stable usage release the letter key before you release any control keys like shift, ctrl or alt.
e.g. CTRL + SHIFT + L
release L and than the others.

% Advanced Find and Replace

[*] you can use regexp commands to find things in your current file
[*] limit search to current selection or current section

note replace all with regexprep style replacements not stable yet simple functions are stable. Better use single replace to be sure.

% Mouse multiline edit
upcoming feature, don't use it yet. maybe i'll remove it if i can't create a well running implementation

R2012b - no Keycombination tested
R2013a - no Keycombination tested
R2013b - no Keycombination tested

% Update Log
V0.01 first release
V0.02 removed Commandwindow support, added operator support
V0.03 better regular expression to get variable behind operator
V0.04 bufgix didn't match all variables
V0.05 R2013b Support
V0.06 Breakpointbar is colorized to show that this feature is enabled.
V0.07 * Supports usermade replacements
      * Bug fixed reported by Jonathan Sullivan - Flashing bug, using matlabs internal replacement tool instead of replacing whole text
V0.08 * Script Templates Variables
      * Keyboard shortcuts
      * some replacements caused still a flashing bug. should now be completely removed
V0.09 * added Advanced replacement tool
      * added GUI for templates
      * fixed bug "multiple editors open"

Also Includes A Search tool which searches a CellStringArray (can be doubles) with regexp and returns a logical array in the size of the CellStringArray where expression is found.

Required Products MATLAB
MATLAB release MATLAB 8.3 (R2014a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
06 Jun 2014 Andreas J.

Andreas J.

With the following code you can use CTRL + E instead of CTRL + D to opened selected functions, it automaticly extends the now opened editor also.

ctrlOnlyFlag = ctrlFlag && ~shiftFlag && ~altFlag;
%% CTRL + E
if ctrlOnlyFlag && evnt.getKeyCode == evnt.VK_E
% Überladenes CTRL + D von Matlab
str = daEdit.mEditor.SelectedText;
fprintf('Strg+D: "%s" in "%s"\n',str, char(daEdit.mJavaEditor.getShortName))

Comment only
06 Jun 2014 Andreas J.

Andreas J.

BugReport: If you have multiple editors opened (like 30+, depends on your computer) the extend editor function will take a while to finish. e.g. if you use the edit function it can take a while until the "Busy" label is removed from matlabs bottom bar..

This bug will be fixed in a future release.

Comment only
21 May 2014 Andreas J.

Andreas J.

I currently use a custom keyboard shortcut to delete the line i'm currently on quite a lot. If you want to use it also add following code in daEditor.DaEditorCallbacks:runShortcutKey

ctrlShiftFlag = ctrlFlag && shiftFlag && ~altFlag;
if ctrlShiftFlag && evnt.getKeyCode == evnt.VK_Y
% remove Current Line - multiple lines at once possible
linSize = numel(daEdit.getTextByLine(daEdit.selection(3)));
if linSize == 0
offS = -2;
offE = -1;
offS = -2;
offE = 0;
posS = daEdit.idx2pos(daEdit.selection(1),0)+offS;
posE = daEdit.idx2pos(daEdit.selection(3),linSize)+offE;


Comment only
30 Sep 2013 Andreas J.

Andreas J.

Thanks for your feedback Jonathan Sullivan. I'll look into it as soon as i have time for it!

Comment only
27 Sep 2013 Jonathan Sullivan

Jonathan Sullivan

This is great. I like the idea. I have a few comments.

First off, there is a somewhat distracting flashing of the editor window when the "+=" type of substitution is occurring. Not a big deal, but it would be nice to fix it.

Secondly, the colorization of the breakpoint bar wasn't working. It couldn't find it by the .getComponent calls you hard coded in. I do have a solution that will dynamically find it. It is below. Notice the change in the number of arguments to the function colorizeBreakPointBar.

function colorizeBreakPointBar(jMainPane,color)
[names, access] = findAllComponents(jMainPane);
a = access(strcmpi(names,'BreakpointView$2'));
for jj = 1:length(a)
inds = a{jj};
this = jMainPane;
for ii = 1:length(inds)
this = this.getComponent(inds(ii));

function [names, access] = findAllComponents(jMainPane,names,access,access_base)

cmps = jMainPane.getComponents;

if nargin == 1;
names = {};
access = {};
access_base = [];

for ii = 1:length(cmps)
c = regexp(char(cmps(ii).toString),'\.([^\[\.]+)\[','tokens');
names{end+1} = c{1}{1};
access{end+1} = [access_base ii-1];

[names, access] = findAllComponents(jMainPane.getComponent(ii-1),names,access,access{end});


names = names(:);
access = access(:);

Comment only
15 Apr 2013 Jan Simon

Jan Simon

An overloaded function is used, when its folder appears before the folder of the original file in Matlab's PATH. Therefore moving a folder temporarily to the first position on the PATH is sufficient to shadow a function of Matlab's toolboxes. See "addpath" without the recommended '-end' flag.

For this reason the '-end' flag is such essential: When you create a damaged function, which shadows an important function like PATH, EDIT, STRCMP etc, it could happen, that you cannot start Matlab to fix this problem.

Comment only
08 Apr 2013 Andreas J.

Andreas J.

AFAIK to overlod a function, the function new function need a higher folder level. And the edit function is in matlabroot. so if you don't have write acces to the matlab root folder you need to start this tool manually.

I would be very pleased if anyone can proof me wrong. It would be veryhelpfull to know another way to overload functions

like @overload \path\morepath\somemore\andmore\myFunc.m

Comment only
08 Apr 2013 Jan Simon

Jan Simon

This is a very good idea in general. I had some automatically closing parenthesis in my Alpha editor on the Mac 20 years ago already.

In the startup.m file, you expect the user to have write privileges in the matlabroot folder. This is not a smart idea.

Comment only
05 Apr 2013

Changed: Tested Releases

05 Sep 2013

operatoren support
+=, -=, *=, /=

06 Sep 2013

better regexp for variable finding

09 Sep 2013

bugfix variable match

23 Sep 2013


25 Sep 2013

Breakpointbar is colorized to show that this feature is enabled.

12 May 2014

* Supports usermade replacements
* Bug fixed reported by Jonathan Sullivan

12 May 2014

updatet description

19 May 2014

* Script Templates Variables
      * Keyboard shortcuts
      * some replacements caused still a flashing bug. should now be completely removed

19 May 2014

forgot to update summary
* Extends the editor features. Closing brackets, Operator. Templates, Keyboard Shortcuts

02 Jul 2014

* added Advanced replacement tool
      * added GUI for templates
      * fixed bug "multiple editors open"

Contact us