Tabbing/Spaces
Fredrik Lundh
fredrik at effbot.org
Sat Jan 20 01:16:51 EST 2001
Terry Hancock wrote:
> This is entirely understandable, but it's a lot easier to use tabs
> when writing (and I really wish it was set to 4 spaces myself).
Depends on your editor, of course.
Real editors don't necessarily insert a tab character
everytime you press the tab key...
> But surely there's a simple way to please both -- aren't
> there de-tabbing filters I can use to substitute spaces for tabs
> (or vice-versa)? What _I_ find really irritating is that my code
> usually winds up being a mixture of the two.
I'm pretty sure your editor can do it for you (I'll leave
it to the vim gurus to explain how).
here's a piece of code I use for emacs (taken from a
java mode sample by jwz):
;; normalize whitespace on the way out
(defun python-mode-untabify ()
(save-excursion
(goto-char (point-min))
(while (re-search-forward "[ \t]+$" nil t)
(delete-region (match-beginning 0) (match-end 0)))
(goto-char (point-min))
(if (search-forward "\t" nil t)
(untabify (1- (point)) (point-max))))
nil)
(add-hook 'python-mode-hook
'(lambda ()
(make-local-variable 'write-contents-hooks)
(add-hook 'write-contents-hooks 'python-mode-untabify)))
Cheers /F
More information about the Python-list
mailing list