Terry J. Reedy added the comment:

I looked more into tab handling in tk and Idle. Tk uses literal tabs in text to 
position following text according to the tab stops configured with the Text 
tabs option.  Tabs stops are ultimately set to the pixel (not character), 
although one may enter distances in other units.  The following text may be 
left, right, center, or number justified with respect to the tab stop, with 
'left' the default.  I am rather sure that there is no way to tell tk to 
display a special char at the beginning of any extra space it adds. In the 
general case, there may not be enough extra to do so.

Tab handling in Idle is more confused.  They are normally converted to spaces 
in Editor windows, but in left as is and used for auto-indents in multi-line 
statements in Shell.  (The latter is a major nuisance, which I hope to remedy.) 
 There are more oddities within the editor, some probably not necessary now.  
One is that turning tabs on and off changes the tab to space replacement to 8 
instead of what it was (the default now being 4).  Another is that Idle was 
written when mixed space-and-tab indents were legal.  So a) Idle allows one to 
write illegal-in-3.x indents, and b) the code to handle tab, backspace, enter, 
indent, and dedent is probably more complicated that it would have to be if 
illegal indents were never allowed.  (The tab handling code is in 
EditorWindow.py, in 3.4.2 mostly around lines 240-260 and 1200-1300.)

Given the above, I would consider tagging tabs at least when a file is read and 
probably during editing.  Since indents are the major concern, I would not 
worry much about what happens elsewhere.
---

Successive tabs could be differentiated by having two tab tags with different 
background colors and alternate their use.  The following does this with a 
sample line.

import tkinter as tk
root = tk.Tk()
text = tk.Text(root)
text.pack()

text.tag_config('TAB0', background='#fed')  # light yellow
text.tag_config('TAB1', background='#eef')  # light blue
ttags = ('TAB0', 'TAB1')
tdex = 0

line = 'a\t\t    \t b'
text.insert('insert', line)
for i, c in enumerate(line):
    if c == '\t':
        text.tag_add(ttags[tdex], '1.%d'%i, '1.%d'%(i+1))
        tdex ^=1

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue22354>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to