[Pythonmac-SIG] Using Spaces for indentation in IDE
Oliver Steele
steele@cs.brandeis.edu
Wed, 11 Aug 1999 06:19:13 -0400
Joseph J. Strout <joe@strout.net> writes:
> At 1:45 PM -0700 07/23/99, Chris Barker wrote:
>>Can the IDE be set up to use just spaces for indentation? I'd like it to
>>be just like Emacs mode.
>
> If you must continue down this evil path, I think this is your most likely
> bet. Hack the IDE code that loads and saves files. On loading, have it
> convert spaces to tabs. On saving, have it convert tabs to spaces.
I needed a solution for this too. (In addition to wanting to work with the
many sources I download from the web, I'm doing cross-development work with
people using other IDEs on Windows and UNIX.)
I've put a patch that does this at
http://www.cs.brandeis.edu/~steele/sources/python.html, at
PyIDESpacesToTabsPatch.py. 'import' this file, and it'll patch the IDE to
change spaces to tabs, and back.
This is only minimally tested, but if you desperately need to edit
space-indented files you might see whether it actually solves your problem
-- if it's useful for enough people, maybe something like it can go in the
IDE.
> This will be far easier than trying to get the text engine (WASTE) to
> understand that a tab isn't really a tab, but some variable number of
> spaces, and that when you hit delete, sometimes you don't want to delete
> just one space, but 2 or 3 or 4.
This was my first approach (getting PythonIDE to understand that spaces and
tabs both indent) -- it avoids PyIDESpacesToTabsPatch's problem of figuring
out which tabs used to be spaces and which ones used to be tabs, and it
copies the spec of python-mode.el, which seemed like a Good Thing -- but
it's annoying to click in the middle of an indentation level, and to have to
arrow or backspace multiple times, so I prefer the other solution.
---
From PyIDESpacesToTabsPatch:
"This is a work in progress; use it at your own risk.
Patches PyIDE's edit windows so that an editor opened onto a file
indented with spaces will have represent the spaces as tabs. Saving such
a file will write it back out with spaces.
Usage: Put this file in Python's search path, and after PythonIDE has
launched, type 'import PyIDESpacesToTabsPatch' at its command line. To
turn off the feature:
import PyEdit
PyEdit.Editor.CONVERT_SPACES_TO_TABS = 0
To turn it back on:
PyEdit.Editor.CONVERT_SPACES_TO_TABS = 1
To do:
- auto-detect 2- and 8-space indents
- save a new buffer as space-indented
- only tabify *.py files?
- let you see whether the file you're editing is space-indented"