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.

2 Answers 2

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)))  
Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.