1

I am trying to get code folding to work in Elpy. I have turned the folding module on already. However, I still seem to be unable to fold code. When I click on the first line of a while loop, I get the following message:

Debugger entered--Lisp error: (invalid-function hs-life-goes-on)
  hs-life-goes-on(nil)
  elpy-folding--click-text((mouse-1 (#<window 3 on while-loops.py> 94 (32 . 80) 18555047 nil 94 (4 . 5) nil (4 . 10) (7 . 14))))
  funcall-interactively(elpy-folding--click-text (mouse-1 (#<window 3 on while-loops.py> 94 (32 . 80) 18555047 nil 94 (4 . 5) nil (4 . 10) (7 . 14))))
  call-interactively(elpy-folding--click-text nil nil)
  command-execute(elpy-folding--click-text)

When I try to use the code folding option from the Elpy drop-down menu, I get the following error:

Debugger entered--Lisp error: (invalid-function hs-life-goes-on)
  hs-life-goes-on(nil)
  elpy-folding-toggle-at-point()
  funcall-interactively(elpy-folding-toggle-at-point)
  call-interactively(elpy-folding-toggle-at-point nil nil)
  command-execute(elpy-folding-toggle-at-point)

When I try to use the shortcut for the elpy-toggle-at-point function, I also get an error similar to the one above:

Debugger entered--Lisp error: (invalid-function hs-life-goes-on)
  hs-life-goes-on(nil)
  elpy-folding-toggle-at-point()
  funcall-interactively(elpy-folding-toggle-at-point)
  call-interactively(elpy-folding-toggle-at-point record nil)
  command-execute(elpy-folding-toggle-at-point record)
  execute-extended-command(nil "elpy-folding-toggle-at-point" "elpy-folding-toggle-at")
  funcall-interactively(execute-extended-command nil "elpy-folding-toggle-at-point" "elpy-folding-toggle-at")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)

It seems that hs-life-goes-on from hideshow.el, which controls the "HideShow" minor mode is the problem. When I went to the function definition in hideshow.el.gz, this is what I found:

(defmacro hs-life-goes-on (&rest body)
  "Evaluate BODY forms if variable `hs-minor-mode' is non-nil.
In the dynamic context of this macro, `inhibit-point-motion-hooks'
and `case-fold-search' are both t."
  (declare (debug t))
  `(when hs-minor-mode
     (let ((inhibit-point-motion-hooks t)
           (case-fold-search t))
       ,@body)))

I am honestly not sure what is going on here.

As a last resort, I uninstalled Emacs and reinstalled it. I am currently using Emacs 28 on MacOS Catalina. My previous Emacs was 26.3. Both of these versions were obtained from HomeBrew. Emacs 26.3, my previous version was obtained from brew cask. My latest one, Emacs 28, was this version compiled from HomeBrew using the --with-cocoa option. Reinstallation did not fix the problem.

A similar question has been asked before, but the error I am getting is quite different from the one that the person asking that question got. In my case, I have also attempted to fix the problem by trying different methods to get code folding to work and managed to track down the code behind the function which seems to be breaking. That is why I think that this question is distinct enough from the aforementioned question to be posted separately on StackExchange, and should not count as a duplicate.

May I know what I can do to solve the problem?

bluefyre91
  • 11
  • 2
  • Either your question is a duplicate, in which case it should be closed, regardless of whether you don't yet see an adequate answer, or your question is a bit different, *and for that reason* the other question "doesn't work in your case". Please clarify your question, contrasting it with the other one, to make clear what the difference is. Or please delete it if there is no real difference. Thx. – Drew Jun 07 '20 at 17:02
  • https://emacs.stackexchange.com/tags/elisp/info – Drew Jun 07 '20 at 17:03
  • @Drew There is no real answer to the previous instance of this question: https://emacs.stackexchange.com/questions/54213/code-folding-in-elpy-not-working?newreg=9394cc64e39d462fba0eff824c9969a5. All the replies are in the comments, but there is no proper answer. Hence, I am not sure whether my question counts as a duplicate. The question seemed similar to mine, which is why I mentioned it in my post. Apologies, this is my first time asking a question on this forum. – bluefyre91 Jun 08 '20 at 18:12
  • The fact that there is no proper answer posted yet to the question is irrelevant. That's not a reason to post a duplicate question. IF you think your question is different then please edit it to make that clear - what the difference is. Otherwise, please delete the question. You can always add a comment to the other question saying that you have the same problem/question/ – Drew Jun 08 '20 at 23:14
  • 1
    @Drew I have made edits to this question in order to clarify how my question is different enough from the previous instance of this question, and why it deserves a separate post (second-to-last paragraph). – bluefyre91 Jun 16 '20 at 14:04

1 Answers1

0

Had this issue on elpy 20211211.2248 on GNU Emacs 27.2 (build 1, x86_64-w64-mingw32) of 2021-03-26. A check on elisp macro documentation clued that it could be related to byte-compilation of the elisp files. Deleting the .elc files in elpy installation directory solved the problem for me.

subhacom
  • 61
  • 3