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)
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityFunction 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 insubr.el
.
(derived-mode-p &rest MODES)
Non-
nil
if the current major mode is derived from one ofMODES
.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.)
provided-mode-derived-p
was only added in 26.1.