I have found that scad-mode.el, a derived mode from CC Mode, which can be found here:


hangs emacs if I type


into the window, or indeed any line containing a # and also one of ()[]{}. I have to kill Emacs completely and restart it after this crash.

I'm not familiar with how one write a derived mode and have not been able to figure out why this happens. I deleted almost all of scad-mode.el and I still get the hang. (This makes me suspect that the hang is caused by something missing rather than something in the code.) Furthermore, I can't find a coherent explanation of how one writes derived modes. The example derived mode,


doesn't look much like scad-mode.el. I wonder if perhaps things have changed since 2002, when the example was written. The documentation text for c-basic-common-init says I need to call c-init-language-vars first, which scad-mode does not. But if I add a call to this

(c-init-language-vars scad-mode)

I get the message:

File mode specification error: (void-function c-init-language-vars)

Can anybody tell me what's wrong with scad-mode.el that it causes Emacs to hang? Or how to go about debugging it?

Note: I reduced scad-mode.el to this:

(add-to-list 'auto-mode-alist '("\\.scad$" . scad-mode))
(require 'cc-mode)
(define-derived-mode scad-mode prog-mode "SCAD"
  "Major mode for editing OpenSCAD code."
  (c-basic-common-init 'scad-mode "k&r")
(provide 'scad-mode)

and it still hangs the same way. It's not clear to me how to truly disentangle the question of how to write a mode from the question of why this is hanging. It has been suggested to me that it's an emacs bug.

  • I updated emacs (now at 26.1...not sure what I was at before) and I now have to type "#a=(" to crash emacs in scad-mode. – Adrian Jun 20 '19 at 12:27
  • 1
    If you need to kill it, then it didn't "crash". You probably mean that it "freezes" or "hangs". It's most commonly due to a pathological font-lock regexp. – Stefan Jun 20 '19 at 12:35
  • What @Stefan said. And please separate your multiple questions into separate questions on this site. How to debug your problem, how to define a derived mode, etc. One question per question, please. Thx. – Drew Jun 20 '19 at 13:54
  • I agree with @Stefan that font-lock is the most likely culprit. One way to check this is to disable font-lock and type the characters. If Emacs doesn't hang you can run font-lock-studio (available from Melpa) to single-step the font-lock keywords to find which is broken. – Lindydancer Jun 20 '19 at 18:51
  • I disabled font-lock by doing M-x font-lock-mode and this had no effect on the behavior. I still get the hang. I have also discovered that if I hit C-g it escapes from the hang. – Adrian Jun 21 '19 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.