7

I am aware that org-mode derives from outline-mode, in the same way as outline-mode derives from text-mode, which derives from nil.

I have always wonder if there exists something similar to a documented tree of major modes allowing to follow hooks, so that fundamental-mode might be at the base of them all.

Is there a list of major-modes, with their respective hierarchies, documented anywhere?

1
  • The most definitive documentation for this would be from within emacs itself, though I don't know how to access such information comprehensively and automatically. Commented Oct 26, 2014 at 19:28

2 Answers 2

4
(defun modes-tree ()
  (cl-loop
   with result = (make-hash-table)
   for maybe-mode in (apropos-internal "-mode$")
   ;; This doesn't really filter all non-modes, but it gets close
   when (fboundp maybe-mode) do
   (setf (gethash maybe-mode result)
         (get maybe-mode 'derived-mode-parent))
   finally (cl-return result)))

Something to get you started. This will produce a hash-map containing every symbol which looks like it is a mode as a key. And, if it is a derived, mode, then the value pointed by that symbol will be the parent mode.

But printing this is a much, much harder problem :) Graph printing is in general very non-trivial. Maybe you could export this as Dot and then use something like OGDF to print it nicely (Graphiz can also print graphs, but, quite frankly, it doesn't look very good / it's hard to get it to lay out the graph exactly the way you want).

4
  • I wish I could +1, but I'm all out of votes :) Printing actually isn't that hard of a problem if you don't complicate it. A simple tree-view will suffice; take a look the output of tree in your terminal. (Choose a small directory!) Commented Oct 26, 2014 at 20:37
  • 1
    @SeanAllred for some reason I thought it's not necessarily an acyclic directed graph :) Yeah, printing this tree won't be too hard (especially so it seems that the hierarchy is more "bushy"), but in general, when there are loops and certain constraints wrt the area where the graph can be printed, it becomes difficult.
    – wvxvw
    Commented Oct 26, 2014 at 20:39
  • I created a tool for self-stabilizing algorithm simulation / visualization for my thesis. You aren't lying when you say that it becomes difficult. Crossings… ugh. Commented Oct 26, 2014 at 20:42
  • 3
    I used neato to get a view of all modes (I took all symbols that had a 'derived-mode-parent property). The output is terrible, but it gives an idea: i.sstatic.net/PKr61.jpg
    – YoungFrog
    Commented Dec 22, 2014 at 14:10
2

The (now built in!) hierarchy package has an example on how to do this. See: https://github.com/DamienCassou/hierarchy#major-modes-hierarchy-example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.