Message 的提示信息威力不够大,修改了一下 tea-timer 的代码,用 butterfly 来强制提醒休息,分享给大家。
;;; rest-timer.el --- Simple countdown timer -*- lexical-binding: t; -*-
;; Copyright (C) 2018 Daniel Kraus
;;
;; Author: Daniel Kraus <[email protected]>
;; Version: 0.1
;; Package-Requires: ((emacs "24.4"))
;; Keywords: convenience, timer
;; URL: https://github.com/dakra/tea-timer.el
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Simple countdown timer
;; TODO: Add modeline
;;; Code:
(defgroup rest-timer nil
"rest-timer"
:prefix "rest-timer-"
:group 'convenience)
(defcustom rest-timer-default-duration 20
"Default timer duration."
:type 'integer
:safe #'integerp
:group 'rest-timer)
(defcustom rest-timer-message "Start to work."
"Message to show when timer is up."
:type 'string
:group 'rest-timer)
(defvar rest-timer--timer nil
"Store current running timer.")
(defun butterfly ()
"Use butterflies to flip the desired bit on the drive platter.
Open hands and let the delicate wings flap once. The disturbance
ripples outward, changing the flow of the eddy currents in the
upper atmosphere. These cause momentary pockets of higher-pressure
air to form, which act as lenses that deflect incoming cosmic rays,
focusing them to strike the drive platter and flip the desired bit.
You can type `M-x butterfly C-M-c' to run it. This is a permuted
variation of `C-x M-c M-butterfly' from url `http://xkcd.com/378/'."
(interactive)
(if t
(progn
(switch-to-buffer (get-buffer-create "*butterfly*"))
(erase-buffer)
(sit-for 0)
(animate-string "Please have a rest"
(/ (window-height) 2) (- (/ (window-width) 2) 12))
(sit-for (* 5 (/ (abs (random)) (float most-positive-fixnum))))
(message "Successfully flipped one bit!"))
(message "Well, then go to xkcd.com!")
(browse-url "http://xkcd.com/378/")))
(defun rest-timer-rest-ready ()
"Display rest ready message and reset timer."
(if (require 'alert nil 'no-error)
(alert rest-timer-message)
(butterfly))
(setq rest-timer--timer nil))
;;;###autoload
(defun rest-timer (&optional duration)
"Set a rest timer to DURATION in seconds or rest-timer-default-duration."
(interactive "P")
(when rest-timer--timer
(when (y-or-n-p "Another rest timer already running. Cancel the old one? ")
(rest-timer-cancel)
(setq rest-timer--timer nil)))
(if rest-timer--timer
(rest-timer-display-remaining-time)
(message "Setting rest timer to %s minutes." (or duration rest-timer-default-duration))
(setq rest-timer--timer
(run-at-time (* 60 (or duration rest-timer-default-duration)) nil 'rest-timer-rest-ready))))
(defun rest-timer-display-remaining-time ()
"Displays remaining time in the Minibuffer."
(interactive)
(if rest-timer--timer
(let* ((remaining-time (decode-time (time-subtract (timer--time rest-timer--timer) (current-time)) t))
(minutes (nth 1 remaining-time))
(seconds (nth 0 remaining-time)))
(message "%s minutes and %s seconds left" minutes seconds))
(message "No rest timer active")))
(defun rest-timer-cancel ()
"Cancel running rest timer."
(interactive)
(when rest-timer--timer
(cancel-timer rest-timer--timer)
(setq rest-timer--timer nil)))
(provide 'rest-timer)
;;; rest-timer.el ends here