IPython function definition indentation - ipython

Is there a configuration option to make ipython history bring up the entire previously entered function block, rather than doing it line by line?

Related

Convert greek latex symbol in the jupyter-lab text editor

In Jupyter Notebooks you can type, for example \alpha and hit the tab key and the \alpha changes into α. This is a pretty cool feature. Unfortunately, it doesn't work in the jupyter-lab editor. Any reason why that doesn't work? Or do I need to set a preference somewhere?
if you type $\alpha$ it will be rendered as the greek letter thanks to latex
Although the answer of #joelostblom works fine, you can simply install the LaTeXStrings Julia package to enable the \alpha [tab] feature without needing to spawn an IPython kernel.
using Pkg
Pkg.add("LaTeXStrings")
This feature is provided by the IPython kernel, not the Jupyter Notebook. The kernel provides TAB completion by looking up the latex (or latex-like) symbol in this dictionary (originally from Julia) and then inserts its value (the corresponding Unicode character). As such, there needs to be an active IPython kernel to provide the TAB completion (here is the PR that added the functionality to IPython in case you want to read more about it).
An IPython kernel is automatically started with the notebook and used when running cells, but this is not the case when editing a text file (which is also why there is no TAB completion for other things such as imports, etc). You can start one manually by right clicking inside a Python text file and selecting "Create console for editor". After that autocompletion works just as in the notebook, including Greek latex symbols.

Is there a way to edit last Octave command and /or script typed in Octave CLI

typing and executing a single line command in octave cli is simple.
for example a=1.
If one wants to edit this command and execute it again it is possible by navigating the history with the up/down keys.
But when executing a multi line command-script, one can still navigate to a single line and edit it, but how to execute the all script again, without going line by line in the history and "enter" the line?
for example:
for i=1:6
a(i) = i;
end
Is there a way to open the all script in an editor, edit, and re-execute it?
Yes there is, via the history command.
E.g. history -q 3 will display the last 3 commands -- the -q switch means do not prepend line numbers, such that the output is copy-pasteable.
You can also use the -w switch to redirect the output to a file, which you could then modify in your editor and call as a script, as you suggest.
If you're using the GUI, you can also use the history pane to highlight the lines you're interested in (in the order that you want them!), and paste directly into the editor window.

Change RET behavior in IPython shell

In IPython (5.3 in this case) pressing the RET has double meaning:
send current input to the interpreter
insert line break to the current input and let the user to modify it further
Looks like the first one is implemented only if the the cursor is in the beginning or end of the line. How can I change this behavior? For example have a separate keystroke for this purpose.
P.S. Any link to keybindings configuration in IPython would also be much appreciated.

Execute/Run a single line in IPython rather entire Cell

I have often this problem, when I'm slicing or subsetting data that I want to view/print [df.head()] the data and look into into it before writing next line of my code.
For this case, every time, I have to run the whole block(cell) in ipython, even if I have some logic written I had to comment that block and execute my print line alone.
Is there a feature where you can select a single line and execute it.
I often start a qtconsole attached to the kernel. You can do that as follows:
Create a new cell.
In the new cell, type %qtconsole and execute that cell.
Delete the new cell.
Once you have a qtconsole that is attached to the notebook kernel. You can print
the value of variables there.

When using magic %paste in ipython, how can i get it to just paste the copied code, rather than paste and execute, so that it can be edited

When using magic %paste in ipython, it executes pasted code, rather than just pasting. How can i get it to just paste the copied code so that it can be edited?
You have two options:
To edit it by hand, run %cpaste. Then you can paste it in with standard terminal options (try Ctrl-Shift-V), and edit it. Enter -- on a line to finish.
To change it as text in your code, run %paste foo. It will store the clipboard contents in foo.
Adding to Thomas K's answer (quoted below), if you have stored statements to a string variable foo by using %paste foo, you can later run that string (or any python statements in string form) using the exec(foo [, globals, locals]).
You have two options:
To edit it by hand, run %cpaste. Then you can paste it in with standard terminal options (try Ctrl-Shift-V), and edit it. Enter --
on a line to finish.
To change it as text in your code, run %paste foo. It will store the clipboard contents in foo.
There is a solution for this issue in ipython, if you are not concerned with indentation,
Just run %autoindent to Automatic indentation OFF.