As an example, let's use latex-mode
, that inherits from tex-mode
, that inherits from text-mode
. Is there a command, that would take as input latex-mode
and give me parent and grand-parent? Or, other way around, is there a command that would take text-mode
as input, and give me children and grand-children?
Asked
Active
Viewed 396 times
3
2 Answers
4
Property derived-mode-parent
of a mode symbol gives you the parent mode it is derived from.
(get 'latex-mode 'derived-mode-parent)
(get 'tex-mode 'derived-mode-parent)
This will give you a list of the hierarchy:
(defun derived-modes (mode)
"Return a list of the ancestor modes that MODE is derived from."
(let ((modes ())
(parent nil))
(while (setq parent (get mode 'derived-mode-parent))
(push parent modes)
(setq mode parent))
(setq modes (nreverse modes))))

Drew
- 75,699
- 9
- 109
- 225
0
I have a version based on recursion
(defun my/derived-modes (mode)
(interactive (list major-mode))
(defun iter (mode)
(and mode
(cons mode
(iter (get mode 'derived-mode-parent)))))
(message "%s" (iter mode)))

Jiacai Liu
- 111
- 3