KeyBindings - Alter Matlab Editor key bindings

KeyBindings alters Matlab Editor's keyboard shortcuts.
927 Downloads
Aktualisiert 21. Aug 2009

Lizenz anzeigen

KeyBindings is inspired by EditorMacro (http://www.mathworks.com/matlabcentral/fileexchange/24615), although these two functions have slightly different focus. KeyBindings focuses on altering built-in shortcuts of the Editor, whereas EditorMacro provides also shortcuts for custom matlab functions and code templates.

Main motivation for me to write this function and for you to use it is better support for docked editor window and support for multi-key shortcuts.

KeyBindings uses different approach to modify shortcuts than EditorMacro. Main benefits of this are:
+ Custom shortcuts don't get reseted when editor is docked.
+ Supports multi-key shortcuts.
+ Filetype change does not reset custom shortcuts.
Unfortunately, this approach does not provide "perfect" solution. Main drawbacks are:
- Supports only built-in (java) actions, i.e. it is not possible to bind shortcut to you own matlab-function.
- All open documents have to be reloaded after shortcuts are modified (function does that automatically).
- Requires at least Matlab version R2007b.
However, the good thing is that the user can cherry pick best features of KeyBindings and EditorMacro. These two functions should work nicely together.

Syntax:
bindingsList = KeyBindings(keystroke, actionID)

KEYSTROKE is a string representation of the keyboard combination. Special modifiers (Alt, Ctrl or Control, Shift, Meta, AltGraph) are recognized and should be separated with a space, dash (-) or plus (+). Multi-key shortcuts can be created by separating keystrokes with comma (,). At least one of the modifiers should be specified, otherwise very weird things will happen...
For a full list of supported keystrokes, see: http://java.sun.com/javase/6/docs/api/java/awt/event/KeyEvent.html
If KEYSTROKE was already defined, then it will be updated (overridden).

In addition to java keystroke representation the keystroke can be one of the following code words:
Save - Store current key bindings to file under $prefdir.
Load - Read previously saved key bindings from file.

ACTIONID should be name of one of the Matlab's build-in actions. Available actions with their descriptions and current key bindings are listed when no input arguments are given.

After any modification to key bindings all open documents are reloaded to update shortcuts. Thus all documents have to be saved before modifying key bindings.

Note:
- Saving and reading key bindings to file works only in R2009a. Otherwise this should work with R2007b+.
- It is not possible to assing keystrokes to text templates or custom Matlab functions, only built-in actions are supported.

Examples:
% List current key bindings
KeyBindings
% Add new key binding
KeyBindings('Shift Ctrl M','show-mlint-report')
% Alter multiple key bindings at once
KeyBindings({'Ctrl B,B','Ctrl B,N','Ctrl B,P'},...
{'toggle-bookmark','next-bookmark','prev-bookmark'})
% Remove keybinding
KeyBindings('Ctrl-R','')

Warning:
This code heavily relies on undocumented and unsupported Matlab functionality. Use at your own risk!

Zitieren als

Perttu Ranta-aho (2024). KeyBindings - Alter Matlab Editor key bindings (https://www.mathworks.com/matlabcentral/fileexchange/25089-keybindings-alter-matlab-editor-key-bindings), MATLAB Central File Exchange. Abgerufen.

Kompatibilität der MATLAB-Version
Erstellt mit R2007b
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS Linux
Kategorien
Mehr zu Desktop finden Sie in Help Center und MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Veröffentlicht Versionshinweise
1.1.0.0

Emphasized relationship to EditorMacro.

1.0.0.0