0

I am struggling with my emacs configuration. The relevant lines in .emacs are:

(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))))))

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 M-x python-mode, everything is as it should.

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.

I'd appreciate some hints.

user52366
  • 1,035
  • 1
  • 10
  • 21

2 Answers2

1

Figured it out in the meanwhile... the problem was that elpy-enable does install a hook. It does not directly invoke the elpy mode as I thought. Therefore only the second invocation of python-mode did actually result in a call of this function. Of course this is better... So now I have:

(elpy-enable)
(setq elpy-rpc-backend "jedi")
(add-hook
 'elpy-mode-hook
 '(lambda () (setq-local ac-max-width 0.5)))  
user52366
  • 1,035
  • 1
  • 10
  • 21
0

To enable elpy functionality, all you need in your .emacs is

(package-initialize)
(elpy-enable)

However, you also have to properly install elpy package itself.

Try to perform all steps from "Quick installation" section: https://github.com/jorgenschaefer/elpy#quick-installation

a5kin
  • 1,335
  • 16
  • 20
  • All packages are properly installed, otherwise the setup would not work if I M-x python-mode. My question is why my code does not work, although the hook is called when I open a .py file. It only works when I re-set python-mode, although I already am in this mode. – user52366 Dec 07 '17 at 19:53