title: Get rid of "reference to free variable" byte-compilation warnings
body: <p>I'm writing an emacs major mode, which uses buffer-local variables to store some state:</p>
  
  <pre class="lang-lisp prettyprint-override"><code>(defun foo-mode ()
    "My nice major mode"
    (interactive)
    (kill-all-local-variables)
    (setq mode-name "foo")
    (setq major-mode 'foo-mode)
    (set (make-local-variable 'foo-state) "bar"))
  
  (defun foo-change-state ()
    (setq foo-state "baz"))
  </code></pre>
  
  <p>This works very well and has the property that in any buffer not using my major mode, the <code>foo-state</code> variable is not bound (which is a good thing in my opinion, since it avoids cluttering the symbols table).</p>
  
  <p>However, byte-compiling such a piece of code produces the following warning:</p>
  
  <pre><code>Warning: assignment to free variable `foo-state'
  </code></pre>
  
  <p>Using <code>defvar</code> gets rid of the warning, but has the side-effect that <code>foo-state</code> is now bound everywhere, which is undesirable in my opinion.</p>
  
  <p>Is there a way to get rid of the warnings while still not binding the mode-specific variables in every buffer? Or am I mistaken when I think these variables should not be declared globally?</p>