3

Is it possible to check if a mode is derived from another mode?

eg:

(member major-mode '(c-mode c++-mode glsl-mode))

Could be replace with something like this:

(does-mode-derive-from major-mode cc-mode)
6

Function derived-mode-p does that.

So in your case: (derived-mode-p '(c-mode c++-mode glsl-mode)). C-h f tells you:

derived-mode-p is a compiled Lisp function in subr.el.

(derived-mode-p &rest MODES)

Non-nil if the current major mode is derived from one of MODES.

Uses the derived-mode-parent property of the symbol to trace backwards.

This is its definition, in case you want to be able to pass major-mode:

(defun derived-mode-p (&rest modes)
  "Non-nil if the current major mode is derived from one of MODES.
Uses the `derived-mode-parent' property of the symbol to trace backwards."
  (apply #'provided-mode-derived-p major-mode modes))

(@phils pointed out in a comment that provided-mode-derived-p is available only starting with Emacs 26.)

  • 3
    Regarding the last part, note that provided-mode-derived-p was only added in 26.1. – phils Jan 29 at 1:43
  • @phils: Good to know. I added that to the answer. Thx. – Drew Jan 29 at 2:09

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.