title: The difference between setq and setq-default in Emacs Lisp
body: <p>I have a question about Emacs Lisp. What is the difference between <strong>setq</strong> and <strong>setq-default</strong>?</p>
  
  <p>Tutorials say <strong>setq</strong> takes effect in the <em>local buffer</em> while <strong>setq-default</strong> affects all buffers.  </p>
  
  <p>For example, if I wrote <strong>(setq a-var a-vars-value)</strong> in <strong>init.el</strong>, I found after starting Emacs and opening a new buffer, the <strong>a-var</strong> is also there and its value is <strong>a-vars-value</strong>. I thought it was not supposed to be there. It seems there is no difference between <strong>setq</strong> and <strong>setq-default</strong>.  </p>
  
  <p>Is there something wrong with my understanding?</p>
  
  <p>For example:  </p>
  
  <ol>
  <li><p>I wrote <strong>(setq hello 123)</strong> in the <strong>init.el</strong> file, and I run <strong>emacs abuffer</strong> in the shell, then I input <strong>"hello C-x C-e"</strong>, it shows "123". The same happens when I run this in all new buffers.  </p></li>
  <li><p>I wrote <strong>(setq tab-width 4)</strong> in the <strong>init.el</strong> file. When I run <strong>tab-width C-x C-e</strong>, it shows "8" (Current mode is 'Text'). However, when I use <strong>(setq-default tab-width 4)</strong>, it show "4". I can't explain this phenomenon.</p></li>
  </ol>