Using tabs instead of spaces in IDLE? 
Author Message
 Using tabs instead of spaces in IDLE?

Is there a way to use tabs exclusively for indentation in IDLE?  Basically,
I'd like tabwidth to equal identwidth while permitting developers to adjust
the indentwidth.  I see that AutoIndent.py says

    # indentwidth is the number of characters per logical indent level.
    # tabwidth is the display width of a literal tab character.
    # CAUTION:  telling Tk to use anything other than its default
    # tab setting causes it to use an entirely different tabbing algorithm,
    # treating tab stops as fixed distances from the left margin.
    # Nobody expects this, so for now tabwidth should never be changed.
    usetabs = 1
    indentwidth = 4
    tabwidth = 8    # for IDLE use, must remain 8 until Tk is fixed

But I don't quite understand that explanation.  

The reason I ask is that I'm going to be introducing Jython to a bunch of
Java developers at work.  I expect to get a lot of complaints about blocks
being delimited by whitespace (already got one), and I'd like to be ready
with nice editor configurations so that it's never a practical problem for
our team.  Our group's current coding style (for C++ and Java) includes
indentation by tabs.  Every developer sets his editor to always insert a
tab when the tab key is pressed, but they adjust the visual display of the
tab size to be whatever they want it to be.  It doesn't look like IDLE is
friendly to that type of customization.  I know that emacs is.  I'm
currently investigating the other editors that my team uses, such as
CodeWright.

Thanks,
---Tom



Mon, 02 Aug 2004 10:21:03 GMT  
 Using tabs instead of spaces in IDLE?
On Thu, 14 Feb 2002 02:21:03 GMT

Quote:

> Is there a way to use tabs exclusively for indentation in IDLE?
Basically,
> I'd like tabwidth to equal identwidth while permitting developers to
adjust
> the indentwidth.  I see that AutoIndent.py says

I don't use IDLE, so I can't answer your question (I use XEmacs).  However,
I've long been a {*filter*} tabber but recently decided to uses spaces
instead.  I've found through experience that this is probably the best way
to go when coding in Python.  Further, since Emacs (and I've heard, vim)
support treating groups of spaces as a single tab (tab inserts n number of
spaces, backspace takes you back n spaces), there really isn't much
functional difference between the two when editing.

So why change?  Because I've found that most python code you will find uses
spaces.  Certainly all the code in the standard library does.
Cutting/pasting will go much easier in the typical case than if you use
tabs.  If you decide to edit a python file you've gotten from the standard
library or from a contributed source, you will have to remember to indent
with spaces and not automatically reach for the tab key.  If you forget,
you'll have an invisible error in your file (although the traceback will
usually lead you quickly to it).  I've had this happen enough that I
finally capitulated and made the switch.  End result: editing my code is
about the same and editing other's code is far easier.

Regards,

--
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308  (800) 735-0555 x308



Mon, 02 Aug 2004 10:50:58 GMT  
 Using tabs instead of spaces in IDLE?

