Building a today-I-learned habit, and displaying the documentation for random Emacs commands
| emacsI'd like to build a habit of regularly learning one small thing each day in one of three domains: tech, life, and learning. My measurable output would probably be in the form of index cards, tweets, blog posts, and notes (in org-capture, Dropbox, or Evernote). I can get input from various sources like blog posts, videos, books, webpages, and so on.
2016-02-19a Preparing for a today-I-learned habit — index card #til #learning
A little bit of randomness might be useful for learning more about Emacs. Emacswiki has a random page function, but the chunks are often a little large or irrelevant. On the other hand, displaying a random command from the packages that I already have loaded into my Emacs – that might be a good way to discover interesting things.
I started by looking at apropos-command
, which led me to apropos-internal
, which is a C function that referred to obarray
. Using obarray
by itself didn't work (suspiciously few elements, so I often ended up looking at emms-related functions). I eventually found mapatoms, which seems to do a better job at listing an appreciable number of interactive functions. I filtered the list to include only documented functions that had not been marked as obsolete: 8,415 in my current Emacs, which should be plenty to go through. =)
(defun my/describe-random-interactive-function () (interactive) "Show the documentation for a random interactive function. Consider only documented, non-obsolete functions." (let (result) (mapatoms (lambda (s) (when (and (commandp s) (documentation s t) (null (get s 'byte-obsolete-info))) (setq result (cons s result))))) (describe-function (elt result (random (length result))))))
I've added this to a key-chord + hydra keymap as a repeatable function, so I can type hh
to start my Hydra and then type r
as many times as I want in order to show the documentation for a random interactive function. If you're curious about that, you can see the key-chord section of my config.
Anyway, today I learned more about obarray
and mapatoms
– they're not interactive functions, but they were handy for building this little bit of code. We'll see how it goes! =)