- Undocumented Matlab - https://undocumentedmatlab.com -

Spicing up the Matlab Editor

Posted By Yair Altman On March 30, 2018 | 2 Comments

I’d like to introduce guest blogger Andreas Justin [1], who will discuss some way-cool features in his Editor Plugin utility. Many of his feature implementations are not Editor-specific and can be reused in other Matlab-Desktop applications, for example dockable panels, and integration with Matlab’s main Preferences window.
Note: I will be traveling to the USA in June, and to Spain in August. If you would like me to visit your location for onsite consulting or training, then please let me know.
Happy Easter/Passover!

Overview

Editor-plugin's cool logo
Editor-plugin's cool logo
Compared to other IDE like IntellIJ, Eclipse and many more, Matlab’s editor seems somewhat outdated. Especially writing Object-Oriented code in Matlab is kind of a hassle. To make Matlab more user friendly, I’ve written a Java app that adds important features to the editor – Features such as navigating inside Class-code and in Inherited members; Searching through methods and instantly jumping to desired location; Reopening an editor that was closed by accident; Storing bookmarks between Matlab sessions; and Live Templates using commands directly written in the editor, replaced by pre-defined text.

The default Keyboard shortcuts listed below for the features can be customized. Most variables can be customized as well (I will point out which variables are not [yet] customizable).
Most GUIs have a search field. Within this search field you can move the list or the tree up and down using arrow keys, or hit <escape> to return to editor. These search fields allow you to enter regular expressions to limit results shown in list or tree. Also, most GUIs are dockable.
The Editor-Plugin utility is open-source. It is available on GitHub [2] and also mirrored on the Matlab File Exchange [3]. A detailed setup guide [4] is provided on the utility’s wiki section in GitHub [5].
If you discover any problem or have any suggestion for improvement, please visit the utility’s Issues section on GitHub [6], where all open/closed issues can be tracked and discussed.
A brief overview of some of the features is presented below. For a detailed explanation of these and other features (which are not listed below), please review the Features section [7] of the utility’s wiki (you guessed it: on GitHub…).

Editing

  • Delete / duplicate linesCTRL + SHIFT + Y or D allows you to delete or duplicate current line.
    Deleting/duplicating complete lines
  • Move lines up or downCTRL + ALT + UP or DOWN allows you to move selected lines up or down.
    Moving complete lines
  • Live (auto-replace) templates – Live Templates are editor commands you can design to insert predefined code. Here’s an example for the command %this% (delivered within the package). When you type a command into the editor the string will get replaced by the predefined text. This predefined text may include variables depending on what you want to achieve. %this% was designed to insert the fully qualified name of the current class you’re in (or function, or script).
    Auto-replace template
  • Clipboard StackCTRL + SHIFT + V opens the Clipboard Stack, where the last 10 copied/cut text are stored and can be directly inserted into the current editor position. The Clipboard Stack only stores text copied from editor.

  • Auto switch current folder and detail viewer – Switching editor tabs will update the Desktop’s current folder and detail viewer. This behavior can be directly changed in the detail viewer bar.
    Use the new icons in the Desktop’s Current Folder panel: Toggle detail viewer to toggle detail viewer and Toggle following the current editor file to toggle following the current editor file.
    Follow current editor file
  • File Structure – I personally use this one the most: CTRL + F12 will show a GUI that let you search methods and properties including inherited ones.
    File structure analysis
  • Navigation History – Every editor file that is opened is stored in the navigation history. Up to 50 editor file paths are stored. If you have a 5-Button Mouse, you can navigate through previous location (backward and forward).
  • Recently ClosedCTRL + SHIFT + T will show a GUI that allows you to reopen closed editors this or last session.
  • BookmarksCTRL + SHIFT + F2 will show a GUI that allows you to name, search and delete bookmarks. Matlab has this nice feature to delete bookmarks after closing the editor. This feature will store all bookmarks. If an editor or Matlab is closed and opened later. All Bookmarks will be restored.
    This feature has some issues though. The most obvious first: if the source file has been changed outside of Matlab, the bookmark does not get updated, and may point to the wrong line, or gets deleted. Also on some Systems the default shortcut does not work. But there are workarounds.

