executing a random command

Discussion of Emacs Lisp

executing a random command

Postby elaliquo » Sun Apr 02, 2017 10:38 am

I am writing a function that will implement a random colour theme in emacs. Have a look at this example:

Code: Select all
(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,
Code: Select all
(nameOfRandomColorTheme)
, of course, doesn't work, even though either
Code: Select all
(color-theme-xp)
or
Code: Select all
(color-theme-xemacs)
work. How do I randomly pick one of these two commands and then execute it?
elaliquo
 
Posts: 1
Joined: Sun Apr 02, 2017 9:31 am

Re: executing a random command

Postby peterlane » Mon Apr 10, 2017 6:18 am

I don't know Emacs lisp so this may be off base, but:

Code: Select all
  (setq nameOfRandomColorTheme (nth randomNumber '(
"color-theme-xemacs"
"color-theme-xp")))


is setting nameOfRandomColorTheme to a string value, and then:

Code: Select all
  (nameOfRandomColorTheme)


is using that string as if it were a function.

In your example you say
Code: Select all
(color-theme-xp)
as a function does what you want: perhaps you want a structure like:

Code: Select all
(if (= 0 randomNumber) (color-theme-xemacs) (color-theme-xp))
peterlane
 
Posts: 6
Joined: Wed Jan 18, 2017 5:34 am


Return to Emacs Lisp

Who is online

Users browsing this forum: No registered users and 2 guests