Created
December 29, 2010 11:50
-
-
Save buzztaiki/758455 to your computer and use it in GitHub Desktop.
Countdown to 2011 in Emacs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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