Other useful features

  • Dockable Windows – As mentioned before, most GUIs are dockable.
    Dockable Windows
  • Preferences – Preferences panel integrated in Matlab’s main Preferences window.
    Preferences panel integrated in Matlab's main Preferences window
  • Execute current lineSHIFT + F9 allows you to execute the current line. This is equivalent to selecting the entire line, then clicking F9, and is similar in concept to the editor’s built-in ability to execute the current cell-block.
    Execute current line
  • VarDiff – Select two variables in the workspace and compare them using Matlab’s internal comparison feature (adding a custom hook to the Workspace context-menu was discussed by Yair [8] back in 2010).
    Variables comparison integrated in the Workspace browser
  • KeyPressListener – Allows you to create custom keyboard shortcuts for your own functions. A similar functionality was discussed by Yair [9] back in 2009.

As noted above, a detailed explanation of these and other features is provided in the Features section [7] of the utility’s wiki. If you discover any problem or have any suggestion for improvement, please visit the utility’s Issues section on GitHub [6], where issues can be tracked and discussed.

Categories: Desktop, Guest bloggers, High risk of breaking in future versions, Java, Undocumented feature


2 Comments (Open | Close)

2 Comments To "Spicing up the Matlab Editor"

#1 Comment By Josh On January 27, 2021 @ 04:42

Dear Yair,
Small typo; you wrote
>>Move lines up or down – CTRL + ALT + UP or DOWN allows you to move selected lines up or down
but it’s actually ALT+SHIFT then UP/DOWN

Cheers! Great post!!
josh

#2 Comment By Niko On January 12, 2022 @ 13:26

Hi,
Has anyone acomplished to install Andreas’ tool for Matlab version ‘9.11.0.1809720 (R2021b) Update 1’ or higher?
I think the fact that Matlab now uses the stupid LiveEditor causes problems 🙁
Cheers,
Niko


Article printed from Undocumented Matlab: https://undocumentedmatlab.com

URL to article: https://undocumentedmatlab.com/articles/spicing-up-the-matlab-editor

URLs in this post:

[1] Andreas Justin: https://github.com/GavriYashar

[2] on GitHub: https://github.com/GavriYashar/Matlab-Editor-Plugin

[3] on the Matlab File Exchange: https://www.mathworks.com/matlabcentral/fileexchange/58497-gavriyashar-matlab-editor-plugin

[4] detailed setup guide: https://github.com/GavriYashar/Matlab-Editor-Plugin/wiki/Setup

[5] wiki section in GitHub: https://github.com/GavriYashar/Matlab-Editor-Plugin/wiki

[6] Issues section on GitHub: https://github.com/GavriYashar/Matlab-Editor-Plugin/issues

[7] Features section: https://github.com/GavriYashar/Matlab-Editor-Plugin/wiki/Features

[8] discussed by Yair: http://undocumentedmatlab.com/blog/customizing-workspace-context-menu

[9] discussed by Yair: http://undocumentedmatlab.com/blog/editormacro-assign-a-keyboard-macro-in-the-matlab-editor

[10] EditorMacro – assign a keyboard macro in the Matlab editor : https://undocumentedmatlab.com/articles/editormacro-assign-a-keyboard-macro-in-the-matlab-editor

[11] Accessing the Matlab Editor : https://undocumentedmatlab.com/articles/accessing-the-matlab-editor

[12] Non-textual editor actions : https://undocumentedmatlab.com/articles/non-textual-editor-actions

[13] Recovering previous editor state : https://undocumentedmatlab.com/articles/recovering-previous-editor-state

[14] Spicing up Matlab uicontrol tooltips : https://undocumentedmatlab.com/articles/spicing-up-matlab-uicontrol-tooltips

[15] Variables Editor scrolling : https://undocumentedmatlab.com/articles/variables-editor-scrolling

Copyright © Yair Altman - Undocumented Matlab. All rights reserved.