[Tutor] OT (probably): How to change default tab key value to 4 spaces in GNOME Terminal?

Peter Otten __peter__ at web.de
Sun Apr 26 16:02:04 EDT 2020


boB Stepp wrote:

> On Sun, Apr 26, 2020 at 4:18 AM Peter Otten <__peter__ at web.de> wrote:
>>
>> Peter Otten wrote:
>>
>> > With readline you can do
>> >
>> > import readline
>> > readline.parse_and_bind("TAB: '    '")
>>
>> The moment I sent that suggestion I had a clever idea (I thought): Change
>> Python's completer to insert 4 spaces if there's no text to complete yet.
>>
>> But then I saw that this is already implemented for interpreters newer
>> than my aging default 3.4:
>>
>> [rlcomplete.py]
>>         if not text.strip():
>>             if state == 0:
>>                 if _readline_available:
>>                     readline.insert_text('\t')
>>                     readline.redisplay()
>>                     return ''
>>                 else:
>>                     return '\t'
>>
>> You might try replacing the '\t's with '    ' though.
> 
> Do you mean replace "\t" within rlcomplete.py?

Yes. 

If you are ambitious you can check `text` for the number of spaces and 
calculate the number of spaces necessary to bring you to the next multiple 
of four.

Keep a copy of the original file in case you mess up, or do the right thing 
and write your own subclass in a separate module and override the complete() 
method there. See the bottom of rlcomplete.py to learn how to install your 
custom Completer.




More information about the Tutor mailing list