all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Calling a function every random number of minutes, where random  amount changes
@ 2007-11-29 15:51 metaperl.com
  2007-11-29 19:37 ` vk0vk0vk0
  0 siblings, 1 reply; 3+ messages in thread
From: metaperl.com @ 2007-11-29 15:51 UTC (permalink / raw)
  To: help-gnu-emacs

The code below randomly selects one of my favorite color-themes. I
would like to set something up so that (color-theme-random) is called
after n minutes have elapsed. Where n is non-constant and randomly
chosen between 5 and 60.

In other words, after 7 minutes it calll the function. Then after 30
minutes it calls it again. Then 12 minutes... and so on and so on.

(require 'color-theme)

(random t)

(defvar *color-theme-favorites*
  '(

    arjen andreas billw blippblopp blue-mood blue-sea calm-forest
    classic comidia dark-blue dark-blue2 deep-blue
    euphoria feng-shui fischmeister goldenrod gray1 gray30
    high-contrast hober infodoc jb-simple jonadabian
    jsc-dark jsc-light
kingsajz
    late-night lawrence lethe
    marine marquardt midnight mistyday montz oswald parus
    robin-hood simple-1 subtle-blue tty-dark
    word-perfect
    xp

    ))

(defun color-theme-random()
     (interactive)



     (let* ((choice (nth (random (length *color-theme-favorites*))
			 *color-theme-favorites*))
	    (fn (intern (format "color-theme-%s" choice))))
       (funcall fn)))

(color-theme-random)

(provide 'color-theme-random)
;;;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Calling a function every random number of minutes, where random  amount changes
  2007-11-29 15:51 Calling a function every random number of minutes, where random amount changes metaperl.com
@ 2007-11-29 19:37 ` vk0vk0vk0
  2007-11-29 21:51   ` metaperl.com
  0 siblings, 1 reply; 3+ messages in thread
From: vk0vk0vk0 @ 2007-11-29 19:37 UTC (permalink / raw)
  To: help-gnu-emacs

first of all. it's a wonderfully weird feature you want here.

Here are the functions i came up with.

(defun time-after-seconds (seconds)
  "returns an internal emacs time that is 'seconds' seconds into the
  future."
  (seconds-to-time (+ seconds (time-to-seconds (current-time)))))

(defun timer-create-callfunc-after-seconds (func seconds)
  "run 'func' after 'seconds' seconds."
  (let ((timer (timer-create)))
    (timer-set-function timer func)
    (timer-set-time timer (time-after-seconds seconds))
    (timer-activate timer)))

(defun callfunc-random-interval (func interval-from-seconds
interval-to-seconds)
  "run 'func' with a random interval between 'interval-from-seconds'
  and
'interval-to-seconds' seconds in a infinite loop."
  (funcall func)
    (timer-create-callfunc-after-seconds
     (list 'lambda '()
           (list 'funcall ''callfunc-random-interval
                 (list 'quote func) interval-from-seconds
                 interval-to-seconds))
     (+ interval-from-seconds (random interval-to-seconds))))

;; (callfunc-random-interval (lambda () (insert " foo")) 2 3)

and how to make it work like you want it to:

(callfunc-random-interval 'color-theme-random (* 60 5) (* 60 60))

Hope this helps you in your insane experiment.

metaperl.com wrote:
> The code below randomly selects one of my favorite color-themes. I
> would like to set something up so that (color-theme-random) is called
> after n minutes have elapsed. Where n is non-constant and randomly
> chosen between 5 and 60.
>
> In other words, after 7 minutes it calll the function. Then after 30
> minutes it calls it again. Then 12 minutes... and so on and so on.
>
> (require 'color-theme)
>
> (random t)
>
> (defvar *color-theme-favorites*
>   '(
>
>     arjen andreas billw blippblopp blue-mood blue-sea calm-forest
>     classic comidia dark-blue dark-blue2 deep-blue
>     euphoria feng-shui fischmeister goldenrod gray1 gray30
>     high-contrast hober infodoc jb-simple jonadabian
>     jsc-dark jsc-light
> kingsajz
>     late-night lawrence lethe
>     marine marquardt midnight mistyday montz oswald parus
>     robin-hood simple-1 subtle-blue tty-dark
>     word-perfect
>     xp
>
>     ))
>
> (defun color-theme-random()
>      (Interactive)
>
>
>
>      (let* ((choice (nth (random (length *color-theme-favorites*))
>                        *color-theme-favorites*))
>           (fn (intern (format "color-theme-%s" choice))))
>        (funcall fn)))
>
> (color-theme-random)
>
> (provide 'color-theme-random)
> ;;;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Calling a function every random number of minutes, where random  amount changes
  2007-11-29 19:37 ` vk0vk0vk0
@ 2007-11-29 21:51   ` metaperl.com
  0 siblings, 0 replies; 3+ messages in thread
From: metaperl.com @ 2007-11-29 21:51 UTC (permalink / raw)
  To: help-gnu-emacs

On Nov 29, 2:37 pm, vk0vk0...@gmail.com wrote:
> first of all. it's a wonderfully weird feature you want here.
>
> Here are the functions i came up with.
>

it works great. thank you very much! keeps me awake during my 8 hours
of cubicle imprisonment :)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-11-29 21:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-29 15:51 Calling a function every random number of minutes, where random amount changes metaperl.com
2007-11-29 19:37 ` vk0vk0vk0
2007-11-29 21:51   ` metaperl.com

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.