Commit | Line | Data |
---|---|---|
622aca7c RM |
1 | (require 'timer) |
2 | ||
3 | ;;;###autoload | |
4 | (defvar hanoi-break-interval (* 60 30) | |
5 | "*Number of seconds between Hanoi breaks.") | |
6 | ||
7 | (add-hook 'post-command-hook 'hanoi-break-check t) | |
8 | ||
9 | (defvar hanoi-break-p nil | |
10 | "Non-nil if we need a Hanoi break real soon now.") | |
11 | ||
12 | (defun hanoi-break-check () | |
13 | "Take a Hanoi break if the time has come." | |
14 | (and (not (input-pending-p)) | |
15 | (prog1 hanoi-break-p | |
16 | (setq hanoi-break-p nil)) | |
17 | (hanoi-break))) | |
18 | ||
19 | ;;;###autoload | |
20 | (defun hanoi-break () | |
21 | "Take a Hanoi break, son." | |
22 | (interactive) | |
23 | (save-window-excursion | |
24 | (eval (condition-case error | |
25 | (if (not (yes-or-no-p "Take a break now? ")) | |
26 | '(hanoi-break-schedule 60) ; Bug him again in one minute. | |
27 | ;; Eat the screen. | |
28 | (if (eq (selected-window) (minibuffer-window)) | |
29 | (other-window 1)) | |
30 | (delete-other-windows) | |
31 | (scroll-right (window-width)) | |
32 | ;; Send him on his way. | |
33 | (message "Take a break, son.") | |
34 | (if (get-buffer "*Hanoi*") | |
35 | (kill-buffer "*Hanoi*")) | |
36 | (condition-case () | |
37 | (progn | |
38 | (hanoi (/ (window-width) 8)) | |
39 | ;; Wait for him to come back. | |
40 | (read-char) | |
41 | (kill-buffer "*Hanoi*")) | |
42 | (quit nil)) | |
43 | '(hanoi-break-schedule)) ; Schedule next break. | |
44 | (quit '(hanoi-break-schedule 60)) ; Bug him again in one minute. | |
45 | ;;(error t) | |
46 | )))) | |
47 | ||
48 | ;;;###autoload | |
49 | (defun hanoi-break-schedule (&optional time) | |
50 | "Schedule a break for ARG seconds from now (default: hanoi-break-interval)." | |
51 | (interactive (list (and current-prefix-arg | |
52 | (prefix-numeric-value current-prefix-arg)))) | |
53 | (or time (setq time hanoi-break-interval)) | |
54 | (run-at-time time nil 'hanoi-break-soon)) | |
55 | ||
56 | (defun hanoi-break-soon () | |
57 | "Take a Hanoi break very soon." | |
58 | (setq hanoi-break-p t)) | |
59 | ||
60 | (defun cancel-hanoi-break () | |
61 | "Cancel scheduled Hanoi breaks." | |
62 | (interactive) | |
63 | (cancel-function-timers 'hanoi-break-soon)) | |
64 | ||
65 | (provide 'hanoi-break) |