3

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.

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.

2
  • 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
    Nov 24 '15 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
    Nov 24 '15 at 21:22
4

Here a conf that do what you want:

    (defun py-outline-level ()
      (let (buffer-invisibility-spec)
        (save-excursion
          (skip-chars-forward "\t ")
          (current-column))))
    (defun hide-body-recenter ()
      (interactive)
      (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)

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

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.