Quote:
>to go when coding in Python.  Further, since Emacs (and I've heard, vim)
>support treating groups of spaces as a single tab (tab inserts n number of
>spaces, backspace takes you back n spaces), there really isn't much
>functional difference between the two when editing.

While I'm sure you know what you mean, other readers might not realize
that the genuinely useful capability of vim (and I suspect Emacs, if you
mean what I think you mean) is to not insert some constant 'n' spaces,
but rather to:

"insert just enough spaces to get you to the next tabstop".

And while vim indeed does just what I said, when you backspace over
these runs of spaces while in insert mode, it knows how those spaces
where generated and so:

"deletes any such spaces inserted through a tab, just as if
it were deleting a single tab."

This is a very useful capability. As for how to get it, one might
insert the following into their .vimrc:

set tabstop=8
set softtabstop=4
set shiftwidth=4
set et
"ascii-183==
"ascii-187==?
set lcs=tab:?\
set list

The above configuration has the following properties:

1. "set tabstop=8". This leaves *hard* tabs at 8, so that whenever
you open a file with "real" tabs in it, they will have the same
indentation level as more, cat, lpr, and so forth are likely to.

2. "set softtabstop=4". This governs the behavior of the normal
tab key in vim.

3. "set shiftwidth=4". This sets autoindent to use a indentation
level of 4 after code blocks are begun.

4. "set et". This tells vim to never insert tabs. Use runs of
spaces instead.

5. "set lcs=tab:?\ ". This tells vim to use ascii-187 (the single
'>>' char) as a visible marker of all *real* tabs in your file.
This makes physical tabs as plain as day in your file: helpful
for seeing what's wrong with makefiles. Similar to the "Show-P"
feature in Word.

6. "set list". Turns #5 on.

Two notes. You can't type ascii 187 with an ordinary character.
In vim, you get it buy typing '<ctrl>V187'. The two lines before
the "set lcs" line are just vim comments that I have so that I
don't forget the numeric codes.

One last note. You're going to forget this eventually.

What if you want to type a *real* tab?

<ctrl>V<tab>

Or you can "set noet" to temporarily turn of tab expansion.

C//



Mon, 02 Aug 2004 11:35:07 GMT  
 Using tabs instead of spaces in IDLE?

Quote:

> On Thu, 14 Feb 2002 02:21:03 GMT

> I don't use IDLE, so I can't answer your question (I use XEmacs).

Same here. :-)

Our QA department is likely to use IDLE, I would guess.  The development
team will probably use a mixture of editors (CodeWright, vi, XEmacs, etc.).
 The developers should have already set their tools to always use tabs
because of our existing coding style guidelines.  If QA uses IDLE, then
it'll cause a mess.  If a developer has to use tabs for Java and spaces for
Python, things could get messy.  (Not in XEmacs, but I'm not sure how good
some of the other editors are at per language configuration.)

perhaps-we-should-all-just-use-ed-ly y'rs
---Tom



Mon, 02 Aug 2004 11:46:25 GMT  
 Using tabs instead of spaces in IDLE?
[Tom Bryan]

Quote:
> Is there a way to use tabs exclusively for indentation in IDLE?

Yes, provided you're happy with indentwidth==8.

Quote:
> Basically, I'd like tabwidth to equal identwidth while permitting
> developers to adjust the indentwidth.

You're out of luck there, if they want anything other than 8 for both.

Quote:
>  I see that AutoIndent.py says

> # indentwidth is the number of characters per logical indent level.
> # tabwidth is the display width of a literal tab character.
> # CAUTION:  telling Tk to use anything other than its default
> # tab setting causes it to use an entirely different tabbing algorithm,
> # treating tab stops as fixed distances from the left margin.
> # Nobody expects this, so for now tabwidth should never be changed.
> usetabs = 1
> indentwidth = 4
> tabwidth = 8    # for IDLE use, must remain 8 until Tk is fixed

> But I don't quite understand that explanation.

Don't be so timid <wink>:  change the code and see what happens.  The
meaning of the comment will soon become painfully clear.  Have you ever used
a word processor (as opposed to a text editor)?  Tk switches to "word
processor" tabs when you change its default tab setting.

Quote:
> ...
> It doesn't look like IDLE is friendly to that type of customization.

Not exactly:  the Tk text widget is the hangup here.  IDLE's autoindent code
is shared by PythonWin, which latter, being based on the Scintilla text
widget, doesn't suffer the same tab surprises.

Quote:
> I know that emacs is.  I'm currently investigating the other editors
> that my team uses, such as CodeWright.

CodeWright won't be a problem.  But stick to IDLE's default (== the Emacs
python-mode default), and no editor anywhere will be a real problem.


Mon, 02 Aug 2004 12:29:43 GMT  
 Using tabs instead of spaces in IDLE?

Quote:

> [Tom Bryan]
>> Is there a way to use tabs exclusively for indentation in IDLE?

> Yes, provided you're happy with indentwidth==8.

:-P

Quote:
>> Basically, I'd like tabwidth to equal identwidth while permitting
>> developers to adjust the indentwidth.

