简体   繁体   中英

emacs configuration: python-mode-hook

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 Mx 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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM