title: Create a new mode in Emacs
body: <p>I know nothing about Emacs Lisp (or any Lisp, for that matter). I want to do something that seems very simple, yet I have had no luck with online guides. I want to create "packet-mode.el" for <code>.packet</code> files. I want to do the following:</p>
  
  <ul>
  <li>Enable C++ mode</li>
  <li>Make <code>packet</code> a keyword, while leaving the rest of C++ mode unchanged</li>
  </ul>
  
  <pre class="lang-lisp prettyprint-override"><code>(define-derived-mode packet-mode fundamental-mode
    (font-lock-add-keywords 'c++-mode `(("packet" . font-lock-keyword-face)))
    (c++-mode))
  
    (add-to-list 'auto-mode-alist '("\\.packet\\'" . packet-mode)
    (provide 'packet-mode)
  </code></pre>
  
  <p>I've also tried switching the order of the statements in packet mode, but then the C++ highlighting breaks.</p>
  
  <p>I would like <code>packet</code> to behave like <code>struct</code> in the sense that</p>
  
  <pre><code>packet foo {
    int bar;
  }
  </code></pre>
  
  <p>is highlighted the same way it would be if <code>struct</code> were used in place of <code>packet</code>.</p>