File Exchange

image thumbnail

extend Matlab Editors callback

version 1.15 (59.4 KB) by

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

1 Download

Updated

View License

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

Comments and Ratings (10)

Andreas J.

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-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=-=~=');

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))
     edit(str)
  end

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.

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;
                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

Andreas J.

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(:);

Jan Simon

Jan Simon (view profile)

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.

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

Jan Simon

Jan Simon (view profile)

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.

Updates

1.15

link to new project

1.15

dead

1.15

V0.10 * several fixes
      * IntelliJ like Filestructer Browser
      * made it easier to "install" extended editor

1.12

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

1.11

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

1.10

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

1.9

updatet description

1.8

* Supports usermade replacements
* Bug fixed reported by Jonathan Sullivan

1.7

Breakpointbar is colorized to show that this feature is enabled.

1.6

R2013b

1.5

bugfix variable match

1.4

better regexp for variable finding

1.3

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

1.1

Changed: Tested Releases

MATLAB Release
MATLAB 8.6 (R2015b)
Acknowledgements

Inspired: GavriYashar/Matlab-Editor-Plugin

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

» Watch video