Better folding in python

Hi, I need to work with long python files, with long docstings and I wanted to use folding to manage this. I think that the default fold in my init.el does not work for docstrings. I found this reddit discusion recomending elpy.

I added this in my packages.el

(package! elpy :recipe
  (:host github :repo "jorgenschaefer/elpy")

and in my config.el:

(after! elpy
  (set-company-backend! 'elpy-mode
    '(elpy-company-backend :with company-files company-yasnippet)))

Should I remove fold from my init.el? I would like to use code folding with other programming languages too, but I don’t know if I might have some problem by having fold and elpy at the same time.

When I have both enabled, M-x elpy-folding-toogle-at-point works after I run M-x elpy-enable M-x +fold/toggle M-x +fold/toogle otherwise I get the message Please enable the ’Folding module’ to use this functionality. How can I enable the Folding module?

uncomment the line fold under the :editor category and run doom sync on the command line.

The fold/... commands are hardcoded to use generalised folding packages based on certain predicates, in theory it could be made to be extensible but thats not on the roadmap yet.

Otherwise they should not clash, if you use one function to create a fold you need to use its opposite to remove it but otherwise they play nicely,

another option would be to conditionally bind the folding commands when using the elpy minor mode, this would happen by binding them to the elpy-mode-map see the docs for map! to see how to do that.

Hope this helps

1 Like

Did that solve your issue? if so ill mark my answer as the solution and consider this closed?

Thank you, it solves the problem.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.