<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Atomized &#187; whitespace</title>
	<atom:link href="http://atomized.org/tag/whitespace/feed/" rel="self" type="application/rss+xml" />
	<link>http://atomized.org</link>
	<description>Fragmenting reality.</description>
	<lastBuildDate>Mon, 23 May 2011 23:46:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Smarter trailing whitespace deletion</title>
		<link>http://atomized.org/2008/08/smarter-trailing-whitespace-deletion/</link>
		<comments>http://atomized.org/2008/08/smarter-trailing-whitespace-deletion/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 21:51:41 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[whitespace]]></category>

		<guid isPermaLink="false">http://atomized.org/?p=309</guid>
		<description><![CDATA[I used to use delete-trailing-whitespace in my local-file-write-hooks for any source file I edited, but I had to disable it a while back. Many files containing legacy source were extremely messy in this regard, and it made making simple fixes harder to track, since there was a large amount of noise in the diff from [...]]]></description>
			<content:encoded><![CDATA[<p>I used to use <code>delete-trailing-whitespace</code> in my <code>local-file-write-hooks</code> for any source file I edited, but I had to disable it a while back. Many files containing legacy source were extremely messy in this regard, and it made making simple fixes harder to track, since there was a large amount of noise in the diff from the whitespace changes.</p>
<p>But I just solved this. Here at <a href="http://digg.com/">Digg</a>, we document all new code with <a href="http://www.phpdoc.org/">phpDocumentor</a>. Leveraging this, I wrote a new function to examine the header of the source file and strip whitespace if I have an <code>@author</code> tag.</p>
<pre>
(defun maybe-delete-trailing-whitespace ()
  "Delete trailing whitespace if I am the author of this file."
  (interactive)
  (and (delete-trailing-whitespacep) (delete-trailing-whitespace)))

(defun delete-trailing-whitespacep ()
  "Should we delete trailing whitespace when saving this file?"
  (save-excursion
    (goto-char (point-min))
    (next-line 25)
    (let ((pos (point)))
      (goto-char (point-min))
      (re-search-forward (concat "@author +" user-full-name) pos t))))

(defun progmodes-write-hooks ()
  "Hooks which run on file write for programming modes"
  (prog1 nil
    (set-buffer-file-coding-system 'utf-8-unix)
    (untabify-buffer)
    (copyright-update)
    (maybe-delete-trailing-whitespace)))

(defun progmodes-hooks ()
  "Hooks for all programming modes"
  (add-hook 'local-write-file-hooks 'progmodes-write-hooks))

(add-hook 'php-mode-hook 'progmodes-hooks)
(add-hook 'js2-mode-hook 'progmodes-hooks)
;; Repeat for any other mode for editing source
</pre>
<p>It works a treat, happily stripping trailing whitespace if I’m listed as an author in the header, and leaving it unmolested otherwise. I’m not entirely satisfied with <code>delete-trailing-whitespacep</code>, which feels a little graceless. Maybe someone knows a better way to do it?</p>
]]></content:encoded>
			<wfw:commentRss>http://atomized.org/2008/08/smarter-trailing-whitespace-deletion/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

