[MATLAB's GUI] Erase everything within "Delimiter matching"

Hello,
After coming across this post,
I improved a lot my Matlab experience by better seeing the scope of a function, it's arguments, parenthesis, etc. It's great.
However, I was wondering if there is a way to setup a hotkey to remove the contents that are highlighthed by such delimiters. I couldn't find anything online.
In other words, if Matlab is properly highlighting these delimiters (i.e. parenthesis, brackets, IF/END, etc) there must be a way to capture these 2 "endpoints" and just erase everything within it. Maybe some Java hacks which I'm not super familiar with?
I'm using Matlab 2020b and have no intention of changing it anytime soon (because I have custom libraries that stopped being supported) if that changes anything.
Thanks for any input!
Luciano

 Accepted Answer

Hello,
this answer comes with a big warning, because I accidentally deleted the script, but I managed to recover it. So, 100% not recommended thing to do, as it's undocumented and also, you're risking to lose your code. If your editor loses focus, it will be saved and you can't undo.
Because I don't think this is something that should be posted because of users potentially losing the code, let's discuss your problem first.
Can you elaborate on this, why would you do this, what are you trying to fix - In other words, if Matlab is properly highlighting these delimiters (i.e. parenthesis, brackets, IF/END, etc) there must be a way to capture these 2 "endpoints" and just erase everything within it.

3 Comments

Hi Mario,
Thanks for the reply!
I see your point and haven't really considered not being able to undo this action. However, I'm not sure why this would be the case, though.
So more about the problem. I'm not trying to fix anything, this would be more of an improvement in my general use of Matlab. I'm a pretty heavy user and always try to automate my tasks to get a better workflow.
One such task that I started to noticed is to change parameters of a function. Particularly when I got a reasonable number of parameters (think like 3 to 10).
Normally, I would
  1. duplicate the line(s) -- I use this custom lib with hotkeys for that
  2. then proceed to move the cursor (ctrl+Arrow keys) until I highlight the part I want to change,
  3. then I need to eyeball where is the closing parenthesis and proceed to erase (ctrl+del) up to that point
This is just an example, but the eyeballing works thanks to the stack overflow link above but it quickly fades away.
In this example, it would be a lot quicker for me to, once the highlighting happens and I'm happy to where it is, I could just press a hotkey and erase that section of code (better yet, Ctrl+X so we don't loose the code) and continue writing the code immediately.
Other examples would be anywhere you want to rewrite the contents given by a "specific highlight". Imagine even if there is a hotkey to "jump to the next highlight". That way we can fly trough nested parenthesis until the right one is found and BAM- removed, code is changed, and life continues.
I know this is very niche and from what I'm seeing online, this looks like a feature used in VIM-like editors. I don't fully expect to find a solution but wanted to ask y'all anyway.
Hope it makes more sense now.
LB
Sorry for the delay.
Check this
doc matlab.desktop.editor
Get the opened file in editor
openedDoc = matlab.desktop.editor.getActive
So, you are looking for Selection and Text property. With these you can figure out how to delete parts of code.
Unfortunately, I didn't find any information, how to obtain the underlined text, i.e. when you click on "if" and the editor will underline the "end".
Thanks, for the help. I would need the underlined text for this project but I imagined that's hard to find.
Cheers,
LB

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products

Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!