7

Currently, I use the hs-minor-mode to collapse my python code and make it easier to work with - however, by default this only folds def my_function(): blocks. Is it possible to get it to work with if, for, while etc. blocks as well?

If not, does anyone know a better option for code folding? I do use C-s and M-x occur to move around my code already, I just sometimes like to fold my code so I don't have so much to look at.

dieggsy
  • 475
  • 2
  • 10

2 Answers2

2

After a little more looking around, I found:

Which can do what I wanted (and possibly a little more). I haven't thoroughly tested them both out, but on first impression, yafolding is working the best so far on python.el.

dieggsy
  • 475
  • 2
  • 10
0

I use spacemacs distro and was struggling with this issue. Use this gist to get hideshow folding to work with indentation.

Edit: Sure Drew, here's the elaboration.

  1. Add both the snippets found in the link to user-init() function of .spacemacs file
  2. Call hs-hide-level using M-x or keybind it, the way shown below
  (with-eval-after-load 'evil-maps
    (define-key evil-motion-state-map (kbd "zs") 'hs-hide-level))

right after the pasted snippets

  1. Profit :)
Yesh
  • 101
  • 2
  • This is essentially a link-only answer, so it risks being deleted. Please summarize the answer that you invite readers to find at that link destination. Thx. – Drew Mar 16 '21 at 17:41