[Tutor] OT (probably): How to change default tab key value to 4 spaces in GNOME Terminal?
DL Neil
PyTutor at danceswithmice.info
Sun Apr 26 00:53:33 EDT 2020
On 26/04/20 4:10 PM, boB Stepp wrote:
> Linux Mint, Python 3.7.5, GNOME Terminal 3.28.1
>
> A while back I became tired of the default Python interpreter prompt
> ">>>" and replaced it with the Python version number, e.g., "3.7.5:
> ". But my original version that I have used for years did not take
> into account the secondary default prompt "..." and where it put the
> cursor. For whatever reason my annoyance level with this flaw rose
> high enough today that I fixed it as follows:
>
> """Configure prompt appearance in Python REPL."""
>
> import sys
>
> py_version = sys.version.split()[0]
> sys.ps1 = py_version + ": "
>
> # Ensure cursor lines up with previous line of code:
> sys.ps2 = "..." + " " * (len(sys.ps1) - 3)
>
> This does what I want, but now there is a new annoyance:
>
> 3.7.5: def f(s):
> ... print(s)
> ...
> 3.7.5: f('Jeremy')
> Jeremy
>
> In the second line as I was typing it I pressed <tab> when the cursor
> was lined up with the "d" in "def". What I see in the terminal is the
> "p" in "print" lining up under the colon as I have shown above. I
> understand that the default terminal behavior is that <tab> shifts in
> 8 columns wide tab stops. I would like to change this behavior for
> when I am in the Python interpreter to have <tab> always shift 4
> columns from the starting cursor position. Does anyone know how to
> accomplish this?
>
> After some searching online the best advice I could find was to enter
> at the command prompt "tabs -4". I tried this and as far as I can
> tell it did not work for me while in the Python interpreter.
You are not alone!
However, the first point to understand is that in the interpreter TAB
performs a "completion" function. Indeed (whilst this is definitely in
'do as I say, not as I do' territory) please recall what PEP-8 has to
say about TABs!
You will find (very little) sympathy in the Python Tutorial:
14. Interactive Input Editing and History Substitution
https://docs.python.org/3/tutorial/interactive.html
--
Regards =dn
More information about the Tutor
mailing list