> You're out of luck there, if they want anything other than 8 for both.

That's what I was afraid of.  I think that Jython could do good things for
my group at work, but I really don't look forward to the stupid whitespace
discussions.  It's bad enough on c.l.py.  I can't wait to hear it in person.

Quote:
>>  I see that AutoIndent.py says
[...snip...]
>> But I don't quite understand that explanation.

> Don't be so timid <wink>:  change the code and see what happens.  

I did.  I changed it to 4 and 4.  I toggled tabs on in Idle.  It seemed to
work on my Linux box.

Quote:
> meaning of the comment will soon become painfully clear.  Have you ever
> used a word processor (as opposed to a text editor)?  Tk switches to "word
> processor" tabs when you change its default tab setting.

Ick.  So the tabs will depend on the font, etc.?

Quote:
>> ...
>> It doesn't look like IDLE is friendly to that type of customization.

> Not exactly:  the Tk text widget is the hangup here.  IDLE's autoindent
> code is shared by PythonWin, which latter, being based on the Scintilla
> text widget, doesn't suffer the same tab surprises.

Hm.  PythonWin might be a good option.  The UNIX heads will probably just
use vi and Emacs, which I think we can handle.  The current "approved"
coding style for all languages in the group is supposed to be "always
indent with leading tabs; for alignment purposes, tabs should be viewed as
4 spaces; set your visual display of tabs to whatever you prefer."  

Quote:
>> I know that emacs is.  I'm currently investigating the other editors
>> that my team uses, such as CodeWright.

> CodeWright won't be a problem.  But stick to IDLE's default (== the Emacs
> python-mode default), and no editor anywhere will be a real problem.

I would, but then we've got spaces in some languages and tabs in others.  
And I dread the discussion of how many spaces one level of indentation
should be even more than I dread the whitespace-delimited-blocks whining.

I've already been coding some samples with

(defun my-python-mode-hook ()
  (setq tab-width 4)
  (setq indent-tabs-mode t)
  )
(add-hook 'python-mode-hook 'my-python-mode-hook)  

It's stupid, but the whitespace issue is probably going to be one of the
biggest obtacles to introducing Jython to my co-workers.  I'll be back to
tell everyone how it goes.

I-just-hope-no-one-mentions-the-alien-whitespace-eating-nanovirus-ly y'rs,
---Tom



Mon, 02 Aug 2004 21:13:50 GMT  
 Using tabs instead of spaces in IDLE?

Quote:
> Tom Bryan

> That's what I was afraid of.  I think that Jython could do good things for
> my group at work, but I really don't look forward to the stupid whitespace
> discussions.  It's bad enough on c.l.py.  I can't wait to hear it in person.

This is now fixed for c.l.py
http://python.sourceforge.net/peps/pep-0666.html

Good luck with your co-workers.

Laura Creighton



Tue, 03 Aug 2004 00:20:12 GMT  
 Using tabs instead of spaces in IDLE?

Quote:

> And while vim indeed does just what I said, when you backspace over
> these runs of spaces while in insert mode, it knows how those spaces
> where generated and so:

> "deletes any such spaces inserted through a tab, just as if
> it were deleting a single tab."

This sounds ingenious, but what happens when you save the
file and load it back? Does it remember this information
somehow, or does it get lost?

--
Greg Ewing, Computer Science Dept, University of Canterbury,      
Christchurch, New Zealand
To get my email address, please visit my web page:        
http://www.cosc.canterbury.ac.nz/~greg



Tue, 03 Aug 2004 09:44:45 GMT  
 Using tabs instead of spaces in IDLE?

Quote:


>> And while vim indeed does just what I said, when you backspace over
>> these runs of spaces while in insert mode, it knows how those spaces
>> where generated and so:

>> "deletes any such spaces inserted through a tab, just as if
>> it were deleting a single tab."

> This sounds ingenious, but what happens when you save the
> file and load it back? Does it remember this information
> somehow, or does it get lost?

The editor remembers this information by saving it in the text file
itself.

