So, I’ve been having fun with this web site that creates random themes for Emacs. I’ve been saving the resultant .el files and loading them when starting Emacs. Each color theme can be started by evaluating an elisp expression prefixed with inspiration-.
Unfortunately, I don’t know elisp. Can someone help me figure out how I might write a function that looks at what “inspiration-” prefixed functions are available, and randomly evaluate one of them?
I like to build up a solution to these problems incrementally. If you just want to try my answer, skip to the
defunblock of code at the end. I go to the*scratch*buffer, inlisp-interaction-modeto try these code snippets out. You can typeC-jafter an expression and Emacs will run it and insert the results in the buffer.The
aproposfunction searches for symbols matching some pattern, including regular expressions. So we can find all symbols starting with “inspiration-” like so:But that result has a list for each symbol with some other information. We can discard that and just take the symbol name, which comes first, using the
firstfunction:Some of those aren’t functions, so let’s remove any that fail the
functionptest:Now let’s randomly choose one of those. I’m switching from
lettolet*becauselet*allows me to reference earlier definitions in the same initialization, e.g. usingsymbolswhen definingfunctions.Now let’s turn that into a new lisp function (and let’s not have the name start with
inspiration-). I’ll mark it asinteractiveso that you can run it viaM-x use-random-inspirationin addition to using it in other elisp code. The other big change is to usefuncallto actually run the randomly selected function:So add that to your
$HOME/.emacsfile and try it out.EDIT: Avoid the Apropos buffer popup