This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

executing a random command

2 posts · 10819 views

I am writing a function that will implement a random colour theme in emacs. Have a look at this example:
(defun random-colour-theme () ;; written 2017-04-02
  "Pick a random colour theme."
  (interactive)
  (setq randomNumber (random 2))
  (setq nameOfRandomColorTheme (nth randomNumber '(
"color-theme-xemacs"
"color-theme-xp")))
  (nameOfRandomColorTheme)
  )
The last part,
(nameOfRandomColorTheme)
, of course, doesn't work, even though either
(color-theme-xp)
or
(color-theme-xemacs)
work. How do I randomly pick one of these two commands and then execute it?

Re: executing a random command

I don't know Emacs lisp so this may be off base, but:
  (setq nameOfRandomColorTheme (nth randomNumber '(
"color-theme-xemacs"
"color-theme-xp")))
is setting nameOfRandomColorTheme to a string value, and then:
  (nameOfRandomColorTheme)
is using that string as if it were a function.

In your example you say
(color-theme-xp)
as a function does what you want: perhaps you want a structure like:
(if (= 0 randomNumber) (color-theme-xemacs) (color-theme-xp))
http://peterlane.info/scheme.html