I am trying to reuse lots of things that are built in c-mode for technically another c-like language, including syntactical highlighting and stuff like that.

However, c-mode in my settings are customized using mode hooks. Specifically, I have enabled following two lines in my c-mode-hook:

  (semantic-mode t)
  (semantic-idle-summary-mode t)
  (semantic-stickyfunc-mode t)

But this is breaking the major mode derived from c-mode, because semantic-mode has no idea how to parse the source file in another c-like language. Is there a way to derive a major mode from an existing one without running the hooks for the parent?

  • 1
    Duplicate of stackoverflow.com/questions/36268882/…
    – phils
    Feb 8, 2018 at 1:48
  • that is very sad according to that answer.
    – Jason Hu
    Feb 8, 2018 at 1:56
  • M-x report-emacs-bug, e.g., to request an enhancement along the lines @Stefan sugggested in his answer - for c-mode, for example.
    – Drew
    Feb 8, 2018 at 2:03

1 Answer 1


As per the duplicate Q&A on Stack Overflow, you can't sensibly do what you're asking.

However, it's easy enough to modify your custom hook function to prevent the unwanted code from running for your derived mode by testing major-mode (which you would typically do via derived-mode-p in order to also catch derivatives of the derivative, etc...).

(unless (derived-mode-p 'YOUR-MODE)
  (semantic-mode t)
  (semantic-idle-summary-mode t)
  (semantic-stickyfunc-mode t))

Your Answer

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

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