title: emacs configuration: python-mode-hook
body: <p>I am struggling with my emacs configuration. The relevant lines in .emacs are:</p>
  
  <pre><code>(require 'python-mode)
  (add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode))
  
  (add-hook
   'python-mode-hook
   '(lambda ()
      (message "python-mode-hook called")
      (require 'jedi)
      (when (require 'elpy nil t)
        (elpy-enable)
        (setq elpy-rpc-backend "jedi")
        (add-hook
         'jedi-mode-hook
         '(lambda ()
            (setq-local ac-max-width 0.5))))))
  </code></pre>
  
  <p>Whan I load a python file, the hook is called and I get the "python-mode-hook called" message. However, the elpy functionality is not there. If I then <code>M-x python-mode</code>, everything is as it should.</p>
  
  <p>I don't understand why I need to call "python-mode" twice. I somehow think it may be related to the hooks being called/defined in the wrong order, but I don't understand what is wrong here.</p>
  
  <p>I'd appreciate some hints.</p>