--
CARL BANKS                                http://www.aerojockey.com
"Nullum mihi placet tamquam provocatio magna.  Hoc ex eis non est."



Tue, 03 Aug 2004 10:38:11 GMT  
 Using tabs instead of spaces in IDLE?
On Fri, 15 Feb 2002 14:44:45 +1300

Quote:


> > And while vim indeed does just what I said, when you backspace over
> > these runs of spaces while in insert mode, it knows how those spaces
> > where generated and so:

> > "deletes any such spaces inserted through a tab, just as if
> > it were deleting a single tab."

> This sounds ingenious, but what happens when you save the
> file and load it back? Does it remember this information
> somehow, or does it get lost?

It doesn't.  It saves the file with spaces.  It's basically emulating tabs
with spaces.  That's the whole point - you get the convenience of tabs with
the uniformity (conventions-wise) of spaces.

--
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308  (800) 735-0555 x308



Tue, 03 Aug 2004 10:31:09 GMT  
 Using tabs instead of spaces in IDLE?

Quote:
----- Original Message -----



> >> And while vim indeed does just what I said, when you backspace over
> >> these runs of spaces while in insert mode, it knows how those spaces
> >> where generated and so:

> >> "deletes any such spaces inserted through a tab, just as if
> >> it were deleting a single tab."

> > This sounds ingenious, but what happens when you save the
> > file and load it back? Does it remember this information
> > somehow, or does it get lost?

> The editor remembers this information by saving it in the text file
> itself.

Psychic text editing?  :-)

Actually, when backing over a space which is lined up exactly on a
tab position, vim assumes it must represent a tab; else it is handled
as a "normal" space.



Tue, 03 Aug 2004 11:17:03 GMT  
 Using tabs instead of spaces in IDLE?

Quote:
>> This sounds ingenious, but what happens when you save the
>> file and load it back? Does it remember this information
>> somehow, or does it get lost?

>The editor remembers this information by saving it in the text file
>itself.

I believe that you're answering a different question than what
he asked. The ability of vim to "backspace" over a current
line and treat those spaces entered as if it were a single
tab is possible on the current *line* being introduced in insert
mode only.

Still, this mode works fairly well, and is about as compatible-
with-Python as you can get. For those who sometimes have to
switch back and forth between modes in different files, they
might like this feature:

## vim: et ts=8 sts=4

Vim reads the "vim:" command in your file and interprets it.
You typically put this at the head of your file, somewhere
near where you do the $Id: $ thingy for CVS.

C//



Tue, 03 Aug 2004 12:10:03 GMT  
 Using tabs instead of spaces in IDLE?

Quote:

>>> This sounds ingenious, but what happens when you save the
>>> file and load it back? Does it remember this information
>>> somehow, or does it get lost?

>>The editor remembers this information by saving it in the text file
>>itself.

> I believe that you're answering a different question than what
> he asked.

Yeah.  Although the question was about vim, my mind was still thinking
Emacs from a few posts ago.  Emacs scans the line(s) above to
determine how to unindent, i.e., all of the unindent information is
saved in the file.

--
CARL BANKS                                http://www.aerojockey.com
"Nullum mihi placet tamquam provocatio magna.  Hoc ex eis non est."



Tue, 03 Aug 2004 14:43:49 GMT  
 Using tabs instead of spaces in IDLE?
Carl Banks || Thu 14 Feb 2002 10:43:49p:

Quote:

>>>> This sounds ingenious, but what happens when you save the
>>>> file and load it back? Does it remember this information
>>>> somehow, or does it get lost?

>>>The editor remembers this information by saving it in the text file
>>>itself.

>> I believe that you're answering a different question than what
>> he asked.

> Yeah.  Although the question was about vim, my mind was still thinking
> Emacs from a few posts ago.  Emacs scans the line(s) above to
> determine how to unindent, i.e., all of the unindent information is
> saved in the file.

Perhaps more clearly: The formatting of the code itself is the unindent
information; emacs examines the code struture to figure out how to do this
(and other things).

--
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com



