View README.txt
#==============================
# Startup
#==============================
# the startup file creates a edit.m file in specified path (needs to be set) directory.
# you can change this behavior in sturtup.m and edit editPath.
# it will overload the built in edit function.
# and add paths to the appdata of "0"
#==============================
THIS THREAD IS DEAD. THIS FILE WILL NO LONGER BE UPDATED:
THIS CODE IS REPLACED BY: http://de.mathworks.com/matlabcentral/fileexchange/58497-gavriyashar-matlab-editor-plugin
Andreas J. (2021). extend Matlab Editors callback (https://www.mathworks.com/matlabcentral/fileexchange/41099-extend-matlab-editors-callback), MATLAB Central File Exchange. Retrieved .
Inspired: GavriYashar/Matlab-Editor-Plugin
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
moved to https://github.com/GavriYashar/Matlab-Editor-Plugin
If you add following code in daEditor.DaEditorCallbacks, the system will search for the expression in your own commands and will print the result out in the command window. e.g.:
%calc<CTRL+SPACE>
%commandwindow output:
-=~=-=~=-=~=-=~=-=~=-
TabCompletion on MESRC:
Calc_sth
sth2calc
calcMore
theCalculationNeverEnds
-=~=-=~=-=~=-=~=-=~=-
%%%%%%%%% CODE %%%%%%%%%%
%% CTRL + SPACE
if ctrlOnlyFlag && evnt.getKeyCode == evnt.VK_SPACE
aE = matlab.desktop.editor.getActive;
daEditor.DaEditorCallbacks.tabCompletion(aE);
end
pos = aE.Selection;
pos(2,1:4) = pos;
cursorPos = matlab.desktop.editor.positionInLineToIndex(aE, pos(1,1),pos(1,2));
txt = aE.Text(matlab.desktop.editor.positionInLineToIndex(aE,pos(1,1),1):cursorPos-1);
idx = regexp(txt,'\%');
if isempty(idx); return; end
idx = idx(end); % nearest to cursor
expr = txt(idx+1:end);
mesrPath = fullfile(SDS_ToolPath_DA,'MatlabM\Tools\Matlab_Editor_StringReplacements\Replacements');
oCD = cd(mesrPath);
dirCont = dir('MESRC_*.m');
mesrList = {dirCont.name};
mesrList = mesrList(:);
mesrList = regexprep(mesrList,'MESRC_(.*?)\.m','$1');
cd(oCD);
mesrListTab = mesrList(util.regexCell(mesrList,expr));
txts = strjoin(mesrListTab,'\n\t');
fprintf('\n-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=');
fprintf('\nTabCompletion on MESRC:')
fprintf('\n\t%s',txts)
fprintf('\n-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=');
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))
edit(str)
end
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.
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;
else
offS = -2;
offE = 0;
end
posS = daEdit.idx2pos(daEdit.selection(1),0)+offS;
posE = daEdit.idx2pos(daEdit.selection(3),linSize)+offE;
daEdit.repText('',posS,posE);
end
Thanks for your feedback Jonathan Sullivan. I'll look into it as soon as i have time for it!
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));
end
this.set('background',color(1:3));
end
function [names, access] = findAllComponents(jMainPane,names,access,access_base)
cmps = jMainPane.getComponents;
if nargin == 1;
names = {};
access = {};
access_base = [];
end
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});
end
names = names(:);
access = access(:);
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.
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
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.