I have yapf installed, and would like to run it automatically. Documentation says there is a way: http://elpy.readthedocs.io/en/latest/ide.html#command-elpy-format-code but I don't see it in the source code.

PS. It's not important that it come from Elpy. If there's an alternative ready-made solution, it's just as good.


elpy-format-code is available in elpy. You can run it with C-c C-r f or M-x elpy-format-code.

If you want to run it automatically, you can use buffer hooks or a timer to run whenever you want.

  • Can you tell when was this added? I have 1.8.0 and it doesn't have this function. – wvxvw May 18 '17 at 12:26
  • It is added in 1.11. Current version is 1.15. – ChillarAnand May 19 '17 at 4:44
  • For some reason is not loading during the normal setup process. I have to load the elpy.el file directly for the function to be defined. – Marcelo Lacerda Dec 15 '20 at 12:58
  • 1
    Are you loading elpy in your init file? @MarceloLacerda – ChillarAnand Dec 16 '20 at 11:09
  • Oh silly me I was not doing (elpy-enable) in the init file. – Marcelo Lacerda Dec 16 '20 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.