Emacs Mode and Tabs

Michael Powe michael+news at trollope.org
Fri Dec 20 18:08:27 EST 2002


Robin Munn wrote:

> Justin Shaw <wyojustin at hotmail.com> wrote:
> > "Thomas Guettler" <pan-newsreader at thomas-guettler.de> wrote in message
> > news:pan.2002.12.19.20.21.39.180460.730 at thomas-guettler.de...
> >> Hi!
> >>
> >> I use xemacs with python-mode 4.1
> >>
> >> Unfortunately it does not automatically detect
> >> if a file uses spaces or tabs for indentation.
> >>
> >> Is there a switch to make xemacs do the right
> >> thing automatically?
> >>
> >>  thomas
> > 
> > Reindent all of your files with spaces then emacs will always do the right
> > thing.
> > Justin
[ ... ]
 
> Some people like to use spaces for indentation. Their argument is that
> tabs should be avoided *precisely* because they give different views of
> the same source file. Consistency within the file is more important than
> having it look the way you prefer. And tabs would be fine if everyone
> used them only for indentation, but that never happens. Inevitably,
> someone will want to (say) split an if condition across two lines, and
> their tab settings won't line up on the column they want. So they use
> spaces to fill in the rest. Then when someone else (who uses different
> tab settings) looks at the file, they see the if condition with wacky
> indentation, and it looks ugly.

However, if you program in emacs, it's a non-issue, because emacs in a
programming mode will "do the right thing" with indentation, whether you
are using tabs or spaces.  if you split a conditional, or a parameter
list, or whatever, it will be lined up automagically, as it should be.

from the emacs manual:

S.3 Tabs vs. Spaces 
Emacs normally uses both tabs and spaces to indent lines. If you prefer,
all indentation can be made from spaces only. To request this, set
indent-tabs-mode to nil. This is a per-buffer variable, so altering the
variable affects only the current buffer, but there is a default value
which you can change as well. See section AD.2.4 Local Variables. 

There are also commands to convert tabs to spaces or vice versa, always
preserving the columns of all nonblank text. M-x tabify scans the region
for sequences of spaces, and converts sequences of at least three spaces
to tabs if that can be done without changing indentation. M-x untabify
changes all tabs in the region to appropriate numbers of spaces. 

emacs:  God's Own Editor (tm)  ;-)

at any rate, this gets rid of tabs:

(Linux 2.4.18-18.7.x.spire) [/home/looie]   3:04pm                      
 {19} --> sed -e 's/[tab here]/[spaces here]/g' test > newtest


mp



More information about the Python-list mailing list