In emacs is it possible to get a list of parent modes for a derived mode?
I found derived-mode-p, but this only allows me to test if a mode is derived from another.
Every symbol has a property list and for derived modes, this list includes the component derived-mode-parent
which indicates which mode it was derived from. It seems to be just a single symbol.
(define-derived-mode nst-mode text-mode "Testing")
=> nst-mode
(get 'nst-mode 'derived-mode-parent)
=> text-mode
I don't see how there could be more than one parent, ever.
Here is a demo of a transitive chain of parents.
(define-derived-mode rope nil "Victim of mouse")
(define-derived-mode mouse rope "Victim of cat")
(define-derived-mode cat mouse "Victim of dog")
(define-derived-mode dog cat "Enough already")
(let ((mode 'dog) parents)
(while mode
(setq parents (cons mode parents)
mode (get mode 'derived-mode-parent)))
(reverse parents))
=> (dog cat mouse rope)
... or, just for fun, a recursive version:
(defun derived-mode-parents (mode)
(and mode
(cons mode (derived-mode-parents
(get mode 'derived-mode-parent)))))
(derived-mode-parents 'dog)
=> (dog cat mouse rope)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With