Skip to content

Instantly share code, notes, and snippets.

@buzztaiki
Created December 29, 2010 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buzztaiki/758455 to your computer and use it in GitHub Desktop.
Save buzztaiki/758455 to your computer and use it in GitHub Desktop.
Countdown to 2011 in Emacs.
(require 'deferred)
(require 'popup)
(defvar countdown-started nil)
(defvar countdown-wait 1000)
(defstruct countdown-tip buffer tip)
(defun countdown-start ()
"Start countdown to 2011."
(interactive)
(if countdown-started
(message "countdown already started.")
(setq countdown-started t)
(countdown-loop)))
(defun countdown-stop ()
(interactive)
(setq countdown-started nil))
(defun countdown-loop (&optional tip)
(when tip
(countdown-delete-tip tip))
(when countdown-started
(lexical-let ((newtip (countdown-show-tip)))
(deferred:nextc (deferred:wait countdown-wait)
(lambda (x)
(countdown-loop newtip))))))
(defun countdown-show-tip ()
(unless (minibufferp)
(ignore-errors
(make-countdown-tip
:buffer (current-buffer)
:tip (popup-tip
(number-to-string
(ceiling (time-to-seconds (time-subtract (encode-time 0 0 0 1 1 2011) (current-time)))))
:nowait t)))))
(defun countdown-delete-tip (tip)
(save-excursion
(when (buffer-live-p (countdown-tip-buffer tip))
(set-buffer (countdown-tip-buffer tip))
(popup-delete (countdown-tip-tip tip)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment