title: Getting Emacs to untabify when saving certain file types (and only those file types)
body: <p>I have the following in my .emacs file:</p>
  
  <pre><code> (defun c++-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 'c++-mode-hook
             '(lambda ()
                (make-local-hook 'write-contents-hooks)
                (add-hook 'write-contents-hooks 'c++-mode-untabify)))
  </code></pre>
  
  <p>Mostly ripped off from <a href="http://www.jwz.org/doc/tabs-vs-spaces.html" rel="noreferrer">http://www.jwz.org/doc/tabs-vs-spaces.html</a>. This causes emacs to run <code>untabify</code> on the buffer before saving a C++ file.</p>
  
  <p>The problem is that after I have loaded a C++ file, the <code>untabify</code> hook is being applied to <strong>all</strong> subsequent file writes, even for buffers of other file types. This means that if I open a C++ file and then edit, say, a tab-delimited text file, the tabs get clobbered when saving the file.</p>
  
  <p>I'm not an elisp guru, but I think the <code>(make-local-hook 'write-contents-hooks)</code> line is trying to make the addition to <code>write-contents-hooks</code> apply only to the local buffer. However, it isn't working, and <code>c++-mode-untabify</code> is in <code>write-contents-hooks</code> for all buffers.</p>
  
  <p>I'm using EmacsW32 22.0 on a Windows XP box. Does anyone have any idea how to make the <code>write-contents-hooks</code> change local to a specific buffer or how to reset it to <code>nil</code> when switching to other, non-C++ buffers?</p>