I've been trying to use Hide Show package in emacs. I encountered a problem when using python. Let's say I have the following code:

Test code

When I have hit the command hs-hide-level. This is the result.


Which is not correct since I'm looking for this:

What I'm looking for

So, apparently there's a bug in the code which provokes that the folding is being done only in the impair methods (for some reason), but I'm asking here for a workaround if anyone has encountered the same problem.

I'm using Emacs 24.3.1 under ubuntu 14.04.

  • And if anyone could be kind to tell me where to report the bug, it would be nice too, because there's no github's repository for this apparently.
    – silgon
    Commented Nov 24, 2015 at 18:07
  • 2
    As hide-show is part of Emacs, you must hand in an Emacs bug, preferably by using M-x report-emacs-bug.
    – wasamasa
    Commented Nov 24, 2015 at 21:22

1 Answer 1


Here a conf that do what you want:

    (defun py-outline-level ()
      (let (buffer-invisibility-spec)
          (skip-chars-forward "\t ")
    (defun hide-body-recenter ()
    (defun my-pythonFold-hook ()
      (setq outline-regexp "[^ \t\n]\\|[ \t]*\\(def[ \t]+\\|class[ \t]+\\)")
      (setq outline-level 'py-outline-level)
      (outline-minor-mode t)
      (define-key python-mode-map (kbd "C-<kp-subtract>") 'hide-body-recenter)
      (define-key python-mode-map (kbd "C-<kp-add>") 'show-all)
      (define-key python-mode-map (kbd "C-S-<kp-subtract>") 'hide-subtree)
      (define-key python-mode-map (kbd "C-S-<kp-add>") 'show-subtree))
    (add-hook 'python-mode-hook 'my-pythonFold-hook)

Then you can use C-+, C--, C-S-+, and C-S-- (numeric keypad)

  • I'm only using one little part of your code but as you say, that's exactly what I wanted. Thanks ;)
    – silgon
    Commented Nov 25, 2015 at 9:25
  • another comment years appart, do you know how to add docstrings so they hide at the same time?
    – silgon
    Commented Nov 2, 2018 at 8:06

Your Answer

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

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