Creating a Matlab run line shortcut (like R) - macos

R has a great shortcut that runs the line your cursor is currently on then moves the cursor onto the next line (cmd + return). In matlab, you have to highlight the line then run the highlighted section (shift + F7).
Is there a way to create an 'R like' run line shortcut? I'm using OSX.

On the Home tab, click New, and then select Command Shortcut.
In the Label field: enter a name for the shortcut.
In the Callback field:
currentEditor = matlab.desktop.editor.getActive;
originalSelection = currentEditor.Selection; assert(originalSelection(1)==originalSelection(3));
currentEditor.Selection = [originalSelection(1) 1 originalSelection(1) Inf]; disp(currentEditor.SelectedText);
eval(currentEditor.SelectedText);
currentEditor.Selection = originalSelection + [1 0 1 0];
Now I can run the line I'm on by pressing Alt+s+1 (perhaps you can change this to an arbitrary hotkey). I hope this helps.
EDIT: In MATLAB R2018a Command Shortcuts have been repackaged as Favorite Commands. So to create a new shortcut in this and later version, you need to go Home tab -> Favorites -> New Favorite.
EDIT: You currently (in MATLAB R2020b) can run this code with Alt+1 (no need for 's' as above). However, it does not appear to be changeable in Preferences -> Keyboard -> Shortcuts

currentEditor = matlab.desktop.editor.getActive;
originalSelection = currentEditor.Selection;
currentEditor.Selection = [originalSelection(1) 1 originalSelection(3) Inf]; disp(currentEditor.SelectedText);
eval(currentEditor.SelectedText);
currentEditor.Selection = [originalSelection(3),0,originalSelection(3),0]+[1,0,0,0];

Related

Use gnuplot within Fortran code in Windows

I have a fortran code as below
program compute_plot
integer :: i, n = 10
real :: x(10), y(10)
x(1) = 0.0
y(1) = 0.0
do i = 2, n
x(i) = 0.1*i
y(i) = x(i)*x(i)
end do
open(unit = 5, file = 'data.txt')
do i = 1, n
write(5,*) x(i),y(i)
end do
close(5)
call system('gnuplot -p data_plot.gnu')
end program compute_plot
and another gnuplot script as below
reset
set terminal pngcairo dashed enhanced size 480,360 font 'arial,12' fontscale 1.0
set encoding utf8
set output 'plot.png'
set xlabel "x"
set ylabel "y"
m = "./data.txt"
set title 'The parabola'
plot m using 1:2 w l
These two code work well in Linux terminal, but I could not find a way to make them work in Windows command prompt. I also not sure if it is possible to make them work in Windows. Please advise.
Download gp503-win32-mingw.zip from gnuplot official webpage;
Extract the zip file in your desired folder, e.g. F:Document;
The gnuplot folder will now have the path of F:\Documents\gnuplot\;
Right click This PC, click on Properties, click on Advanced system settings, click on Advanced tab, click on Environment Variables...;
Choose Path on the top table of Environment Variables windows, then click Edit...;
Now click on New to add in the path of gnuplot.exe, e.g. in my desktop F:\Documents\gnuplot\bin
To check if it is working properly, go to Command prompt and run the command of gnuplot.

How can I find the particular file in a Project/Folder in Sublime Text

I know that using ctrl+shift+f we can find the text in folder we want and simple ctrl+f will find the text in a opened file or we can right folder and click on a option Find in Folder... to search the text
I am looking for, how can I find the file in a Folder/Project.
You can use the Goto Anything feature (Ctrl+P on Windows and Linux, Cmd+P on macOS) and type the name of the file you're looking for. If there are multiple hits, you can select the appropriate file using cursor keys. It also supports powerful operators, that let you jump to specific parts inside a file.
Examples:
file.js opens that file
:100 jumps to line 100 in current file
file.js:100 jumps to line 100 in file.js
#loadFile lists all files with classes/functions named loadFile (shortcut: Ctrl+R, Cmd+R on macOS)
file.js#loadFile jumps to a loadFile() in file.js
This can be done using:
Windows: Ctrl + P
Mac: Cmd + P
It works much like ItelliJ's Shift - 2 times, with a faster and accurate prediction.

Sublime Text: prevent new line comment

I am not completely sure if this not a plugin, but after starting a line comment in .js file, for example, when I hit enter the next line starts with "//" as well. This is kind of annoying. Is there a simple way to remove this?
In "Preferences -> Package Settings -> Doc Blockr -> Settings Default" you can find lines:
// If true, then pressing enter while in a double-slash comment (like this one)
// will automatically add two slashes to the next line as well
"jsdocs_extend_double_slash": true,
If you want to disable this behavior go to "Preferences -> Package Settings -> Doc Blockr -> Settings Default" and add
{
"jsdocs_extend_double_slash": false
}
This is indeed caused by the package DocBlockr.
When using this package, you can hit shift + enter to prevent the // from appearing on your new line.

XCode: How to join two lines?

Say I have this:
CGColorSpaceRef space =
CGColorGetColorSpace(col.CGColor);
Is there a hotkey in XCode that lets me join these two lines together into:
CGColorSpaceRef space = CGColorGetColorSpace(col.CGColor);
?
Simplest method I have found: Position your cursor at the end of a line, then CTRL-SHIFT-RIGHT CTRL-SHIFT-LEFT SPACE.
There is no such function like the "J" command in VI.
Old question but I was looking for a way today, and ended up adding:
<key>JoinLines</key>
<dict>
<key>Join Current Line</key>
<string>moveDown:, moveToBeginningOfText:, deleteToBeginningOfLine:, deleteBackward:</string>
</dict>
In file:
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist
(to be edited with sudo)
Then restart XCode, go to preferences -> Key Bindings, and assign some shortcut to "Join Current Line". Seems to work!
Xcode 13.2 added CTRL-J [Join paragraphs (Deletions)].
There's at least one extension for Xcode Source Editor that provides "Join Lines" command, available in AppStore: TextPlus. After installing and activating the extension, you can assign any shortcut to the corresponding "Join Lines" menu via Xcode > Preferences > Key Bindings.

xcode All-in-one layout: keyboard shortcut to switch between project and debug page?

When you configure xcode to use the All-in-one layout, a toggle appears to allow you to switch between project and debug 'mode' (the IDE calls these pages).
Is there a keyboard shortcut to perform the toggle?
Project: Cmd + 0 (zero)
Build: Cmd + Shift + B
Debug: Cmd + Shift + Y
Found this here: http://www.cocoabuilder.com/archive/xcode/252986-keyboard-shortcut-for-next-page-in-all-in-one-layout.html
More shortcuts:
http://cocoasamurai.blogspot.com/2008/02/complete-xcode-keyboard-shortcut-list.html
I use (discovered)
Cmd + ~
using all in one setup

Resources