[Python-Dev] whitespace normalization
Barry Warsaw
barry at python.org
Wed Apr 25 22:15:07 CEST 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Apr 25, 2007, at 2:37 PM, skip at pobox.com wrote:
>>> Well, there are editors that don't intelligently strip
>>> whitespace, so
>>> that people using them would be constantly pained by such a hook.
>
> Guido> And they should. There really is no excuse for letting one
> Guido> developer's poor choice of tools cause later grief for
> all other
> Guido> developers.
>
> Just a little FYI, python-mode (the one Barry and I manage - dunno
> about the
> one distributed w/ GNU Emacs these days) is one of those tools that
> leaves
> trailing whitespace behind when advancing to the next line..
Maybe we should include this function in the mode:
;; untabify and clean up lines with just whitespace
(defun baw-whitespace-normalization ()
"Like untabify, but also cleans up lines with trailing whitespace."
(interactive)
(save-excursion
(save-restriction
(untabify (point-min) (point-max))
(goto-char (point-min))
(while (re-search-forward "[ \t]+$" nil t)
(let ((bol (save-excursion (beginning-of-line) (point)))
(eol (save-excursion (end-of-line) (point))))
(goto-char (match-beginning 0))
(if (and (bolp)
(eq (char-after) ?\))
(forward-char 1))
(skip-chars-backward " \t" bol)
(delete-region (point) eol)
))
;; Now clean up any trailing blank lines
(goto-char (point-max))
(skip-chars-backward " \t\n")
(if (not (bolp))
(forward-char 1))
(delete-region (point) (point-max))
;; But make sure the files ends in a newline
(if (not (bolp))
(newline))
)))
(defalias 'baw-normalize-whitespace 'baw-whitespace-normalization)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)
iQCVAwUBRi+2y3EjvBPtnXfVAQKyCAP5AUwHxTgOCRkkgCRfAP/oWCxf1WT/Y1lk
PUrb4eRaR2s5B8XP417V3O/uMPHfiQr9Ci1txoIuq22PRbPvOFT4bfSYXFxPrrGS
FOlvivpE8rnXSxv4bJC/3B11GNDoyQJds8D4/13XIZXnFE4W2WtyA0fG1kxQXBEc
gvjk/FXuRS8=
=3Wll
-----END PGP SIGNATURE-----
More information about the Python-Dev
mailing list