Tab wars revisited (was Re: Python indentation)

Steve Lamb grey at despair.dmiyu.org
Wed Jul 7 19:13:39 EDT 2004


On 2004-07-07, Istvan Albert <ialbert at mailblocks.com> wrote:
> Is there a reason why a TAB is not a TAB is not a TAB?

    Yes.  Name the number of spaces a TAB should translate into.  

    That was easy.  Now explain why your answer is right and the next guy's
answer, which is different than yours, is wrong.

    Oh, not so easy, eh?  TAB, by it's very nature, is a variable and
configurable width.  A SPACE is not.

> Is it really that trivial to set up an editor so that when one hits
> delete/backspace to 'un-align' a line of code it deletes as
> many space characters as the soft-tab has inserted?

> I don't think so.

    Uhm, yes, it is.  With vim part of my configuration when loading Python
files:
au FileType python set autoindent smartindent et sts=4 sw=4 tw=80 fo=croq

    Translates into:

Autoindent on
Smartindent on
Expandtab on
SoftTabStop 4 spaces
ShiftWidth 4 spaces
TextWidth 80 spaces
FormatOptions 
  c - auto-wrap comments, automatically inserting current comment character
  r - Automatically insert current comment character after hitting enter in
      in insert mode
  o - Automatically insert current comment character after hitting o or O in 
      command mode.
  q - allow formatting of comments with gq (IE, reflow and keep comment
      characters at the front of the line).

    Where's the magic?  Here:

-----
'softtabstop' 'sts'     number  (default 0)
                        local to buffer
                        {not in Vi}
        Number of spaces that a <Tab> counts for while performing editing
        operations, like inserting a <Tab> or using <BS>.  It "feels" like
        <Tab>s are being inserted, while in fact a mix of spaces and <Tab>s is
        used.  This is useful to keep the 'ts' setting at its standard value
        of 8, while being able to edit like it is set to 'sts'.  However,
        commands like "x" still work on the actual characters.
        When 'sts' is zero, this feature is off.
-----

    Number of spaces that a <Tab> counts for while performing editing
operations like....<BS> (Backspace).  IE, I set STS to 4.  I hit tab, 4 spaces
are inserted.  I hit backspace, 4 spaces are removed.  It's just that simple.

    As for alignment operations ShiftWidth is used for << and >> which are
used to (de)indent blocks of code.

-- 
         Steve C. Lamb         | I'm your priest, I'm your shrink, I'm your
       PGP Key: 8B6E99C5       | main connection to the switchboard of souls.
-------------------------------+---------------------------------------------



More information about the Python-list mailing list