[Python-Dev] Reindenting the C code base? (original) (raw)

Georg Brandl g.brandl at gmx.net
Mon Dec 15 09:20:44 CET 2008


Jeffrey Yasskin schrieb:

On Sun, Dec 14, 2008 at 8:26 AM, Guido van Rossum <guido at python.org> wrote:

On Sat, Dec 13, 2008 at 2:11 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:

Guido van Rossum <guido python.org> writes:

I think we should not do this. We should use 4 space indents for new files, but existing files should not be reindented. Well, right now many files are indented with a mix of spaces and tabs, depending on who did the edit and how their editor was configured at the time. That's a shame. We used to have more rigorous standards than allowing that. Perhaps a graceful policy would be to mandate that all new edits be made with spaces without touching other functions in the file. Then hopefully the code base would gradually converge to a tabless scheme. I don't think so. I find local consistency more important than global consistency. A file can become really hard to read when different indentation schemes are used in random parts of the code. If you have a problem configuring your editor, just say so and someone will explain how to do it. I've never figured out how to configure emacs to deduce whether the current file uses spaces or tabs and has a 4 or 8 space indent. I always try to get it right anyway, but it'd be a lot more convenient if my editor did it for me. If there are such instructions, perhaps they should be added to PEPs 7 and 8?

I use this little hack to detect indentation in Python's C files:

(defun c-select-style () "Hack: Select the C style to use from buffer indentation." (save-excursion (if (re-search-forward "^\t" 3000 t) (c-set-style "python") (c-set-style "python-new"))))

(add-hook 'c-mode-hook 'c-select-style)

-- where "python" and "python-new" are two appropriate c-mode styles.

Georg

-- Thus spake the Lord: Thou shalt indent with four spaces. No more, no less. Four shall be the number of spaces thou shalt indent, and the number of thy indenting shall be four. Eight shalt thou not indent, nor either indent thou two, excepting that thou then proceed to four. Tabs are right out.



More information about the Python-Dev mailing list