Wed, 04 Aug 2004 15:13:41 GMT  
 Using tabs instead of spaces in IDLE?
[Tom Bryan, on fiddling the the Tk text widgets default tab width]

Quote:
> I did.  I changed it to 4 and 4.  I toggled tabs on in Idle.  It
> seemed to work on my Linux box.

Are you sure?  Here's what I see, laboriously replacing tabs with spaces by
hand so you'll see the same thing, and using Courier New (a fixed-width
font, just to simplify life).  It's not the initial whitespace that screws
you, so it's quite likely you don't notice at first.  Everywhere you see a
run of whitespace (one or more blanks) here, I hit TAB once followed by the
letter T:

123456789012345678901
    T   T   T   T   T
a   T   T   T   T   T
ab  T   T   T   T   T
abc T   T   T   T   T
abcd T  T   T   T   T
abcde T T   T   T   T
abcdef T T  T   T   T
abcdefg T T T   T   T

No programmer expects that.  Tk "wants to" put the character following the
first hard tab into column 5, no matter how far to the right of column 5 you
are when you hit the tab key for the first time.  Similarly it "wants to"
put the character following a line's second hard tab in column 9, and again
irrespective of where on the line you are when you hit tab the second time.

What programmers expect is:

123456789012345678901
    T   T   T   T   T
a   T   T   T   T   T
ab  T   T   T   T   T
abc T   T   T   T   T
abcd    T   T   T   T   T
abcde   T   T   T   T   T
abcdef  T   T   T   T   T
abcdefg T   T   T   T   T

It's incredibly jarring when you delete characters "on the left side" of
lines containing hard tabs after changing the Tk default, as the widget goes
thru amazing hoops trying to keep seemingly random portions of the remaining
line at fixed distances from the left margin.

Quote:
> Ick.  So the tabs will depend on the font, etc.?

Not really; IDLE tries to compute the "average width" of a character in the
font then, but that's just to fool the Tk text widget; see the latter's docs
at, e.g.,

    http://tcl.activestate.com/man/tcl8.4/TkCmd/text.htm

You'll find that the only way to specify non-default tabs under the covers
is to give a list of absolute distances from the left margin (in units of
centimeters or inches or points, etc, but not in units of "characters").

Quote:
> Hm.  PythonWin might be a good option.  The UNIX heads will probably just
> use vi and Emacs, which I think we can handle.  The current "approved"
> coding style for all languages in the group is supposed to be "always
> indent with leading tabs; for alignment purposes, tabs should be
> viewed as 4 spaces; set your visual display of tabs to whatever you
> prefer."

Well, everyone is entitled to live with the consequences of their
self-imposed insanities <wink>.

Quote:
> I would, but then we've got spaces in some languages and tabs in others.

Most (all?) programmer's editors can be taught to use different rules based
on file extension.  The standard for the Python library is 4-space indents
and no hard tab characters anywhere.  That's what the Python developers have
learned works best.

Quote:
> ...
> It's stupid, but the whitespace issue is probably going to be one of the
> biggest obtacles to introducing Jython to my co-workers.  I'll be back to
> tell everyone how it goes.

So don't tell them.  Use Jython yourself, and leave them in the dust.
They'll either beg to learn your secret, or you'll be promoted so high so
fast you won't have to endure them anymore <wink>.

let-'em-stew-in-their-own-tabs-ly y'rs  - tim



Thu, 05 Aug 2004 16:21:55 GMT  
 
 [ 16 post ]  Go to page: [1] [2]

 Relevant Pages 

1. used space 0, free space 0

2. problem with using TAB button in tabbed dialogs

3. Can foreach work on newline instead of space ?

4. How to use the ENTER instead of TAB to each fields

5. Enter key instead of Tab

6. Enter instead of Tab

7. VO: Enter key instead of tab question

8. Q: Using arrays instead of using a list

9. Pythonw IDLE Tab setting

10. spaces on idles last line

11. changing tabs to spaces

12. Running out os space for tabs

 

 
Powered by phpBB® Forum Software