1

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?

1

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))))
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)))

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.