By default, Matlab binds F1 to the doc command. I'd like to change that binding to doc2, which is a function of mine. Unfortunately, the documentation is not very helpul with that matter.
Is there a simple way to achieve this ?
Thank you.
No, you can't do that, and MATLAB does not at all bind F1 to the doc command.
By default, F1 is bound to a few different things, depending on what desktop component you're using at the moment, and whether you have anything selected. In the MATLAB desktop, if nothing is selected, it will open up the Help Browser; but if something is selected, it will do Help on Selection instead, and if you're in the Genome Browser from Bioinformatics Toolbox, it will do something different again, specific to that tool.
You can modify those bindings in the MATLAB Preferences (Keyboard->Shortcuts); but you can only remap the bindings for existing actions, not create your own.
When the default action of opening up the Help Browser is carried out by a keyboard shortcut, it is not done by calling the doc command (that would be a bad idea, as the user may have modified or replaced the doc command to do something unrelated to help).
Related
In Simulink, certain error messages provide clickable links to the origin of the error.
See, for example, the following error:
If I click one of the three links in the message, say, Parent setting, Simulink opens the code generation settings dialog and indicates the specific setting(s) using a blue border:
As a user, can I achieve the same highlighting programmatically (using a .m-script)? If so, how?
Yes, this is possible, but it requires the use of Simulink internal support functions. Their API is undocumented and may therefore be unstable. Use at your own risk.
The highlighting in the question is achieved as follows:
slprivate('modelref_highlight_configset_setting', 'rtwdemo_capi', 'RTWCAPISignals')
Here,
slprivate is a .m-function that ships with Simulink. There is no help entry for the function. Its only mention in the help is on the 'Set Simulink Preferences' help page. Its implementation is simple: it is a wrapper around feval. The implementation can be opened by executing the command >> edit slprivate from the Matlab Command window.
The function's documentation is as follows:
slprivate is a gateway for internal support functions used by Simulink.
VARARGOUT = slprivate('FUNCTION_NAME', VARARGIN)
In the usage above, the first parameter 'modelref_highlight_configset_setting', is the Simulink internal support function. In this case, it is the function that does the highlighting.
The second parameter 'rtwdemo_capi', is the name of the Simulink model whose Configuration Parameters window should be opened for highlighting.
The third parameter, 'RTWCAPISignals', is the name of the configuration option to highlight. In this case, that single option highlights two UI elements.
Names of configuration options can be found as follows:
Open the model's Configuration Parameters window (e.g. in Simulink: menu Simulation -> Model Configuration Parameters, or Ctrl + E)
Right-click on (or, rather, next to) the option
In the context menu that appears, click What's This?
In the help window that appears, scroll down to Command-Line Information. The name of the option is given in the Parameter field.
Edit:
The way I figured this out may be useful for other internal functions, so I'll leave that here as well. If the build is started from the Command Window (>> rtwbuild('rtwdemo_capi')) instead of from the GUI, warning and error messages are printed to the command window as well, including the clickable links. If one then hovers over such a link with the mouse pointer, the corresponding command is shown in the Matlab status bar (at the bottom of the main Matlab window).
I want to capture when the user holds down the control key and presses the enter key on a figure window. Note: This is the default keys for "Evaluate Current Section" in the editor.
See example code below:
function test
f = figure;
f.KeyPressFcn = #myKeyPressFcn;
end
function myKeyPressFcn ( hFig, event )
cm = hFig.CurrentModifier();
if ~isempty ( cm )
fprintf ( 'CurrentKey: %s:%s\n', cm{1}, hFig.CurrentKey );
else
fprintf ( 'CurrentKey: %s\n', hFig.CurrentKey );
end
end
To reproduce save the above in an active file in the editor and run the function - the editor needs to be open (this is important!!).
With the figure active press any key -> the selected key is written to the terminal window. However if you hold down Control and press the enter (return) key then this is not captured but instead Matlab attempts to "Evaluate Current Section" (or cell as it used to be called) in the editor (no matter that the figure has the focus). This of course throws as error...
I have contacted Matlab support and this is "expected behaviour!". I can (just about) see why it might be a good idea for demos - but for professional applications that run in Matlab I personally think this "feature" is a bug!!
Notes
When the editor is closed the control+enter is captured in the figure
In deployed applications the control+enter is captured.
If I manually change the Evaluate Current Section shortcut then control+enter is captured.
I have tried a number of things to resolve this but none have worked, for example hiding the editor or setting editor enable state to false (neither of these are acceptable solutions - I was trying to see what I could get to work on a small test case...):
function test
desktop = com.mathworks.mde.desk.MLDesktop.getInstance;
jEditor = desktop.getGroupContainer('Editor').getTopLevelAncestor;
jEditor.setVisible(false);
jEditor.setEnable(false);
f = figure
f.KeyPressFcn = #myKeyPressFcn;
uiwait(f);
jEditor.setVisible(true);
jEditor.setEnable(true);
end
The only way I can get it to work is to close all of the editor files on launching the GUI and then opening them again when the GUI closes (this is not an acceptable solution... - for fairly obvious reasons!!)
I did think about trying to temporarily modify the shortcut key (Preferences-Keyboard-Shortcuts) of the "Evaluate Current Section" -> but haven't worked out a way to do it from the commandline, and then set it back again when finished. If this is fast you could do it when the user presses and releases the control key.
So what am I asking:
If possible I need a solution that will work for anyone anywhere - as if I can get this to work it will be included in a new add-on feature in my Matlab GUI Toolbox. - which is used by people all over the world.
Do you know how to modify the keyboard shortcuts from the commandline - if so how!
Any other suggestions?
My other idea is to change my shortcut to a different key combination - but wheres the fun in that! :) (I will still have the issue if some user somewhere has altered the execute the current cell to my new combination...)
P.S. Thanks for reading this far down!! :)
Why don't you go to the home> Preferences > keyboard > Shortcutand change it there?
you only need to hit Ctrl + Enter in the black box at top of the page for searching the related command, which is here Evaluate Current Section and change it whatever you like.
Please bear in mind you will only need to split out your windows (Undock them). Then, when you click on Ctrl + Enter, it will do whatever you would like.
I hope you find this answer helpful.
You can try the solution from my FEX submission. The KbTimer is motivated by the need to capture keyboard stroke without the need of GUI that designed either by GUIDE or APP DESIGNER. Note that the implementation of function was inspired from the PsychToolbox which is MEX based.
I'm using the %% command to split my code into blocks for the sake of readability,
I collapse those blocks when i'm not working in them.
The default settings don't give you the ability to fold them, so my first question is:
Can you tweak this setting by command, so anyone who opens my script has the option to fold them?
My second question is: Can I program my code to set the blocks as collapsed by default?
Thanks in advance
It is indeed possible
1) Type preference in the command window to get up the preferences menu (or you find in under home)
2) Go to Editor/Debugger -> Code Folding
3) Mark the enable box for Sections
You could wrap your sections in the following way:
%% //Section header
for folding=true
%// Your code here
end %//folding
This allows you to fold on the for "loop".
It will work for everybody who has a fairly recent Matlab editor, without messing with editor settings.
Note that you should not have an actual variable named folding.
Yes, this is entirely possible:
com.mathworks.services.Prefs.setBooleanPref('EditorMCodeFoldEnabledcell', true);
The command takes effect immediately. Find more information in the article Changing system preferences programmatically.
When we're using ctags in vim and want to go to particular definition of variable or function we press ctrl + ], when we want to go back we press ctrl + T.
When we want to autocomplete a name of a variable we press ctrl + N and from a little violet window we can choose the right word.
Is it possible to improve go to definition so that we won't jump in the document, but only the little window with the function or variable definition will appear?
thank you
You want a way to see the function's signature without actually jumping to its definition?
I know about two plugins supposed to provide exactly this feature:
EchoFunc,
Tag Signature Balloons
The last time I tried echofunc it didn't work for JavaScript, at least for me, but it worked well for the few PHP files I've tested it with. I didn't try the other one because it's GVim-only and I use the CLI version almost as often as the GUI version.
But you can also use TagList and/or TagBar: two very useful plugins providing great code navigation based on ctags. Both will display the signature of the tag under your cursor if you hit <Space>.
I'd like to quickly move point to a function in my Emacs buffer. I'd like to run some function and get a prompt asking me for the function name, with completion provided for every function defined in the current buffer.
I generally use etags to navigate around, but sometimes I'm looking for a framework method that's been overridden in several files. In these cases, I can find the file I need but then I'd like to quickly jump to the function there. There is a similar feature in TextMate where you can select a definition from a list in the bottom right of the editor.
Just to jump around functions in the current file? Use imenu. It's the simplest and lightest of all the alternatives listed so far and might be enough for what you want. It's also built into Emacs and has minimum setup hassle. It features graphical and textual interfaces. Anything extra and you'll be better off using one of the other excellent suggestions made here.
speedbar comes standard, and gives you a collapsible menu for each file in the current directory, by default middle clicking on an entry for a function definition jumps to that def. With emacs23 this was changed to the more normal leftclick.
You can use etags-select to select from multiple matching tags. But the answer to what you asked is imenu.
Icicles is probably closer to what you are looking for:
http://www.emacswiki.org/emacs/Icicles_-_Tags_Enhancements
It's an enhancement to etags and includes (among other things) the file name with the tag so you can tell if it's the one you are looking for.
try CEDET. It is a bit difficult to set up the first, but here is an excellent tutorial: by Alex ott
And when he gets installed, you can use semantic-complete-jump. pressed tab couple times, and it is also brings up symbol definitions.
If M-. brings up the wrong method, you can type C-u M-. to find the next one with the same name.
global gtags is very good
To navigate within the current file or a set of files that you select, you do not need a TAGS file. You can use Imenu. But it is better to use Icicles imenu commands.
Why? Because they let you use completion. Substring, regexp, prefix, or fuzzy completion. Combine simple patterns to match, or subtract them.
Command icicle-imenu is bound in Icicle mode to C-c =. Butyou can also look up just a command or just a non-command function (non-interactive), using command icicle-imenu-command or icicle-imenu-non-interactive-function.
These commands are multi-commands, meaning that they are actually browsers: you can trip among function definitions using keys C-RET or C-mouse-2 (direct jumps) and C-down (cycle). Hit RET or click mouse-2 to settle down at a final destination.
I use C-M-a and C-M-e to jump between the beginning and end of functions.
Otherwise, open up Speedbar and click the + icon next to a file name to view a list of functions contained in the file. Then click on the function names to jump to them directly.